Line Following Robot Using Arduino and Maker Drive

In this tutorial, I’ll share with you on how to build a Line Following robot using Arduino and 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:

  1. Easy to troubleshoot with the push button and LED indicator.
  2. Support motor voltage from 2.5V to 9.5VDC
  3. Solid state components provide faster response time and eliminate the wear and tear of mechanical relay
  4. 5V Output (200mA) to power the controller with minimum input voltage of 2.5V.

HARDWARE PREPARATION

This tutorial use :

  1. Maker UNO Bluetooth Robot Kit
  2. Maker Drive
  3. IR Line Tracking Module x2

You can make the hardware connection based on the diagram and table below.

Connection
Maker Drive : M1AMaker UNO: Pin 3
Maker Drive : M1BMaker UNO: Pin 9
Maker Drive : 5VMaker UNO: 5V
Maker Drive : GNDMaker UNO: GND
Maker Drive : M2AMaker UNO: 10
Maker Drive : M2BMaker UNO: 11
Left Tracking Module : DOMaker UNO: Pin A0
Right IR Tracking Module : DOMaker UNO: Pin A1

Reference Video

This is the reference video on how to install the library.

Sample Code

This is the sample code used for this tutorial. Try it!

#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 IR_LEFT A0
#define IR_RIGHT A1
#define NOTE_G4 392
#define NOTE_C5 523
#define NOTE_G5 784
#define NOTE_C6 1047
int startMelody[] = {NOTE_G5, NOTE_C6};
int startNoteDurations[] = {12, 8};
int stopMelody[] = {NOTE_C6, NOTE_G5};
int stopNoteDurations[] = {12, 8};
#define playStartMelody() playMelody(startMelody, startNoteDurations, 2)
#define playStopMelody() playMelody(stopMelody, stopNoteDurations, 2)
char inChar;
String inString;
void setup()
{
pinMode(BUTTON, INPUT_PULLUP);
pinMode(PIEZO, OUTPUT);
pinMode(IR_LEFT, INPUT);
pinMode(IR_RIGHT, INPUT);
Serial.begin(9600);
}
void loop()
{
if (digitalRead(BUTTON) == LOW) {
playStartMelody();
while (true) {
if (digitalRead(IR_LEFT) == LOW &&
digitalRead(IR_RIGHT) == LOW) {
robotForward();
Serial.println("Forward");
}
else if (digitalRead(IR_LEFT) == HIGH &&
digitalRead(IR_RIGHT) == LOW) {
robotTurnLeft();
Serial.println("Left");
}
else if (digitalRead(IR_LEFT) == LOW &&
digitalRead(IR_RIGHT) == HIGH) {
robotTurnRight();
Serial.println("Right");
}
else if (digitalRead(IR_LEFT) == HIGH &&
digitalRead(IR_RIGHT) == HIGH) {
Serial.println("stop");
robotStop();
playStopMelody();
break;
}
}
}
}
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(150); // Motor 1 runs forward.
motor2.setSpeed(150); // Motor 2 runs forward.
}
void robotReverse()
{
motor1.setSpeed(-150); // Motor 1 runs backward.
motor2.setSpeed(-150); // Motor 2 runs backward.
}
void robotTurnLeft()
{
motor1.setSpeed(150); // Motor 1 runs forward.
motor2.setSpeed(-150); // Motor 2 runs backward.
}
void robotTurnRight()
{
motor1.setSpeed(-150); // Motor 1 runs backward.
motor2.setSpeed(150); // Motor 2 runs forkward.
}

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.

3 thoughts on “Line Following Robot Using Arduino and Maker Drive”

  1. Wsalam Pn Nurul Iliani. Pn boleh klik pada link produk di “This tutorial use:”. Terima kasih.

  2. Assalamualaikum. Saya puan nurul dari pulau pinang. Untuk line following robot arduino set ni, macam mana saya boleh dapatkanya ye? Berapa kos untuk 1 set? Terima kasih

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

DIY Interactive Robot Using REKA:BIT With Micro:bit
BLTouch Installation for Ender 3 with 32-bit V4.2.2 Board
Pick and Send Random Meal’s Option and Locations through Telegram Bot Using Grove WiFi 8266 on micro:bit
DIY Automated Vacuum Cleaner Using REKA:BIT With Micro:bit
Rainbow Spark in Mini House using Maker Uno.
Tutorials of Cytron Technologies Scroll to Top