Two Wheel Drive Robot

bulb, 4k wallpaper 1920x1080, beautiful wallpaper-5665770.jpg

In this lesson we will learn how to use the knowledge we have from analog write lesson to actually build a robot that moves around, It will b driven by two motors , that`s why we call it Two Wheel Drive or 2WD. For Steering we will use Differential Steering.

Estimated time: 15 minutes

You will learn about:

Digital Write

 Motor Function

Direction control

Speed Control


Differential Steering

Components Needed

Main Boardarduino, electronic, card-5170681.jpgUSB Cable
Arduinohand, reach, reaching-5961660.jpgBodymercedes-benz, car, clocks-1464852.jpg
2 pieces Motorsgears, bulb, innovation-1443730.jpg2 pieces Wheelsmegaphone, speaker, speak-2374502.jpg
Hoodhand, reach, reaching-5961660.jpg2 pieces Spacerstechnology, robot, futuristic-3940288.jpg
17 pieces/ M3 Flat Washercontroller, playstation, hand-852271.jpg4 pieces M3 nylon washersbridge, illuminated, multicoloured-1092256.jpg
10 pieces M3 x 8 Screwsimac, apple, mockup-606765.jpg2 pieces M4 x 45 screwsspeech icon, voice, talking-2797263.jpg
8 pieces M4 hex nutselectronics, circuit board, computer-1607250.jpg4 pieces M4 nylon Washershand, reach, reaching-5961660.jpg
2 pieces M4 Lock Washersmercedes-benz, car, clocks-1464852.jpg4 pieces M4 Flat Washersasphalt, nature, street-2178703.jpg
Caster Whelbridge, illuminated, multicoloured-1092256.jpgScrew Drivermars, mars rover, space travel-67522.jpg
Pliersmegaphone, speaker, speak-2374502.jpg6 pieces/ M3 x 30 Screws
10 pieces/ M3 Hex Nutmegaphone, speaker, speak-2374502.jpg12 pieces/ M3 Lock Washerimac, apple, mockup-606765.jpg
Step 1:

Install Mainboard on the body [|] For that, you need to use M3 x 10 screws in the installation holes with Nylon washers touching the Mainboard, [|], then using flat washers touching body and nylon washers and lock washers after that and then hex nut.] using screw driver and pliers.

Step 2:

Install the Caster Wheel on the Main Board using M4 Screws Like here.

Step 3:

Install the motors on the both sides of the body [|] We use the in body configuration for motors][|], Where the Wires of the motors come out of them should face the walls.] using 6 M3 x 30 screws, 12 flat washers , 6 lock washers and 6 hex nuts.

Step 4:

Connect [|] For that, you need to place the Arduino on top of the Arduino pin headers [|], the USB port of it facing the edge of the board, and while you can see the access pins of the pinheader at both sides of the Arduino board, then push it in place to ensure the board is in place.] the Arduino to the Main board.

arduino, electronic, card-5170681.jpg
Step 5:

Plug in the USB cable[|] the USB type B to Micro USB, which you can get from a cellphone charger also] to the Micro USB port of Arduino and then plug it to the USB port of the computer.

usb, logo, input-1773302.jpg
Step 6:

Upload [|] Follow this] the following code to the Arduino.

int M1A=3;
int M1B=4;
int M2A=2;
int M2B=5;

void setup() {
pinMode(M1A, OUTPUT);
pinMode(M1B, OUTPUT);
pinMode(M2A, OUTPUT);
pinMode(M2B, OUTPUT);
void loop() {
// Forward
  //M1 Forward
  //M2 Forward

// Backward
  //M1 Backward
  //M2 Backward


  //M1 Backward
//M2 Forward


  //M1 Forward
//M2 Backward


  //M1 Stop
//M2 stop

Step 7:

Remove the USB cable from the USB port of Arduino.

Step 8:

Connect the motor wires to M1 and M2 Screw terminal using the screw driver. The red wire goes to The Terminals closer to Cellpack, the black wires goes to the terminals away from Cellpack.

Step 9:

Install the spacers by removing the two screws at the hood part of the robot and placing the spacers on top and fastening the screws from beneath having the Nylon washers touching the Mainboard and flat washer and spring washers under it .

Step 10:

Install the Hood on the body with M3 x 10 screws.

Step 11:

Install the Cellpack in its place [|] and connect the DC power jack Connector to female DC connector on the Mainboard.

Step 12:

Put the 2C , 3C , 4C and 5C Jumper Caps [|] in the connecting state so the two corresponding pins connect to each other.

Step 13:

Turn the Cellpack on [|] and check the movement of the robot, we have four movements, robot forward, robot backwards,robot turning right, robot turning left.

Congratulations! You have your own Robot now.

Code Explanation
  • In lines 1 ,2 ,3 and 4 [|]
  • In lines 7 to 13 ,[|] we have the void setup part of the code.] .
  • In lines 9 to 12,[|] we define our motor driver pins as outputs.] .
  • In lines 17 to 23,[|] we make the robot go forward by creating a potential difference across each motor and they will run full speed.] .
  • In lines 19 and 20,[|] we digital write pin B of motor 1 LOW, giving it zero volts and digital write pin A of motor 1 HIGH, giving it maximum voltage available.] .
  • In lines 22 and 23,[|] we digital write B pin of motor 2 LOW and digital Write A pin of motor 1 HIGH, making the motor rotate in a direction that makes our robot go forward.] .
  • In line 25,[|] we delay 2000 milliseconds or 2 seconds for robot to go forward.] .
  • In lines 29 to 33,[|] we digital write our pins the opposite way of the previous time which will make our robot go backwards .] .
  • In line 35,[|] we wait 2 seconds again for the robot to have the chance to go backwards.] .
  • In lines 37,to 43, [|]
  • In lines 47 to 53,[|] we perform our going left maneuver , for that we move our M1 motor which is our right motor going forward and our M2 motor which is our left motor go backwards to make the robot go left. Again there are more strategies for going left that we used one here] .
  • In lines 57 to 63,[|] We make the robot stop by digital writing all the control pins going to both motor drivers LOW. That will feed the motors with 0 volts.] .
Further Experimentation
  • Try using analog write instead of digital write for 3 and 5 pins and try giving the robot different speeds.
  • Try using other turning strategies like one motor pause, the other one going forward or other one going backwards.
  • Try increasing the delay times and see for the going forward part the robot exactly goes on a straight line, if not , try calibrating the motors by giving different speeds to motors.
Practical Usage For our Projects
  • We will use these codes for all kinds of robots on wheels and will combine that with other configurations to build remote controlled robots and transformer robots.
X (Twitter)
Scroll to Top