2012-12-28T07:59:28Z

Building an Arduino Robot, Part I: Hardware Components

Posted by Miguel Grinberg under Robotics, Arduino.

Arduino Robot

I have been doing software for almost as long as I have memory. I have also been following the open source hardware movement since its inception a few years ago, but I have never found the time or the disposition to attempt a hardware project myself.

Until now, that is.

I have decided to do a small hardware project to get my feet wet, a project that I will fully document and discuss here with the hope to encourage and motivate others to do the same.

Here is the list of articles I have published:

Deciding what to build

For the hardware platform I have decided on the Arduino. This was an easy choice, as this is a platform that is widely used by hardware tinkerers all over the world, which means there is plenty of information and resources available.

The choice of a project that is in line with my (limited) knowledge was also pretty easy to make. I knew I wanted to build a cool toy, something I can impress my kids with. That pretty much reduced the list of options to just one: a robot.

But what kind of robot? A humanoid robot would be awesome to build, but it does not seem like a good choice for a first project. I needed something easy enough that I can complete in a relatively short amount of time, yet hard enough to be interesting and challenging.

After some Googling to see what other people do with Arduinos I have settled on a remote controlled robot vehicle.

As I said before I wanted to make this challenging, so I decided against buying a kit that includes all the parts, the software and the instructions. Instead, I decided to come up with a relatively custom robot design, get the parts I needed and figure out how to build it and program it without any specific instructions.

Here are the features I decided my robot will have:

  • It should be a vehicle that can move forward, backwards and turn.
  • It should be easy to assemble and disassemble.
  • It should have a mode in which it is able to move on its own, detecting obstacles ahead and avoiding them.
  • It should have a mode in which it can be fully controlled from my Android smartphone.
  • It should be easy to hack, change and improve.

Does this sound interesting enough to you? I hope it does, it certainly does to me!

Shopping list

With the above feature list in hand I went on to research what parts I needed for my project. Here is the list I came up with:

  • Arduino board
  • Motor controller
  • Distance sensor
  • Bluetooth slave
  • Prototyping board and cables
  • USB cable
  • Vehicle kit

The Arduino board

Arduino Robot

The Arduino board will be the brain of the robot, as it will be running the software that will control all the other parts.

My son had an old Arduino Uno that he ended up not using, so I did not need to buy one. There are plenty of Arduino models or even Arduino compatible boards that can be used.

My recommendation: Arduino Uno R3, currently $21.95 at Amazon.

The motor driver

Arduino Robot

The Arduino board cannot directly control a motor. The tricky part is to be able to make the motor selectively run forward or backwards, which requires swapping power and ground inputs into the motor.

There is a specialized circuit called an H-Bridge that can do this, and there are several implementations of this circuit readily available for the Arduino platform, or you can also build one from basic parts for next to nothing.

Without having much knowledge about this I bought the cheapest motor controller board I've found, a fully assembled version of the Adafruit motor shield at Amazon for $13.99. Later I realized with this board I will need to work around a design issue, so if I had to buy again I would get a more expensive one. More about this later.

My recommendation: Arduino Motor Shield R3, for $33.01 at Amazon.

The Distance Sensor

Arduino Robot

Distance sensors send an ultrasonic signal forward and then wait to receive a bounced signal. Depending on how long the signal takes to bounce back the approximated distance to an obstacle can be calculated. I will use this little device to prevent the robot from hitting walls or other obstacles in its way.

Browsing on Amazon I found a cheap and highly regarded component, the HC-SR04, currently selling for $6.59. This is a nice component that will not only give the robot the ability to see but also give it cool looking eyes!

My recommendation: HC-SR04, for $6.59 at Amazon.

The Bluetooth Slave

Arduino Robot

The easiest way to control the robot from a smartphone is via the bluetooth serial interface that all modern smartphones have. The phone will act as a master, so I needed a bluetooth slave for the robot.

Browsing on Amazon I found the BT2S Bluetooth to Serial Slave which seems to fit the bill nicely.

My recommendation: BT2S Bluetooth to Serial Slave, for $14.95 at Amazon.

The Prototyping Board and Cables

Arduino Robot

Arduino Robot

One of the restrictions I decided to impose myself with this project is that I would not do any soldering, so that I can assemble and disassemble the robot to my heart's content without ruining any parts.

Then I needed a platform where I can easily connect all the components together. For this kind of task people typically use a breadboard. Browsing on Amazon I found one from microtivity that comes with a set of jumper cables.

My recommendation: microtivity IB401, for $8.66 at Amazon.

The USB Cable

Arduino Robot

The Arduino board is connected to a computer via a USB port. The USB connection is used to upload software and also can be used as a power source when testing.

I took a cable from an old printer I have, so I did not need to buy this item. If you need to buy a cable, make sure you get the right connectors. The computer side is the standard A-Male, but on the Arduino side you need a B-Male connector.

My recommendation: Amazon Basics USB 2.0 A-Male to B-Male Cable, 6 feet for $5.49 at Amazon.

The Vehicle Kit

Arduino Robot

There are many choices for robot friendly vehicles. My only requirements were that it had a large platform where all the parts can be mounted and that it came with the wheels and motors.

In the end I decided to get the Magician Chassis. This is a kit that is extremely simple to build. It includes two motors and a battery box that plugs directly into the Arduino board.

My recommendation: Magician Chassis, for $25 at Amazon.

The total cost for the parts above gets to around $115 if you go with my recommendations, but if you want to save money you could certainly spend less and do more work.

Final words

Thank you for reading the first part of my tutorial series, I hope you found it useful.

In the second article I will fire up my Arduino board, introduce you to the Arduino development environment and finally write a few little Arduino programs to demonstrate how to control each of the parts of the robot.

If you have any questions or comments please write then below and I'll do my best to address them.

See you next time!

Miguel

113 comments

  • #51 Kevin Suriel said 2014-06-03T02:17:04Z

    Hello, I have been looking at your guide and I was wondering because I already order the parts, therefore I will now be just coding the material but wanted to know should I put all the code all in one arduino code and have you already got this up and running

  • #52 Richard said 2014-06-24T23:47:55Z

    Hey , Miguel. i have a question: do i must use "arduino motor shield r3" ? or can i just work with "SainSmart L293D" or smth. ?

  • #53 Miguel Grinberg said 2014-06-25T02:34:39Z

    @Richard: you can use any motor shield you like, but you may need a different driver. In the current version of the code I have drivers for the Adafruit and Arduino R3 motor shields. If you end up writing a driver for another motor shield please send me the code and I'll add it.

  • #54 daryl jay peguis said 2014-06-26T06:49:26Z

    i want to try making this one!!!

  • #55 Tristan said 2014-07-02T16:48:43Z

    Hello Miguel,

    Thank you for the excellent tutorial - it works like a charme but I'm wondering about a couple of things:

    Could it be that your whole robot is assembled/programmed to go backward - I always thought the rolling ball must be at the back while the big tyres are in front - doesn't really matter I know ...

    When I add another ultrasonic sensor for "cliff-falling" detection you mentioned I just have to inverse the reading - can you be more precise? Would I add the functionality to the "obstacleAhead"-method? How?

    Thank you!

  • #56 Miguel Grinberg said 2014-07-02T18:49:37Z

    @Tristan: 1. I believe you can assemble this robot both ways, I don't think the direction matters much. 2. the cliff-falling detection works in the inverse way to obstacle detection. With obstacles, the robot moves when the distance sensor returns a large reading (i.e. obstacles are far away). To detect falling off a table you work in reverse, the robot moves while the sensor returns a short distance (i.e. the table), and stops when it receives a large reading (i.e. the floor down below).

  • #57 joe nigro said 2014-07-04T19:45:52Z

    Im having trouble I can make individual codes operate but not the whole code help would be soooo appreciated I want to learn form the beginning but at this point in the build I would like to make my robot work exactly like the build and Im using the exact same parts and versions any help ??????

  • #58 Miguel Grinberg said 2014-07-04T22:12:26Z

    @joe: can't really help much without more details. How is it not working?

  • #59 jade from philippines said 2014-07-08T14:27:07Z

    Master Miguel, just want to know if the C++ codes is easy to convert into C language?

  • #60 Miguel Grinberg said 2014-07-10T03:53:04Z

    @jade: sure, someone who knows C++ and C should be able to port it.

  • #61 Swapnil said 2014-08-04T13:48:27Z

    Thanks for the great tutorial I have a Bluetooth module and I used you program to transmit data but like in your led test program when you sent a letter 'a' it switched on and remained on till you sent another signal to turn it off. My question is can we use this as a push button . like if I am sending 'a' the it should just switch on when it receives and then turn off again. Please help

  • #62 Miguel Grinberg said 2014-08-05T06:23:56Z

    @Swapnil: you need to send press and release events to your device. the press event turns the LED on, the release event turns it off.

  • #63 Swapnil said 2014-08-05T10:25:34Z

    Can you please give the code for press and release events

    Also I have uploaded my robo's code on drive Few bugs 1) when I press i to change speed it goes directly from 120 to 255 and if I press l it goes from 255 to 120 2) I have two distance sensor but the distance sensor does not work

    Here is the link

    https://docs.google.com/file/d/0B-aj530CY_y_WmJtTkJxSS1vTVA2OHN6aHJhYjFHM21sUks0/edit?pli=1

    Please help

  • #64 Swapnil said 2014-08-05T18:17:24Z

    Sorry The bug I mentioned is that when I press 'i' to increase the speed it goes directly from 120 to 255 instead of 120 + 3 And when I press 'l' to decrease the speed it goes directly to 0 instead of 120 - 3

    Please help for both the bugs

  • #65 Swapnil said 2014-08-06T17:32:40Z

    I have improved the code a bit Now the sensor on right works but left doesn't Here is the link

    https://docs.google.com/file/d/0B-aj530CY_y_NU42UXN4b21wclE/edit?usp=docslist_api

  • #66 Jimmy said 2014-08-07T18:35:27Z

    You have documented very well, I am a newbie myself on this open source hardware and find your post very educational. Thank You for doing this!

  • #67 Ricardo Magagnin said 2014-10-04T23:24:27Z

    Hello, Miguel, first of all, congratulation for your post, I really appreciate it. I am from Brazil and started to work in one project very similar. The final objective is while I'm at work, the robot cleans my house. The project uses 3D printed parts, continuous track like a tank and Step motor. I am sure that I need help to programming the final software, your post is very helpful but some upgrades need to be done. If necessary, would you like to join the project? or are you interested to sell your job? Thank you

  • #68 Miguel Grinberg said 2014-10-06T00:54:42Z

    @Ricardo: Unfortunately I do not have time, I'm doing too many things already. Good luck with your project, and thanks!

  • #69 Akshaykumar.M said 2014-10-18T16:32:25Z

    how to select ardinuo for particular robot?

  • #70 emma said 2015-02-09T11:59:12Z

    Plsease how do i assemble components such as sensor, temperature and humidity sensor and touch screen on a robot chasis.using andiuno uno kit. Do i need to use a breadboard as well. thank you.

  • #71 Miguel Grinberg said 2015-02-09T16:44:52Z

    @emma: it really depends on the specific components that you choose. You need to look at the documentation for each component to learn how to attach it to the Arduino.

  • #72 Keith said 2015-04-28T19:51:49Z

    Hello Master Miguel I'm currently starting the project this week as in googling the stuff .I jus wanted to ask how I can get access to the components because where I live the hardwares don't have them so I can get them from over seas in countries like China will that be OK as in financially cause I am still a student and won't be able to get the $110

  • #73 Miguel Grinberg said 2015-04-28T21:52:36Z

    @Keith: I had fairly good results with stuff I bought from stores in China, so yes, if you are on a budget and can wait 2-3 weeks or more to receive your orders then go for it.

  • #74 George said 2015-07-06T18:05:38Z

    Hi Miguel from Austin TX. My 10 yr old son and I received our Arduino starter kit last Christmas It has numerous projects that we have completed, blinking lights, playing sounds, and running servos and motors, and inputs such as heat and light sensors. I am not a code writer but learned basic language many years ago so get it somewhat and have no problems changing values with desired results. Goal is a car. We also fly RC planes but a smart car is what we want and not necessarily a remote control, though we may ad a 2.4 Ghz or blue tooth control. What I have is a 4 motor 4 fixed wheel chassy, motors and wheels are yellow and chassy is clear acrylic with an upper and lower piece, you may have seen it. We have Arduino uno, a motor driver that looks like it sits on top of arduino and will run either 6 or 8 motors. I also have about 6 distance sensors, then the bread board, wires, etc. I picked all of this up last Christmas not knowing a thing. I want the car to since it surroundings, at least front and back, but to the side also since I have the sensors. Do you have code and maybe some wiring diagram to accomplish this? I want to get a simple robot working and hope my son's interests continue and that he gets into the makers movement as he grows. Any help is appreciated. George

  • #75 Miguel Grinberg said 2015-07-07T01:55:32Z

    George: the code I have is what I present in this series of articles. You can adapt it to match the hardware that you have, it shouldn't be a lot of effort if you have a bit of coding experience.

Leave a Comment