Step 7: Final Code

Step 8: Now its your turn!

Make your own variants of this robot and post pictures of them below in the comments. I posted pictures of an earlier version of this robot. I'll post...

Many times I have Googled for "Arduino Robot" in hopes of finding a robot to build. I end up finding many versions of a obstacle avoiding robot that uses either an infrared or a sonar range finder sensor mounted on a servo to detect objects in its way while randomly roaming the area around it. The problem with this robot is it is expensive and very advanced in some aspects for a "first robot" to make with an Arduino board. The cost of a servo is about $10, and a range finder sensor runs from about $10 - $30.

This instructable will cover how to make a light seeking robot (Photovore), and some robotics and motor control basics. This robot can be built with parts found at the nearest Radio Shack, if you already have an Arduino board and a robotic base. The cost for a five pack of CdS cells (Light dependent resistors) cost $2.99 at Radio Shack. and a 15 pack of NPN transistors (very useful later on) are also $2.99. Of all these parts, we will only need two NPN transistors and two CdS cells.

Please remember, this is my first instructable. I really appreciate criticism, comments, questions, and suggestions. Your feedback will help me improve this instructable and future instructables created by me.

Hey great tutorial and im currently building the same thing...i have a problem though...i'm using the tamiya gearbox and instead of npn transistor, im using TIP120. however, after doing all the connection the motor just move a bit and stops. i guess it needs more torque to move forward. could you please help me out or suggest i do something?

I absolutely adore the Tamiya base. I remember seeing it at Fry's one day and buying it with the express intent to build a robot :)

Never did finish the sensor package I wanted for mine so it just took a range reading on objects in front of it. Then took the last bid from that reading to decide on turning right or left. Always meant to go back and finish it but alas my cat had other plans ...... like puking on it ~.~

And I have a problem i cant get the same readings from both sensors they are very different i tried using 2 5k pots the change the values but they dont work well at all. I was thinking about constraining the values and mapping them to 0 - 255 but i cant figure out a code for that. I am using the LDRs for a Line Follower.

The transistors are being used to drive the motors. The Arduino cant source enough power on its own, the transistors are acting essentially like a light switch that the Arduino can flip on and off that connects directly to the power supply.

I'm rusty but the resistors are either acting for biasing or to limit the current, maybe both.

A lot of times you will see both a capacitor and a diode hooked up to a DC motor, the caps help with the initial power draw that the motor can place on your supply.

The diodes are there to prevent reverse power flow from the motors. Motors are act a lot like inductors. primarily because both are essentially wire windings. When you power an inductor it induces a magnetic field. When you stop the power flow to the inductor that field collapses and you are going to get a negative voltage spike.

As for the sensors the question is how different are the readings and are you taking readings under the same conditions? Just to decide if they are working properly you should probably take a multimeter and get a resistance reading. First by covering the sensor then by saturating it with as much light as you can. As long as those readings are similar and within spec for the part then you are fine.

The rest of the time the readings should be different. That is how the robot decides which direction to go.

i am making a robot using your instructable, but i am using a base just like in this instructable, http://www.instructables.com/id/RC-Car-to-Robot/. it is an rc car and is using the arduino motor shield which has an H-bridge. over serial it appears to work fine, but when driving it's steering wheels keep turning back and forth rapidly and randomly, sometimes stopping a bit in the left turn position. i don't really know the problem, the left and right turning codes have worled otherwise in non-sensor tests. i really want this to work, it is my first arduino robot, so i am kinda a noob. i chose the rc car as a chassis because it was easier to obtain than the tamiya, although i might get that when i have more money. also i was using the makershield, and now a full sized breadboard to maximize the space between the two sensors but has not helped,

anybody know the problem or how to fix it,

my rc car was also modified to be switched from rc or arduino control, so it still has a rc board within its body, but the motors are connected to both the arduino and rc board. the power is from the on-board battery holder with 4 AA batteries. the power connections are to the Vin and ground screw holes on the arduino motor shield.

hi guys, I want to build a robot like this but instead of any sensors, I want to pre-program a route into an Arduino, so when i turn it on, the robot follows the route I program in Arduino. Can somebody please help me with the program. I dont know where to start. I do know c++. thanks in advance.

A question.... Can an adafruit motor shield be used for this one. Is the circuit design for it the same. The Adafruit Motor Shield is an H Bridge shield used for controlling dc motors, servos and steppers.

I don't have any experience with the adafruit shield, but you should connect the motor leads to the shield, and then you will be able to control the two motors using the specific pins. look for more info on adafruit's website.

Nice robot, im thinking of making something similar. I have a question though, in the second vodio you plug something into some pins on the robot and it runs wirelessly, what is it and what are the pins?

I just noticed my first reply didn't come through.. So! The module I plugged in was a Bluetooth module. It acts just like a serial connection like the one in a USB plug. I suggest getting used to Serial connection and building up your robot to be controlled through the USB cable. Then, when you are ready, you can use a Bluetooth module. The RX of a Bluetooth Module connects to the TX pin (pin 1 on Arduino), The TX pin of the Bluetooth module goes to the RX pin (pin 0 on Arduino) . Make sure that the Bluetooth module operates at TTL levels, which is 5 volts.

Thanks!! I have been having problems connecting, the negative terminals and the ground, it just wont work, could you repeat in a different way how to connet the emmiter and the collector? Everything else works fine.

Hey, great I'ble, I was able to follow your instructions easily, but am having one small issue and thought you might be able to help. Only one of my motors, the left one, actually runs. However, both light sensors respond in a logical way; when the right one is covered or the left is exposed to bright light, the motor stops, so both work. I know the right motor works too, because when I switch the outputs, the other motor runs (so that shows the output circuitry works on both sides as well). Perhaps it's something with the inputs? But both light sensors work properly, so I'm not sure it's that either... Anyway, I think you did a great job on this and if you have any ideas I'd really appreciate them!

If I understand you correctly, both transistors are working, but you aren't able to use them with a certain pin. You may want to try using a different pin for your motor, incase one pin is defective. You will have to change the code a little bit though. Give it a try..

Hi! First of all, congrats! That's an amazing project. Very instructive... I was thinking if we could somehow put a temperature sensor. So it would be an robot which searchs for fire and warns people about the high temperature (in case it's true).

Is there any possibility you can put a circuit diagram? Or one of those reeeeeeally nice squemes like: http://images.bit-tech.net/content_images/2010/09/arduino-projects-getting-started/arduino-morse-flasher-board-layout-large.jpg ?

Wow. I never thought to use light sensors for an OAWAR. This is the best simple robot I have seen on instructables. I thought w/ video meant it had a camera on it (which it doesn't but would be cool). I will have to make this bot at some point and I might add a camera and a transmitter!

Nice one. I understand that you used Tamiya tracked vehicle set as the robot base. Can i know which dual motor set do you use in this project to replace the original motor that comes with Tamiya tracked vehicle set? Thanks...

I have tried your transistor motor circuit as well as two transistor H-bridge designs, and I can't get any of them to put out enough current to power the motors with sufficient torque. They all put out the correct voltages, but either the motors don't move, or they take a lot of time to get up to speed. Do you have any ideas why I'm having this problem?

Are you using a a gearbox, or running the motor shaft directly on the wheels? A gearbox is very, very important for torque. hmm.. what transistors are you using? Also, try using an ac to dc adapter of the wall for more current. Just replace the + and - of the battery with the ac adapter leads.

I've tried both gearboxes and plain motors. In both cases, the motors either spin up slowly or don't spin at all, even with no load on them. I'm using PN2222A transistors, and I'm using an ATX psu for power, which can supply 32A @ 5V.

I'm nearly done with it- I just have programming and testing left to do. It has taken a while, because it is fairly mechanically complex. I'll be sure to post a picture and a link to an instructable once I've finished.

And once again, thanks for directing me to the L298- I ended up using all three I got in the sample for the 5 DC motors on my robot.

If I understand correctly, PID is basically controlling an output's speed based on how far away it is from its goal. For this robot, I would start at using PWM for speed control, and use the SensorDifference integer to determine how fast the robot needs to turn towards light.

Sorry for the late reply. In this case, I would use fuzzy logic, instead of PID. Switch the two motor pins to PWM pins. I use 5 and 6 for my robot. You'll need to find the PWM value that make the robot move at the slowest speed possible without stalling. Then with a little math:

hello sir !!!it's a great instructable for beginners like me !!1am nt using tamiya dual gear box instead i use two dc motors and the wheels are coupled directly to the shaft .i hve one doubt whether the above code suites me.....?!?!?!?

Does your robot move effectively? I'm not sure if you will be able to get enough torque straight off of the motors. Anyway, If you are using transistors, the code will rok, but if you are using an hbridge, you will have to modify the code a little bit.

hi sir!!i made the light seeker with h-bridge and modified your code a little bit :)am very excited to see the robot turn towards the light:)i made the base of the robot with plastic:)thank u so much for the great instructable :)regardsshadovz

Depends on what parts you already have. The arduino costs about $30. a robot base can vary greatly on the price. The transistors will be about $3 and same with the LDRs if you get them from radioshack.

I don't have any experience with playing music on Arduino but i think you should research the Wav shield.

Your code looks very well laid out from what i see. I am mainly a hardware guy , but I crave to learn better coding. When I read through code like you write,I find it easy to follow and thus easy to learn from. I am happy with "It works" never mind "It's efficient!" , bit of a joke there ! Thanks again for your contribution , Build_it_Bob

Thanks - I have learned a few things... especially that I can in fact control motors without a servo driver but by using NPN transistors. Also this led me to look into an H-Bridge, and I see that can be built as well.. probably with 2 transistors and 2 electronic switches (2 more transistors?)

Anyway, I was just wondering why you have the diodes sitting in parrallel with each motor?

(I am a total electronics noob and am learning through others examples...)

You will need 4 transistors for one h bridge. Think of it as one NPN transistor for every state of the motor pins. The only possible outputs are HIGH and LOW and two motor pins. Meaning you need to have 4 transistors. Although, I recommend buying a motor driver as it has a little more circuitry so that you can add speed control, less pins to operate, and you have a third possible state to your motors, not connected (High Impedance). This is a little complicated and it took a little while for me to understand so don't worry if your confused.

The diodes are to protect the transistors. Certain properties of inductors (electromagnets inside the motor) cause electricity to be generated and therefor flow back into your transistors. The diodes provide a route with less resistance so that the electricity can flow back to the batteries.

You can make this a lot more simple by using continuous rotation servos like in http://www.instructables.com/id/Build-Bluetooth-Robot-Fast-and-cheap/ and using a code like this one http://letsmakerobots.com/node/2164

This was supposed to be a first time robot build. The first link does provide a good tutorial on how to build a robotic base but it uses servos and i wanted to keep this simple. I'm not a fan of the second link as it uses a steering used by cars on the road today, however, most robotic bases (including the one in the first link) use differential steering.

just try to add your schematics in the right rotation. I needed to tilt my screen to read them ;)

If you want to try range detection, try the IR methode. It is not as expensive as ultrasound. you'll need 2 x IR LED and 2x IR receiver for it but if you look around you can find them all together for about 5 - 10$