How To Build A 4WD Arduino Robot For Beginners
How To Build A 4WD Arduino Robot For Beginners
Dann Albright
610 articles
Dann is a freelance
business and technology
Facebook Twitter Pinterest Stumbleupon writer. When he's not on
Email his bike, he's looking for
new ways to help people
Advertisement be productive, meet their
goals, and maintain a
healthy relationship with
technology.
Latest
Giveaways!
Remote controlled cars are fun, sure, but self-driving robotic Oculus Go: Is This
cars are even more fun. In this tutorial, we’ll build a four-
The Best Mobile VR
Yet? (Review and
wheeled robot that can drive around and avoid obstacles. I Giveaway)
purchased this complete 4WD kit from AliExpress, but you
could easily buy most of these components from an Fitbit Versa Review:
electronics store and put it together yourself. Fitbit’s Best
Wearable Yet?
I recommend reading through all of the instructions before
you start, as that will make some things clear that might be This USB-C Hub
confusing on the rst time through. Also, this may look like a Does Everything:
QacQoc GN30H
very long, advanced project due to the length of the Review
instructions, but it’s actually pretty simple. No need to be
intimidated – this is a beginner level project that you can get
some satisfying results with, then build upon as you learn
more. Don’t like this style of robot? Here’s some more Arduino
robots you could easily build instead.
https://www.makeuseof.com/tag/build-4wd-arduino-robot-beginners/ 1/18
15/5/2018 How to Build a 4WD Arduino Robot for Beginners
Trending
TECH NEWS
INTERNET , ANDROID
6 Google Photos
Alternatives to Use
If You’re Tired of…
WINDOWS
What Is Windows 10
To get started, we’ll attach the motors and the H bridge (the Timeline? Why It’s
Great and How…
card that delivers power to the motors) to the lower part of
the chassis. First, attach the four metal brackets (they’re
rectangular, drilled blocks of metal) to each motor using two
long bolts and two nuts.
Related Articles
PRODUCT REVIEWS
INTERNET
DIY
You’ll need to make sure that they’re attached correctly, so 7 Cool Projects You
Can Build With a
check out the image below to make sure that the side of the
Teensy
block with two drilled holes will face downward. Note that the
wires on each motor are pointing toward the center of the
chassis.
https://www.makeuseof.com/tag/build-4wd-arduino-robot-beginners/ 2/18
15/5/2018 How to Build a 4WD Arduino Robot for Beginners
Latest Articles
INTERNET , ANDROID
No Gym
Membership? 5
Workout Apps to
Get Fit for Free
Anywhere
ENTERTAINMENT
Now each motor can be attached to the chassis by using two The 15 Best Shows
short bolts in the bottom of each metal bracket. Here’s a view on Amazon Prime
You Need to Watch
of the bottom of the chassis so you can see where the bolts
need to be:
The next step is to secure the H bridge (that’s the red board, in
my kit) to the chassis. You may want to wait until all of the
wires are attached to the H bridge before doing this, but that’s
up to you (I found it to be easier). A quick note: my kit was
missing a number of fasteners, so I used electrical tape to
secure the bridge. However, you can see here where the bolts
and nuts would have gone:
https://www.makeuseof.com/tag/build-4wd-arduino-robot-beginners/ 3/18
15/5/2018 How to Build a 4WD Arduino Robot for Beginners
Now that the H bridge has been attached, you can start wiring
up the power supply. Because the six-AA battery holder
comes with a DC adapter, you’ll need to either cut off the end
(which I did) or run jumper wires to the batteries themselves.
No matter how you decide to do it, you’ll run the positive wire
to the port labelled “VMS” and the negative wire to the one
labelled “GND” on the bridge. Screw down the fasteners and
make sure they’re secure. Then, you’ll connect the motor
wires. On both sides, there’s a set of two ports; one is labelled
“MOTORA” and the other “MOTORB.” Both red wires on each
side will go into the centermost green port, and both black
wires will go into the outermost. This picture should make it
more clear:
https://www.makeuseof.com/tag/build-4wd-arduino-robot-beginners/ 4/18
15/5/2018 How to Build a 4WD Arduino Robot for Beginners
I found that I had to strip some of the housing off of the motor
wires to get this to work. Now that you have the motors and
the power supply all wired up, slide the wheels onto the motor
drive shafts, and attach the four copper shafts in the locations
show in the picture below (each copper shaft needs one small
bolt). This robot is starting to take shape!
Now, set that part of the chassis aside and grab the other one
which will sit on top. The next step is to attach the Arduino—
again, I had to use electrical tape, but you should be able to
better secure yours with some bolts and nuts.
https://www.makeuseof.com/tag/build-4wd-arduino-robot-beginners/ 5/18
15/5/2018 How to Build a 4WD Arduino Robot for Beginners
The next step requires the micro servo, the black crosspiece,
the servo holder (which consists of three black plastic pieces),
and some small screws. Use one of the larger sharp screws in
the kit to attach the black crosspiece to the micro servo:
Then ip the servo upside down into the black plastic ring of
the holder. Make sure that the wires coming out of the servo
are facing in the same direction as the longer part of the
holder (again, see the image below), and use four tiny screws
to secure the crossbar (there are four holes in the holder that
align with the holes on the crossbar).
https://www.makeuseof.com/tag/build-4wd-arduino-robot-beginners/ 6/18
15/5/2018 How to Build a 4WD Arduino Robot for Beginners
Finally, take the other two pieces of the servo holder and snap
them onto the servo (there are grooves in the side pieces that
match the plastic tab on the servo).
https://www.makeuseof.com/tag/build-4wd-arduino-robot-beginners/ 7/18
15/5/2018 How to Build a 4WD Arduino Robot for Beginners
https://www.makeuseof.com/tag/build-4wd-arduino-robot-beginners/ 8/18
15/5/2018 How to Build a 4WD Arduino Robot for Beginners
It’s time to give our robot some eyes. Attach the ultrasonic
sensor to the servo holder using two zip ties.
https://www.makeuseof.com/tag/build-4wd-arduino-robot-beginners/ 9/18
15/5/2018 How to Build a 4WD Arduino Robot for Beginners
Now grab the lower part of the chassis, and connect six
jumper wires to the I/O pins of the H bridge (they’re marked
ENA, IN1, IN2, IN3, IN4, and ENB). Take note of which color
wires are connected to which ports, as you’ll need to know
later.
Now it’s time to start putting this thing together. Grab the
upper part of the chassis and set it on top of the copper shafts
connected to the lower part, and pull the wires attached to the
H bridge through the hole in the center of the chassis.
Connect the six wires to I/O ports as follows:
https://www.makeuseof.com/tag/build-4wd-arduino-robot-beginners/ 10/18
15/5/2018 How to Build a 4WD Arduino Robot for Beginners
A1 to I/O port 5
A2 to I/O port 6
B1 to I/O port 4
B2 to I/O port 3
Now, use four short screws to attach the upper part of the
chassis to the copper shafts. Set the six-AA battery holder on
top of the chassis (screw it down if you can), attach the 9V cell
holder to the Arduino, and this bot is ready to rock!
https://www.makeuseof.com/tag/build-4wd-arduino-robot-beginners/ 11/18
15/5/2018 How to Build a 4WD Arduino Robot for Beginners
The rst thing we’ll do is test to make sure that the bridge and
motors are hooked up correctly. Here’s a quick sketch that
will tell the bot to drive forward for half a second, drive
backward for half a second, then turn left and right:
https://www.makeuseof.com/tag/build-4wd-arduino-robot-beginners/ 12/18
15/5/2018 How to Build a 4WD Arduino Robot for Beginners
28 forward(200);
29 //Go backward
30 backward(200);
31 //Turn left
32 turnLeft(400);
33 coast(200);
34 //Turn right
35 turnRight(400);
36 coast(200);
37 //This stops the loop
38 run = false;
39 }
40 }
41
42 //Define high-level H-bridge commands
43
44 void enableMotors()
45 {
46 motorAOn();
47 motorBOn();
48 }
49
50 void disableMotors()
51 {
52 motorAOff();
53 motorBOff();
54 }
55
56 void forward(int time)
57 {
58 motorAForward();
59 motorBForward();
60 delay(time);
61 }
62
63 void backward(int time)
64 {
65 motorABackward();
66 motorBBackward();
67 delay(time);
68 }
69
70 void turnLeft(int time)
71 {
72 motorABackward();
73 motorBForward();
74 delay(time);
75 }
76
77 void turnRight(int time)
78 {
79 motorAForward();
80 motorBBackward();
https://www.makeuseof.com/tag/build-4wd-arduino-robot-beginners/ 13/18
15/5/2018 How to Build a 4WD Arduino Robot for Beginners
81 delay(time);
82 }
83
84 void coast(int time)
85 {
86 motorACoast();
87 motorBCoast();
88 delay(time);
89 }
90
91 void brake(int time)
92 {
93 motorABrake();
94 motorBBrake();
95 delay(time);
96 }
97 //Define low-level H-bridge commands
98
99 //enable motors
100 void motorAOn()
101 {
102 digitalWrite(enableA, HIGH);
103 }
104
105 void motorBOn()
106 {
107 digitalWrite(enableB, HIGH);
108 }
109
110 //disable motors
111 void motorAOff()
112 {
113 digitalWrite(enableB, LOW);
114 }
115
116 void motorBOff()
117 {
118 digitalWrite(enableA, LOW);
119 }
120
121 //motor A controls
122 void motorAForward()
123 {
124 digitalWrite(pinA1, HIGH);
125 digitalWrite(pinA2, LOW);
126 }
127
128 void motorABackward()
129 {
130 digitalWrite(pinA1, LOW);
131 digitalWrite(pinA2, HIGH);
132 }
133
https://www.makeuseof.com/tag/build-4wd-arduino-robot-beginners/ 14/18
15/5/2018 How to Build a 4WD Arduino Robot for Beginners
That’s a lot of code for a simple test, but defining all of those
functions makes it easier to tweak later. (Big thanks to Billwaa for
his blog post on using the H-bridge for defining these functions.)
If something went wrong, check all of your connections and that
the wires are connected to the correct pins. If everything worked,
it’s time to move onto the sensor test. To use the ultrasonic
sensor, you’ll want to download the NewPing library, and then
use Sketch > Include Library > Add .ZIP Library… to load the
library.
https://www.makeuseof.com/tag/build-4wd-arduino-robot-beginners/ 15/18
15/5/2018 How to Build a 4WD Arduino Robot for Beginners
Make sure that you see the include statement at the top of
your sketch; if you don’t, hit Sketch > Include Library >
NewPing. Once you’ve done that, load up the following sketch:
1 #include <NewPing.h>
2
3 //Tell the Arduino where the sensor is hooked up
4 NewPing sonar(12, 13);
5
6 long inches;
7
8 void setup() {
9 //Activate the serial monitor so you can see the output of the
10 Serial.begin(9600);
11 }
12
13 void loop() {
14 delay(50);
15 //Ping the sensor to determine distance in inches
16 inches = sonar.ping_in();
17 //Print the distance in inches to the serial monitor
18 Serial.print(inches);
19 Serial.print(" in.");
20 Serial.print("\n");
21
22 }
Upload the sketch, and open up the serial monitor using Tools
> Serial Monitor. You should see a rapidly updating sequence
of numbers. Hold your hand in front of the sensor and see if
that number changes. Move your hand in and out, and you
should get a measurement of how far away your hand is from
the sensor.
https://www.makeuseof.com/tag/build-4wd-arduino-robot-beginners/ 16/18
15/5/2018 How to Build a 4WD Arduino Robot for Beginners
https://www.makeuseof.com/tag/build-4wd-arduino-robot-beginners/ 17/18
15/5/2018 How to Build a 4WD Arduino Robot for Beginners
[email protected] Submit
https://www.makeuseof.com/tag/build-4wd-arduino-robot-beginners/ 18/18