Building an Arduino Robot, Part III: Assembling the Robot
Posted byon under
Welcome to the third article in the tutorial series in which I'm building a remote controlled Arduino based vehicle robot.
Here is the list of articles I have published:
- Part I: Hardware Components
- Part II: Programming the Arduino
- Part III: Assembling the Robot (this article)
- Part IV: A (Not So) Basic Robot Firmware
- Part V: Avoiding Obstacles
- Part VI: Remote Control
In the previous article I introduced you to the programming side of my Arduino project, and I wrote a number of Arduino sketches that test the different hardware parts of my robot.
Today I'm taking a break from programming and instead, I will show you how I built and tested my robot hardware.
If you read my first article you know that I'm using the Magician Chassis two wheel vehicle kit. The kit includes the plastic chassis, wheels, motors, battery box and screws. I'm not going to show you the step-by-step assembly of the kit, as the instructions that come with it are easy to follow. What I will tell you though, is one thing I did differently.
The manufacturer suggests attaching the battery box to the lower platform, but that would require unscrewing the top platform to change the batteries. To avoid that hassle, I have attached the box to the top platform.
Here is the vehicle kit, fully assembled:
The top platform of the vehicle comes with a lot of slots where things can be attached. To mount the Arduino board there I attached three standoffs with screws from underneath. I kept them a bit loose until I found the right positions that matched the mounting holes in the board. Unfortunately I could not find a combination of slots that allowed me to match all four mounting holes, so three had to do:
The board ended up a tiny bit crooked with respect to the platform, but other than that it was pretty solid:
I then needed to mount the breadboard in the front of the vehicle. The bottom of the breadboard has adhesive, but since I wasn't sure everything would work fine with this configuration I decided to simply attach it with a rubberband and keep the option to undo the whole thing without complications:
The next step was pretty tricky. I now needed to mount the motor shield on top of the Arduino board, but once I mount it I lose access to the pins that I need to connect the distance sensor and the bluetooth slave.
As I mentioned in a previous article, the prebuilt Adafruit motor driver that I ordered is pretty good, but unfortunately it plugs into every available pin in the Arduino board and does not provide pass-thru headers.
So how can I connect my devices and the motor shield at the same time?
There are actually a few possible solutions:
- While there are no pass-thru headers, the board does have contacts that expose some of the pins, like the six analog pins and the always needed
GND. So if I wanted to solder my way out of the problem I could.
- The Screw Shield solves my problem nicely. This is a shield that plugs in between the Arduino board and the motor shield and provides access to the pins from the side.
- Buy another motor shield that has pass-thru headers.
- Buy a motor shield kit and solder the components it myself, adding pass-thru headers.
Buying the screw shield or another motor shield are the cleanest two solutions to the problem, but unfortunately I did not have either at hand when I was building the robot, and didn't want to postpone the building for a few days until I can get them in the mail.
So what did I do? I cut a few short pieces of cable and inserted their stripped ends in the pins that I needed before I crunched them in place with the motor shield.
The pins that I needed to use were six:
A1(pins 14 and 15) for the
Echopins of the distance sensor.
TX(pins 0 and 1) for the bluetooth slave.
GNDto send power to the breadboard.
Here is the Arduino board with the cables in place, before I inserted the motor shield:
And here it is with the motor shield in place:
Once the motor shield went in the cables could not be removed, so this solution will likely hold until I can get a better alternative. Unfortunately I only had white cable, as I would have preferred to use colored cables to make it more clear what each cable was and, why not say it, to make the robot a bit more colorful. Oh, well...
The last step in building the robot was to make all the connections, so I started by inserting the distance sensor and the bluetooth slave in the breadboard.
The white cables from the
GND pins went into red and blue pins in the breadboard. Then using red and blue jumper cables I extended the power to the proper pins in the distance sensor and bluetooth slave.
The white cables coming out of analog pins 0 and 1 went to pins
Echo in the distance sensor, and the ones from digital pins 0 and 1 went to the bluetooth slave.
Finally, I attached the red and black cables from the two motors that came with the vehicle kit to motor inputs M1 and M3 in the motor shield.
If you don't understand these connections check out the previous article, where I included connection diagrams and explained in detail how these hardware components work.
Right after I completed the assembly of the robot I wanted to make sure the connections were working.
So what I did is simple. I uploaded the three sketches from the previous article that control the distance sensor, the motors and the bluetooth slave one by one to test each component individually.
As I mentioned in the previous article, when the bluetooth slave is connected to the serial pins in the Arduino board the serial communication with the computer to upload sketches does not work very well, so each time I needed to upload a new sketch I unplugged the red power cable that goes to the bluetooth device to make sure there was no interference.
In the end I verified that all the components worked fine, so I called the hardware assembly phase complete!
Introducing... the Michelino!
Without further ado, let me introduce you to my completed robot, which I have named Michelino (pronounced mi-keh-lee-no):
My robot hardware is complete, now I need to give it its brains.
In the next few articles I will write the robot software in C++. This is no small task, as I will be writing the software from scratch. As a side note, I plan to release the code as open source for others to learn from, enjoy or improve.
Stay tuned, as this is bound to get interesting pretty soon!
Become a Patron!
Hello, and thank you for visiting my blog! If you enjoyed this article, please consider supporting my work on this blog on Patreon!
#1 Dimitri said 2013-01-23T14:17:59Z
Very informative and interesting read. I've ordered all the parts and can't wait for the programming part.
#2 denbo said 2013-02-01T17:21:46Z
I was confused by your statement about the Adafruit motor shields. I've built many of them and I always added pass thru headers.
Then I looked at your link to Amazon and noticed it's a pre-built Adafruit 'clone' from SainSmart. Since it is pre-built they already soldered up the headers.
You can buy the motor shield direct from Adafruit and purchase the pass thru headers. Of course, that means you need to completely assemble the motor shield. If soldering is not your bag then your choice to go with the Arduino motor shield makes sense.
Also note that most of the common Arduino motor shields (Arduino, Sparfun, etc...) do not need a library like the Adafruit does. You just set the two PWM signal pins for speed (with analogWrite()) and direction pins to either HIGH or LOW. Not much work.
One other comment to make... it is often times a good idea to have two power supplies: one for the motors and another for the Arduino. Noise from the motor can affect how well your Arduino runs, especially if you have a lot of analog sensors.
The adafruit motor shield has a jumper on the board that dictates whether to power the Arduino through the VIN pin (from the same batteries as the motor) or from separate power supply. A 9v battery with a 2.1mm power plug works well.
#3 Miguel Grinberg said 2013-02-02T03:43:55Z
@denbo: thank you for your comment, you are giving me pretty useful information. I have clarified a little bit better that I'm using a pre-built Adafruit motor shield. I've said in a past article that for this project I decided I was not going to solder, I wanted to keep it simple. Regarding the "other motor shields do not need a library" comment, that is really subjective. If you think about it a library is just C++ code moved to another file, so in reality any component can be controlled without a library even the Adafruit motor shield just by putting the code that controls it in your sketch. The decision to use a library is more a design choice, not a necessity. I, for example, would write my own library for any of those other motor shields for which the manufacturer does not give you one. I'm trying to make the point that to have a well structured application you have to modularize, so libraries are your friend :). Regarding the dual power supply yes, I can see that my robot would benefit for 9V on the motors so I will explore that option at some point. Thanks again!
#4 denbo said 2013-02-02T04:30:47Z
Miguel, please let me clarify something if I may. When I said you 'need' a library for the Adafruit I mean you really NEED Adafruit's library. This is because in order to talk to the 2 L293D chips it goes through a 74HC595N shift register latch. The communication is a bit complicated.
Whereas most other motor shields do not have a corresponding library like the Adafruit does. They just tell you what the direction pins are and which PWM pins control speed. I was not suggesting you should not write your own library, I simply meant that most motor shields do not come with one.
As for the 9v battery that should hook up to the Arduino not to the motors. A single 9v battery can't run the motors. I generally use 8 AA batteries to power the motors and a 9v to power the arduino. A good reference is on Adafruit's website (see second paragraph) http://www.ladyada.net/make/mshield/use.html
#5 Gabriel said 2013-08-16T10:51:40Z
something's wrong with the sketch:
michelino:141: error: 'rightMotor' was not declared in this scope
michelino:140: error: 'leftMotor' was not declared in this scope
#6 Miguel Grinberg said 2013-08-19T22:53:31Z
@Gabriel: Are there any errors or warnings before these? You are probably missing some of the files, or maybe the Arduino libraries for the motors.
#7 Mike Smith said 2013-11-12T14:51:18Z
Thank you for a great tutorial, very easy to understand and very informative. well done
#8 Aniket reddy shamirpeta said 2014-01-24T02:48:57Z
My project is robotic arm will pick a pencil from a cup and move its arm towards the shaperner place in it.the sharpernwr should sense that pencil is place and it should rotate for some time for which pencil is sharped.later robotic arm again pick it from it and place back into cup.
I want the coding for the opening and closing for robotic arm could any one help.I am using mechanical robotic arm and servo to control it.
#9 shishir said 2014-01-25T20:20:41Z
hey dude u r awesome man ur articles are helping a lot thnx buddy. I jst wanted to tell u that i am soon ordering the entire kit so if in the course of essembling the parts(connecting all the wires and all) if i have any problem so at that case could u plz tell me the wiring part in skype or any other video chatting app or site. Thnx!!!!!
#10 Valentin said 2014-01-30T08:49:04Z
I've started reading your Flask tutorial and was very impressed by it.
Now I've found this tutorial and was so amused. I've ordered exactly the same set of hardware and mechanical parts a year ago but still waiting for the opportunity to start tinkering. With your tutorial I will begin right the next week end!
#11 aurdinonewbie said 2014-02-22T04:21:13Z
Your tutorial is so easy to understand but also explains not just the electronics but object oriented programming really well. I really hope you are teaching somewhere, otherwise many students are missing out.
#12 Nvedia said 2014-04-28T03:50:35Z
Please let me know if this chassis would work fine in place of Magician Chassis cause I really want to use 4 wheels
Are the specifications ok?
#13 Miguel Grinberg said 2014-04-29T15:50:17Z
@Nvedia: Sure, you can use a four wheel model just fine.
#14 Kevin said 2014-05-28T06:34:29Z
I am definitely ordering the parts next week this looks great and descriptive also hard which is what I need to learn
#15 Kevin said 2014-05-28T06:39:58Z
Does it move
#16 Miguel Grinberg said 2014-05-28T15:57:20Z
@Kevin: the robot does not move at this phase of the tutorial. The remaining articles explain how to write the software to make it move.
#17 Kapil Surve said 2014-06-16T12:26:33Z
Hi, Miguel, I cant afford to buy the magician chassis.. Can you suggest some parts which I can use to make the body of vehicle?
#18 Miguel Grinberg said 2014-06-16T15:42:23Z
@Kapil: look for robot vehicle chassis on ebay.
#19 jay said 2015-01-30T01:04:13Z
Great tutorial. Thanks for taking the time to write it up so thoroughly.
I just purchased the Adafruit motor shield v2.3.
Do you know if I can stack this with my arduino uno without Soldering, a skill I currently am virtually clueless about. I checked the manual and it seems it's a requirement, but just didn't know if you knew anything more that I couldn't find.
Or do you think I should just bite the bullet and finally learn solder? I'm not a huge fan of permanently combining the two boards.
#20 Miguel Grinberg said 2015-02-01T03:18:55Z
@jay: I believe Adafruit sells the motor driver as a kit, so you will have to put it together by soldering. But you can find clones that come assembled on amazon or ebay.
#21 hello123 said 2015-02-23T09:16:36Z
Hey buddy how did you connect the motors with the board, since i have a chassis should i cut the wires and than connect them to the b oard
#22 Miguel Grinberg said 2015-02-25T06:37:59Z
@hello123: the wires from the motors connect to the motor driver, so it depends on what connector you have there.
#23 Ricky said 2015-03-17T00:35:02Z
Great guide, but I'm a little confused. Where do I attach the battery pack? Do i connect it directly to the arduino board or do I connect it to the motor shield?
#24 Miguel Grinberg said 2015-03-17T03:40:48Z
@Ricky: the simplest way is to power the Arduino with the batteries, then have the motors draw power from the Arduino. Depending on the hardware this may not give the motors enough power, so in those cases you can connect a separate power source directly into the motor shield.
#25 aahd said 2015-03-29T20:10:40Z
I'm getting some trouble with the Bluetooth module. At first it was working but when I reached this article where it had asked to combine both components onto the circuit things started acting up. The distance sensor works fine on its own but when I try to get the Bluetooth module to work on its own it doesn't do what it's supposed to do. Instead of printing "Receive: ' onto the serial monitor and on my phone it keeps displaying 'Distance: 0cm' when the distance sensor sketch and component isn't even connected to the circuit. What could be the problem? It's a weird one.