About This Project
A fun DIY electronics/robotics project where you can build a robot that will avoid obstacles using sensors. Makes use of arduino, sensors, and breadboard.
Meet The MakersJoin Team
.1. Hardware Part
To get started, we’ll attach the motors and the H bridge (the 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.
You’ll need to make sure that they’re attached correctly, so check out the image below to make sure that the side of the block with two drilled holes will face downward. Note that the wires on each motor are pointing toward the center of the chassis.
Now each motor can be attached to the chassis by using two short bolts in the bottom of each metal bracket. Here’s a view 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:
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:
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.
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 flip 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).
Here’s what it looks like after it’s attached:
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).
Now that the servo holder is complete, it can be mounted to the chassis.
Here’s where the bolts go:
It’s time to give our robot some eyes. Attach the ultrasonic sensor to the servo holder using two zip ties.
If you’re working from the same kit as I am, you’ll have received anArduino sensor shield. We won’t be using it in this build, but you can pop it on top of the UNO now if you want (as I have in the image below). Just align the pins on the bottom of the shield with the I/O ports on theArduino and press down to connect them. You don’t need it at the moment, but shields can come in handy.
Whether you connect a sensor shield or not, you’ll now need four wires to connect the ultrasonic sensor to the Arduino. There are four pins on the sensor, VCC, GND, TRIG, and ECHO. Connect VCC to the 5V pin on theArduino, GND to GND, and TRIG and ECHO to I/O pins 12 and 13.
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:
- ENA to I/O port 11
- ENB to I/O port 10
- 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!
Well, almost ready to rock. It doesn’t have quite enough personality yet.
There we go. Now to give it a brain. Let’s do some programming.
.2. Software Part
The first 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:
--- Attached in required files
We need to check all steps again firstly before doing a run test.
.4. FutureOnce you've gotten this behavior working correctly, you can add more complex behavior; make the robot alternate between turning left and right, or choose randomly; sound a buzzer if it gets close to something; just turn, instead of backing up; you’re really only limited by your imagination.
Last updated on 07/29/2016