L9110 DC Motor Control (B4R,B4J,Node-RED)

Experiments & prototyping with the Arduino.
Site Admin
Posts: 195
Joined: 07 Oct 2017, 12:16

L9110 DC Motor Control (B4R,B4J,Node-RED)

Postby rwblinn » 16 Nov 2017, 10:23

Control a DC Motor using the L9110 Motor Control Driver connected to an Arduino.
Test Scenarios
  • Arduino controlling the DC motor by a program developed with B4R.
  • Arduino connected to a PC COM port (USB), controlled by a B4J Application (requires Java).
  • Arduino connected to a Raspberry Pi (USB), controlled by a Node-RED flow.
B4R & B4J are development tools by Anywhere Software.
Node-RED is Flow-based programming for the Internet of Things by the JS Foundation.

Parts Needed
  • 1x Arduino UNO
  • 1x DC Motor
  • 1x L9110 Motor Control Driver

Code: Select all

L9110 = Arduino UNO
VCC = 5v
IB1 = not used
IA1 = not used
IB2 = PWM 11 (green)
IA2 = PWM 12 (yellow)

DC Motor = L9110
DC = 0B2
GND = 0A2



Solution Arduino Program (B4R)
The 2 motor pins are set in output mode. The motor drive direction is set by bits HIGH (true) or LOW (false) - DigitalWrite to both IBA2 & IB2 pins.
The speed can have a value between 0 and 255. This is set via AnalogWrite to the IB2 pin.

The Arduino communicates using the serial line (115200:8N1). An asynchronous stream is handles incoming & outgoing data.
The incoming data must be defined as an array of 2 bytes, whereas (0 is the first byte):
Byte 0: Direction - 0=Break (BRK), 1=Forwards (FWD), 2=Reverse (REV)
Byte 1: Speed - value between 0 and 255
The applications connected to the Arduino must have the serial line setup as 115200:8N1 and send the data as array of bytes.

Solution PC Application (B4J)
The B4J Application connects to a COM port (115200:8N1). For the initial test, connected to a PC Port COM5.
An asynchronous stream is used to read and handle incoming data via the serial line.
The outgoing data, to control the motor, holds a an array of bytes (0 is the first byte):
Byte 0: 0=BRK, 1=FWD, 2=REV
Byte 1: 0-255 speed

Solution Node-RED
Tested the solution as described, also with Node-RED running on a Raspberry Pi.
The Arduino connects to the Raspberry Pi USB port /dev/ttyUSB0. Hint: check the ports with command: ls /dev/tty*.
A simple flow is defined using two inject nodes and a serial out node.
The serial out node has a properties /dev/ttyUSB0:115200-8N1. For other properties, kept the default.
When Node-RED starts, the log shows an entry like: serial port //dev/ttyUSB0 opened at 115200 baud 8N1. When accessing the flow, the Serial Node shows status connected.

Important(!) is to send the data from Node-RED to the connected Arduino in binary format - array of bytes - as described previous.
For the simple flow, Inject Nodes are used with payload buffer and content in JSON format. Example to let the motor run direction forwards with speed 150 is a payload of [1,150].

Instead of a simple flow, a Node-RED Dashboard flow can be created to control the motor via Browser Dashboard.
To send the binary array of bytes a Function Node is required:
Example of a Function Node (JavaScript) to create a Binary Buffer Payload and send via the Serial Node to the Arduino
direction = 2
speed = 150
//Create an array holding direction and speed
var array = [direction,speed]
//Add the array to a binary buffer payload
msg.payload = Buffer.from(array);
return msg;

Node-RED Simple Flow

Code: Select all

{"id":"e882523a.a8af5","type":"serial out","z":"7aa38ac7.9cf4cc","name":"","serial":"70d39577.0b5cb4","x":789.5,"y":92,"wires":[]},

Note: The enhanced Dashboard flow is included in the download.

Download B4R & B4J source code, Node-RED flow

Software Versions
Raspberry Pi Raspian v9.1, Node-RED v.0.17.5, nodejs v6.11.4, Node-RED Dashboard v2.5.1, B4R v2.20, B4J v5.90.

  • Experiment is completed.


Return to “Arduino”

Who is online

Users browsing this forum: No registered users and 1 guest