Arduino DC Motor Protocol

With this devicehandler you can control 1 or 2 DC motors simultaneously connected to the L298N motorcontroller. To control 2 DC motors independently, you need to declare them both in the ino file. They can be controlled in two modes: PWM or normal. The normal mode means digital mode and the signal can be HIGH or LOW (100% speed or 0% speed).

How to build a test circuit with a motor driver, a DC motor and an Arduino Mega?

I. "Welcome" event from microcontroller

Example

c=welcome&id=IqlZci&type=OzDCMotorControllerL298N&pos=2&t=3

Parameters

Parameter Type Range Functionality
c String "welcome" Identifies the welcome message.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
type String "OzDCMotorControllerL298N" Determines the type of the device.
pos Byte 0-255 Determines the position of the device on the list of the ID manager of the microcontroller. Please make sure there are no other devices in the same position.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.



II. Commands to microcontroller

"Set" command

With this command you can determine the speed of the motor. The speed is given in percentage. Negative speed means reverse spinning. You can also set the accel, so you don't need to overstress the motor.

The acceleration parameter is optional. If set, the speed of the motor will grow incrementally (in percent/sec).

Example

//Starts the motor and instantly sets the speed to 30.05
c=set&speed=30.05&t=0&id=IqlZci
//Changes speed with 10%/sec
c=set&speed=60.00&accel=10.00&t=1&id=IqlZci

Parameters

Parameter Type Range Functionality
c String "set" Identifies the command.
speed Double -100.00 to +100.00 Determines the speed percentage of the motor.
accel Double 0 to +100.00 Determines the speed percentage change/sec of the motor. It's a fully optional parameter. If not given, the speed change will be instant. Instant change can be unhealthy for the motor.
t Byte 0-255 Counts the number of commands sent. Counts from 0 to 255 then from 0 again.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.

Response

Responds after the speed is reached. If the "accel" is not sent back, it means that the speed was reached instantly.

//Starts the motor and instantly sets the speed to 30.05 - response
c=set_resp&speed=30.05&t=3&id=IqlZci
//Changes speed with 10%/sec - response
c=set_resp&speed=60.00&accel=10.00&t=4&id=IqlZci

Parameters

Parameter Type Range Functionality
c String "set_resp" Identifies the response.
speed Double -100.00 to +100.00 Responds the speed of the motor.
accel Double 0 to +100.00 Shows the speed percentage change/sec of the motor. If the speed was set instant then there is no accel parameter.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.


"Stop" command

Stops the motor instantly.

Example

//Stops the motor
c=stop&t=2&id=IqlZci

Parameters

Parameter Type Range Functionality
c String "stop" Identifies the command.
t Byte 0-255 Counts the number of commands sent. Counts from 0 to 255 then from 0 again.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.


Response

Responds instantly.

//Stops the motor - response
c=stop_resp&t=5&id=IqlZci

Parameters

Parameter Type Range Functionality
c String "stop_resp" Identifies the response.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.


"Set Min Threshold" command

Sets the mininmum threshold value of the motor.

Example

c=setminthreshold&value=10&t=3&id=IqlZci

Parameters

Parameter Type Range Functionality
c String "setminthreshold" Identifies the command.
value Double -100.00 to +100.00 Value of the min threshold.
t Byte 0-255 Counts the number of commands sent. Counts from 0 to 255 then from 0 again.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.


Response

Responds instantly.

c=setminthreshold_resp&value=10&t=6&id=IqlZci

Parameters

Parameter Type Range Functionality
c String "setminthreshold_resp" Identifies the response.
value Double -100.00 to +100.00 Value of the min threshold.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.


"Set Max Threshold" command

Sets the maximum threshold value of the motor.

Example

c=setmaxthreshold&value=90&t=4&id=IqlZci

Parameters

Parameter Type Range Functionality
c String "setmaxthreshold" Identifies the command.
value Double -100.00 to +100.00 Value of the max threshold.
t Byte 0-255 Counts the number of commands sent. Counts from 0 to 255 then from 0 again.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.


Response

Responds instantly.

c=setmaxthreshold_resp&value=10&t=7&id=IqlZci

Parameters

Parameter Type Range Functionality
c String "setmaxthreshold_resp" Identifies the response.
value Double -100.00 to +100.00 Value of the max threshold.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.


III. Event from microcontroller

None

More information