In this tutorial, I’ll share with you on how to build a mobile robot using a Maker Drive. Before this we’re using an L298N motor driver and now we’re going to change it to Maker Drive and here are the reasons why:
- Easy to troubleshoot with the push button and LED indicator.
- Support motor voltage from 2.5V to 9.5VDC
- Solid state components provide faster response time and eliminate the wear and tear of mechanical relay
- 5V Output (200mA) to power the controller with minimum input voltage of 2.5V.
HARDWARE PREPARATION
This tutorial use :
You can make the hardware connection based on the diagram and table below.
Connection | |
---|---|
Maker Drive M1A | Maker UNO: Pin 3 |
Maker Drive M1B | Maker UNO: Pin 9 |
Maker Drive 5V | Maker UNO: 5V |
Maker Drive GND | Maker UNO: GND |
Maker Drive M2A | Maker UNO: 10 |
Maker Drive M2B | Maker UNO: 11 |
Bluetooth HC05 : TX | Maker UNO: Pin 2 |
Bluetooth HC05 : RX | Maker UNO: Pin 4 |
Bluetooth HC05 : VCC | Maker Drive: 5V |
Bluetooth HC05 : GND | Maker UNO: GND |

Sample Code
This is the sample code used for this tutorial. Try it!
#define BT_TX 4 | |
#define BT_RX 2 | |
#include "SoftwareSerial.h" | |
SoftwareSerial BTSerial(BT_TX, BT_RX); // Maker UNO RX, TX | |
#include "CytronMotorDriver.h" | |
// Configure the motor driver. | |
CytronMD motor1(PWM_PWM, 3, 9); // PWM 1A = Pin 3, PWM 1B = Pin 9. | |
CytronMD motor2(PWM_PWM, 10, 11); // PWM 2A = Pin 10, PWM 2B = Pin 11. | |
#define BUTTON 2 | |
#define PIEZO 8 | |
#define NOTE_G4 392 | |
#define NOTE_C5 523 | |
#define NOTE_G5 784 | |
#define NOTE_C6 1047 | |
int btConnect[] = {NOTE_G5, NOTE_C6}; | |
int btConnectNoteDurations[] = {12, 8}; | |
int btDisconnect[] = {NOTE_C5, NOTE_G4}; | |
int btDisconnectNoteDurations[] = {12, 8}; | |
#define playBtConnectMelody() playMelody(btConnect, btConnectNoteDurations, 2) | |
#define playBtDisconnectMelody() playMelody(btDisconnect, btDisconnectNoteDurations, 2) | |
boolean BTConnect = false; | |
char inChar; | |
String inString; | |
void setup() | |
{ | |
pinMode(BUTTON, INPUT_PULLUP); | |
Serial.begin(9600); | |
BTSerial.begin(9600); | |
delay(1000); | |
} | |
void loop() | |
{ | |
if (BTSerial.available()) { | |
if (BTConnect == false) { | |
BTConnect = true; | |
playBtConnectMelody(); | |
} | |
inString = ""; | |
while (BTSerial.available()) { | |
inChar = BTSerial.read(); | |
inString = inString + inChar; | |
} | |
Serial.println(inString); | |
if (inString == "#b=0#") { | |
robotStop(); | |
} | |
else if (inString == "#b=9#" || | |
inString == "#b=19#" || | |
inString == "#b=29#" || | |
inString == "#b=39#" || | |
inString == "#b=49#") { | |
robotBreak(); | |
} | |
else if (inString == "#b=1#") { | |
robotForward(); | |
} | |
else if (inString == "#b=2#") { | |
robotReverse(); | |
} | |
else if (inString == "#b=3#") { | |
robotTurnLeft(); | |
} | |
else if (inString == "#b=4#") { | |
robotTurnRight(); | |
} | |
else if (inString.startsWith("+DISC")) { | |
BTConnect = false; | |
delay(1000); | |
while (BTSerial.available()) { | |
BTSerial.read(); | |
} | |
playBtDisconnectMelody(); | |
} | |
} | |
} | |
void playMelody(int *melody, int *noteDurations, int notesLength) | |
{ | |
pinMode(PIEZO, OUTPUT); | |
for (int thisNote = 0; thisNote < notesLength; thisNote++) { | |
int noteDuration = 1000 / noteDurations[thisNote]; | |
tone(PIEZO, melody[thisNote], noteDuration); | |
int pauseBetweenNotes = noteDuration * 1.30; | |
delay(pauseBetweenNotes); | |
noTone(PIEZO); | |
} | |
} | |
void robotStop() | |
{ | |
motor1.setSpeed(0); // Motor 1 stops. | |
motor2.setSpeed(0); // Motor 2 stops. | |
} | |
void robotForward() | |
{ | |
motor1.setSpeed(200); // Motor 1 runs forward. | |
motor2.setSpeed(200); // Motor 2 runs forward. | |
} | |
void robotReverse() | |
{ | |
motor1.setSpeed(-200); // Motor 1 runs backward. | |
motor2.setSpeed(-200); // Motor 2 runs backward. | |
} | |
void robotTurnLeft() | |
{ | |
motor1.setSpeed(-200); // Motor 1 runs forward. | |
motor2.setSpeed(200); // Motor 2 runs backward. | |
} | |
void robotTurnRight() | |
{ | |
motor1.setSpeed(200); // Motor 1 runs backward. | |
motor2.setSpeed(-200); // Motor 2 runs forkward. | |
} | |
void robotBreak() | |
{ | |
motor1.setSpeed(0); // Motor 1 stops. | |
motor2.setSpeed(0); // Motor 2 stops. | |
} | |
Thank you
Thank you for reading this tutorial and we hope it helps your project development. If you have any technical inquiry, please post at Cytron Technical Forum.
1 thought on “Bluetooth Mobile Robot wih Maker Drive”
Hi,
The Maker Driver board connection to Maker UNO board shown in video is different from the sample code.