Four Wheel Drive Robot

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

In this lesson we will expand our knowledge from Two Wheel Drive Robot lesson to build a robot with four wheels and four motors , that`s why we call it Four Wheel Drive or 4WD. For Steering we will still use Differential Steering.


Estimated time: 25 minutes


You will learn about:

Digital Write

 Motor Function

Direction control

Speed Control

4WD

Differential Steering


Components Needed

Main Boardarduino, electronic, card-5170681.jpgUSB Cable
Arduinohand, reach, reaching-5961660.jpgBodymercedes-benz, car, clocks-1464852.jpg
4 pieces Motorsgears, bulb, innovation-1443730.jpg4 pieces Wheelsmegaphone, speaker, speak-2374502.jpg
Hoodhand, reach, reaching-5961660.jpg2 pieces Spacerstechnology, robot, futuristic-3940288.jpg
29 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.jpgScrew Driverspeech icon, voice, talking-2797263.jpg
Plierselectronics, circuit board, computer-1607250.jpgPliers
16 pieces/ M3 Hex Nutmercedes-benz, car, clocks-1464852.jpg18 pieces/ M3 Lock Washerasphalt, nature, street-2178703.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 for the back part of the robot and using the two hex nuts in the front side of the robot acting as hex nut for M3 x 10 screws.] 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 4WD front Support and 4WD back support [|] First the motors will be installed on the outside then the wheels will be installed ][|], so that we can install them on the body.] using 12 M3 x 30 screws, 24 flat washers , 12 lock washers and 12 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;
int M3A=6;
int M3B=12;
int M4A=9;
int M4B=8;

 
 
void setup() {
  
pinMode(M1A, OUTPUT);
pinMode(M1B, OUTPUT);
pinMode(M2A, OUTPUT);
pinMode(M2B, OUTPUT);
pinMode(M3A, OUTPUT);
pinMode(M3B, OUTPUT);
pinMode(M4A, OUTPUT);
pinMode(M4B, OUTPUT);
}
   
void loop() {
  
// Forward
  //M1 Forward
digitalWrite(M1B,LOW);
digitalWrite(M1A,HIGH);
  //M2 Forward
digitalWrite(M2B,LOW);
digitalWrite(M2A,HIGH);
  //M3 Forward
digitalWrite(M3B,LOW);
digitalWrite(M3A,HIGH);
  //M4 Forward
digitalWrite(M4B,LOW);
digitalWrite(M4A,HIGH); 
delay(2000);
  
// Backward
  //M1 Backward
digitalWrite(M1B,HIGH);
digitalWrite(M1A,LOW);
  //M2 Backward
digitalWrite(M2B,HIGH);
digitalWrite(M2A,LOW);
  //M3 Backward
digitalWrite(M3B,HIGH);
digitalWrite(M3A,LOW);
  //M4 Backward
digitalWrite(M4B,HIGH);
digitalWrite(M4A,LOW); 
delay(2000);
 
//Right
  //M1 Backward
digitalWrite(M1B,HIGH);
digitalWrite(M1A,LOW);
  //M3 Backward
digitalWrite(M3B,HIGH);
digitalWrite(M3A,LOW);
//M2 Forward
digitalWrite(M2B,LOW);
digitalWrite(M2A,HIGH);
   //M4 Forward
digitalWrite(M4B,LOW);
digitalWrite(M4A,HIGH);
 delay(2000);
 
//Left
  //M1 Forward
digitalWrite(M1B,LOW);
digitalWrite(M1A,HIGH);
  //M3 Forward
digitalWrite(M3B,LOW);
digitalWrite(M3A,HIGH);
//M2 Backward
digitalWrite(M2B,HIGH);
digitalWrite(M2A,LOW);
  //M4 Backward
digitalWrite(M4B,HIGH);
digitalWrite(M4A,LOW); 
 delay(2000);
 
//Stop
  //M1 Stop
digitalWrite(M1B,LOW);
digitalWrite(M1A,LOW);
//M2 stop
digitalWrite(M2B,LOW);
digitalWrite(M2A,LOW);
  //M3 Stop
digitalWrite(M3B,LOW);
digitalWrite(M3A,LOW);
//M4 stop
digitalWrite(M4B,LOW);
digitalWrite(M4A,LOW); 
 delay(2000);
  
}
Step 7:

Remove the USB cable from the USB port of Arduino.

Step 8:

Install the 4WD Front Support and 4WD Back Support with motors on the body using M3 x 10 screws and lock washers and flat washers and hex nuts.

Step 9:

Connect the motor wires to M1, M2, M3 and M4 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 10:

Install the spacers by removing the two screws at the hood part of the robot holding the Mainboard 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 11:

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

Step 12:

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

Step 13:

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

Step 14:

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 to 8, [|]
  • In lines 12 to 22 ,[|] we have the void setup part of the code.] .
  • In lines 14 to 21,[|] we define our motor driver pins as outputs.] .
  • In lines 26 to 38,[|] we make the robot go forward by creating a potential difference across each motor and they will run full speed ahead.] .
  • In lines 28 and 29,[|] 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 31 and 32,[|] 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 lines 34 and 35,[|] we digital write B pin of motor 3 LOW and digital Write A pin of motor 3 HIGH, making the motor rotate in a direction that makes our robot go forward.] .
  • In lines 37 and 38,[|] we digital write B pin of motor 4 LOW and digital Write A pin of motor 4 HIGH, making the motor rotate in a direction that makes our robot go forward.] .
  • In line 39,[|] we wait 2 seconds for the robot to have the chance to go forward.] .
  • In lines 41 to 53,[|] we digital write our pins the opposite way of the previous time which will make our robot go backwards .] .
  • In line 54,[|] we wait 2 seconds again for the robot to have the chance to go backwards.] .
  • In lines 56 to 68, [|]
  • In line 69,[|] we wait 2 seconds for the robot to have the chance to go right.] .
  • In lines 71 to 83, [|]
  • In line 83,[|] we wait 2 seconds for the robot to have the chance to go left.] .
  • In lines 86 to 98,[|] we make the robot stop by digital writing all the pins LOW. That will feed all motors with 0 volts.] .
  • In line 99,[|] we wait 2 seconds for the robot to stay paused, otherwise, it will immediately do the next operation which is going forward in next loop.] .
Further Experimentation
  • Try using analog write instead of digital write for 3 , 5 , 6 and 9 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 uploading the 2WD code, to make the 4 on 2 WD configuration, then connect M1 and M3 motor wires to M1 screw terminal and M2 and M4 motor s to M2 screw terminal , in a double motor configuration and see how the robot will perform..
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, other steering robots,… also we will use the 4 on 2 WD configuration when we need 4 more pins free for other functions of the robot like servo motors or Music player.
Instagram
Facebook
LinkedIn
YouTube
X (Twitter)
Scroll to Top