Building an Arduino Robot, Part III: Assembling the Robot

Posted by Miguel Grinberg under Arduino, Robotics.

Arduino Robot

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:

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:

Arduino Robot

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:

Arduino Robot

The board ended up a tiny bit crooked with respect to the platform, but other than that it was pretty solid:

Arduino Robot

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:

Arduino Robot

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 5V and 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:

  • A0 and A1 (pins 14 and 15) for the Trig and Echo pins of the distance sensor.
  • RX and TX (pins 0 and 1) for the bluetooth slave.
  • 5V and GND to send power to the breadboard.

Here is the Arduino board with the cables in place, before I inserted the motor shield:

Arduino Robot

And here it is with the motor shield in place:

Arduino Robot

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 5V and 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 Trig and 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.

Testing

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):

Arduino Robot

Arduino Robot

Final words

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!

Miguel

18 comments

  • #1 Dimitri said :

    Very informative and interesting read. I've ordered all the parts and can't wait for the programming part.

  • #2 denbo said :

    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. Good luck.

  • #3 Miguel Grinberg said :

    @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 :

    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 :

    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 :

    @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 :

    Thank you for a great tutorial, very easy to understand and very informative. well done

  • #8 Aniket reddy shamirpeta said :

    Hai SIR 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 :

    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 :

    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!

Leave a Comment

Note: all comments are screened before they are published. Thank you for your patience!