Simple Arduino Robot Car For Beginners

Tutorial to show the steps and resources used to build a robot car with an Arduino and a Maker Drive motor driver

Simple Arduino Robot Car For Beginners
Robotic Car with an Arduino Microcontroller and a Maker Drive motor driver

Required Components

  • A chassis (I'm using this kit)
  • Arduino Uno
  • Maker Drive motor driver
  • Batteries (Example: 4 x AAA batteries)
  • 2 x DC Motors (If not included in your chassis kit)

Circuit Diagram

Circuit diagram using Arduino, Maker Drive and two DC motors
Circuit diagram using Arduino, Maker Drive and two DC motors

Code

The code is based on the code example from Cytron, the provider of the Maker Drive motor driver.

I've made a few changes to it, just to try it out and let the car do something a little bit different.
In this code, the car drives around in a right-handed circle:

Click to see some code
#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.

// The setup routine runs once when you press reset.
void setup() {
}

// The loop routine runs over and over again forever.
void loop() {
    robotStop();
    delay(1000);
    for (int i = 0; i < 4; i++)
    {
        robotForward();
        delay(1000);
        robotTurnRight();
        delay(1000);
    }
}

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.
}

Running the motors without the Arduino

The Maker Drive motor driver is great to get started for beginners. It has a simple design and is quite easy to use. It also has great documentation, which is always helpful.

The first thing to do is to connect batteries and the motors to the driver and test it, to make sure everything works.

As per the diagram at the top, connecting the motors and battery to the driver is rather simple.
Connect the battery to the power input terminal (green) and the motors to each of the motor output terminals (black).

Once everything is connected, you can test the driver and make sure the motors run. You can do that by pushing the white buttons on the driver. See the video below:

0:00
/
Motor running with Maker Drive 

You should also see the small LEDs light up when the buttons are pressed. So if you are having any troubles, it can be useful for debugging.

Once you've verified that everything works, you can start connecting the Arduino.

Connecting the Arduino

Cool, the motors are working!

Now, we need something to control them. That's where the Arduino comes in.

To connect the Arduino, you can use the below table and the diagram at the top as guidance.

Connections:

Maker Drive Arduino UNO
M1A Pin 3
M1B Pin 9
5V 5V
GND GND
M2A Pin 10
M2B Pin 11

When all the things are connected, you can then upload the code to the Arduino and your car will soon after start going in circles:

0:00
/
Completed DIY robot car going in circles!

The video above shows the car with the default code from Cytron and the one below shows it running with my modified code, driving in a "big" circle:  

0:00
/
Car running with modified code

If you're having any troubles connecting and setting it up, I can also recommend this video from Cytron on getting started with the Make Drive with an Arduino.

Thanks

Woohoo, it works!

I hope you enjoyed that :)
I'll soon be coming out with an article on how to use a pyboard instead of the Arduino board, in order to get familiar with another microcontroller.


Thank you for reading.