How to Make an Autonomous Wheeled Robot Move | Arduino

In this post, I’ll show you how to make a basic autonomous wheeled robot move forwards, backwards, to the right, and to the left using Arduino.

Shout out to the late Gordon McComb for this project idea. He is the author of an excellent book that I recommend buying if you’re getting started with robotics: How to Make a Robot.

Requirements

Here are the requirements:

  • Make an autonomous wheeled robot move forwards, backwards, to the right, and to the left using Arduino.

You Will Need

The following components are used in this project. You will need:

Directions

First, we need to test the servos to see if they are working. Code up the sketch below into the Arduino Integrated Development Environment (IDE).

Give it a descriptive name like test_servos.ino.

1_code_the_sketchPNG
// Include library that enables us to work with servos
#include <Servo.h> 

/**
 * This program is a test of the servo motors 
 * 
 * @author Addison Sears-Collins
 * @version 1.0 2019-05-11
 */

// Create two servo objects, one for each wheel
Servo right_servo;
Servo left_servo;

/*   
 *  This setup code is run only once, when Arudino is 
 *  supplied with power.
 */
void setup() { 
  
  // Right servo is connected to digital pin 9
  right_servo.attach(9);   

  // Right servo is connected to digital pin 9
  left_servo.attach(10);
} 

/*   
 *  This code repeats as long as the Arduino has power.
 */
void loop() { 
  
  // On the continuous rotation servo, the write() 
  // method sets the speed of the servo.
  // 0 is full speed in one direction.
  // 180 is full speed in the other direction.
  // ~90 is no movement (You will have to tweak to
  //   get no movement).
  
  // Move forwards
  right_servo.write(0);  
  left_servo.write(180);

  // Wait 2 seconds
  delay(2000);

  // Move backwards (reverse)
  right_servo.write(180);  
  left_servo.write(0);

  // Wait 2 seconds
  delay(2000);
/*
  // Turn right
  right_servo.write(180); 
  left_servo.write(180);
  
  // Wait 2 seconds
  delay(2000);

  // Turn left
  right_servo.write(0);    
  left_servo.write(0);     
  
  // Wait 2 seconds
  delay(2000);
  */
}

Make sure the right and left servos are OFF:

  • a13 to j2 = left servo OFF
  • e13 to j28 = right servo OFF
2_servos_are_off

Compile the sketch in the IDE by clicking the checkmark in the upper left corner of the IDE.

3_compile_the_sketchPNG

Upload the sketch to the Arduino board by connecting the USB to your computer. Then click the right arrow (Upload) button on the IDE. The LED on your Arduino should be illuminated.

4_connect_usb
5_right_arrow_arduino_uploadPNG

Remove the USB cord from the Arduino.

Turn ON both servos:

  • a13 to e3 = left servo ON
  • e13 to e28 = right servo ON
6_servos_are_on

Hold the robot in your hand or place the robot on the floor.

Power up the Arduino by plugging in the 9V jack.

Observe the robot move.

7_moving_robot
8_moving_robot

When you are done watching it move, pull the 9V jack out of the Arduino and turn the servos OFF. Remember:

  • a13 to j2 = left servo OFF
  • e13 to j28 = right servo OFF

Here is another sketch (named basic_wheeled_bot.ino) that you can upload to the Arduino that adds some different movements to your robot and breaks up the movements we had in the test code into separate methods. Feel free to play around with this and create your own movement sequence:

// Include library that enables us to work with servos
#include <Servo.h> 

/**
 * This program makes a basic wheeled robot
 * do different movements.
 * 
 * @author Addison Sears-Collins
 * @version 1.0 2019-05-11
 */

// Create two servo objects, one for each wheel
Servo right_servo;
Servo left_servo;

/*   
 *  This setup code is run only once, when Arudino is 
 *  supplied with power.
 */
void setup() { 
  
  // Right servo is connected to digital pin 9
  right_servo.attach(9);   

  // Right servo is connected to digital pin 9
  left_servo.attach(10);
} 

/*   
 *  This code repeats as long as the Arduino has power.
 */
void loop() { 

  // On the continuous rotation servo, the write() 
  // method sets the speed of the servo.
  // 0 is full speed in one direction.
  // 180 is full speed in the other direction.
  // ~90 is no movement (You will have to tweak to
  //   get no movement).
  
  go_forward();

  // Pause 2 seconds
  delay(2000);

  go_backwards();

  // Pause 2 seconds
  delay(2000);
  
  go_right();

  // Pause 2 seconds
  delay(2000);
  
  go_left();

  // Pause 2 seconds
  delay(2000);
  
  stop_all();

  // Pause 2 seconds
  delay (2000);
}

/*   
 *  Forwards, backwards, right, left, stop.
 */
void go_forward() {
  right_servo.write(0);
  left_servo.write(180);
}
void go_backwards() {
  right_servo.write(180);
  left_servo.write(0);
}
void go_right() {
  right_servo.write(180);
  left_servo.write(180);
}
void go_left() {
  right_servo.write(0);
  left_servo.write(0);
}
void stop_all() {
  right_servo.write(90); // Tweak the 90
  left_servo.write(90);  // Tweak the 90
}

Video

How to Wire the Batteries and Motors of a Basic Wheeled Robot

In this post, I’ll show you how to wire the batteries and motors of a basic wheeled robot.

Shout out to the late Gordon McComb for this project idea. He is the author of an excellent book that I recommend buying if you’re getting started with robotics: How to Make a Robot.

Requirements

Here are the requirements:

  • Connect the left servo, right servo, and AA batteries to the solderless breadboard.

You Will Need

The following components are used in this project. You will need:

Directions

Take off all of the insulation from a 6-inch long male-to male jumper wire.

Cut the jumper wire into eight pieces that are each 0.5 inches in length.

wiring_the_robot-1

Use pliers or the end of your wire stripper to push the jumper wire pieces into the connectors of the two servos and the 4 x AA battery holder.

wiring_the_robot-3
wiring_the_robot-4
wiring_the_robot-2

Connect the black lead of the left servo to cell b4 of the solderless breadboard.

wiring_the_robot-5
wiring_the_robot-6

Connect the black lead of the right servo to cell b29 of the solderless breadboard.

wiring_the_robot-7

Connect cell a4, a16, and a29 to the blue (-) negative rail of the solderless breadboard using a jumper wire.

wiring_the_robot-8

Connect the black lead of the 4 x AA battery connector to cell b16. The red lead should sink down in b13.

wiring_the_robot-9

Connect the Digital 10 pin of the Arduino to cell a2 of the breadboard.

wiring_the_robot-11

Connect the Digital 9 pin of the Arduino to cell a27 of the breadboard.

wiring_the_robot-10

Connect the Ground (GND) pin of the Arduino to the blue negative rail of the breadboard (brown jumper wire in the image below).

wiring_the_robot-11-1

Connect a jumper wire from cell a13 to j3 (or any cell on the other side of the groove of the breadboard). This wire provides power (i.e. turned ON) to the left servo when it is connected from cell a13 to cell e3. When it is connected from cell a13 to j2, the left servo is turned OFF.

  • a13 to e3 = left servo ON
  • a13 to j2 = left servo OFF

Connect a jumper wire from cell e13 to j28 (or any empty cell on the other side of the groove of the breadboard, excluding row 2). This wire provides power (i.e. turned ON) to the right servo when it is connected from cell e13 to cell e28. When it is connected from cell e13 to j28, the right servo is turned OFF.

  • e13 to e28 = right servo ON
  • e13 to j28 = right servo OFF
wiring_the_robot-12

That’s it for the wiring. In the next post, we will create a program on Arduino that enables the robot to make basic movements autonomously.

How to Build a Basic Wheeled Robot Base

In this post, I’ll show you how to do build a motorized base for a basic wheeled robot.

Shout out to the late Gordon McComb for this project idea. He is the author of an excellent book that I recommend buying if you’re getting started with robotics: How to Make a Robot.

Requirements

Here are the requirements:

  • Build a motorized wheeled-robot base

You Will Need

wheeled-robot-base-1

The following components are used in this project. You will need:

Directions

First, grab the white foam board and cut it as follows:

  • Two pieces that are 4.5 inches by 3.75 inches in dimensions
  • Two pieces that are 3.75 inches by 1.25 inches in dimensions
wheeled-robot-base-2

Heat up the glue gun (I used the 100 Watt setting) and add a line of glue to one of the smaller boards. Then quickly (before the glue dries) attach one smaller board to the end of one of the larger boards so that the edges are lined up.

wheeled-robot-base-3

Do this again for the other smaller board/larger board set.

wheeled-robot-base-4
wheeled-robot-base-5

Now, glue a wooden hole plug to the middle of the top of one of the small boards using the hot glue gun. This board set is the lower base of the robot. The wooden plug will be in the rear on the underside of the lower base.

wheeled-robot-base-6
wheeled-robot-base-7
wheeled-robot-base-8

On the side opposite of the one with the wooden plug, glue two servo motors on either side. The two handles on either side of the servos need to be aligned with the sides and front of the base.

wheeled-robot-base-9

The shaft of the servo needs to be closest to the end of the base with the wooden plug.

wheeled-robot-base-10
wheeled-robot-base-11
wheeled-robot-base-12

Grab a 9V battery with barrel jack connector and place it between the two servos using a stick of Velcro. The bottom of the battery should NOT hang over the edge of the board. This 9V battery will eventually be used to power the Arduino.

wheeled-robot-base-13

Get another piece of Velcro and place it on the underside of the 4xAA battery holder. Attach a piece of Velcro to the middle of the board on the opposite end of the servos/9V battery.

wheeled-robot-base-14

Using Velcro, place the 4xAA battery holder in the rear (the end with the wooden plugs underneath) of the lower base behind the servos/9v battery. The edge of the battery holder should be even with the board, and the wires should hang out the back of the board.

wheeled-robot-base-15
wheeled-robot-base-16
wheeled-robot-base-17

Now, we need to attach the upper base (the white board set that has nothing attached to it) to the top of the servos. Get two pieces of Velcro and place them on top of the servos. Then lower the upper base down over the servos so that the boards are aligned.

wheeled-robot-base-18
wheeled-robot-base-19
wheeled-robot-base-20
wheeled-robot-base-21

Grab the solderless breadboard and remove one of the two power rails. You can use scissors to cut the adhesive that keeps the power rail stuck to the breadboard.

wheeled-robot-base-22
wheeled-robot-base-23

Peel off the backing on the underside of the solderless breadboard, and attach the breadboard to the top of the robot above the servos so that it is aligned with the edge of the white board. The power rail should be in the middle of the board.

wheeled-robot-base-24
wheeled-robot-base-25

Now Velcro the Arduino to the board, behind the solderless breadboard. Give about 1/8 inch of space between the Arduino and breadboard.

wheeled-robot-base-26
wheeled-robot-base-27

Place the rubber tires over each wheel. You will have to stretch the rubber a bit to get it over the wheel, but rest assured they will fit snugly.

wheeled-robot-base-28

Unscrew the screw in the middle of the servos, and then screw the wheels in to the axle of the servos. If you have one of the four-pronged stubs, just remove it. It pops right off if you give it enough of a tug.

wheeled-robot-base-31
wheeled-robot-base-29
wheeled-robot-base-30

Don’t screw the wheels in too tightly, just snugly.

wheeled-robot-base-32

That’s it! You now have assembled the body of the wheeled robot base. Now we need to connect all those dangling wires to something. We’ll do that in the next post (“How to Wire the Batteries and Motors of a Basic Wheeled Robot“).