Obstacle avoidance Arduino robot – build your own larryBot


So after 5 previous versions that had various flaws, I now have an Arduino robot that actually works and although basic is very cheap – although there a probably a few more flaws so please point them out to me but this is a good start on how to make your own robot.

In order to catch up, please see my previous posts below, describing the problems that the other 5 versions had, how the h-bridge chip works and using the SRF05 ultrasound distance sensor.

larryBot – Arduino robot versions 0.1 to 0.5 lessons learned
Control a DC motor with Arduino and L293D chip

Arduino SRF05 Distance Sensor

Now that you’re up to speed, lets start by fixing the flaws in the previous version, this was the case that my motors were drawing way too much current and the L293D chip from ST Micro couldn’t output enough current for each motor.

So, I replaced the chip with the snappy named ‘SN754410‘ from Texas Instruments. This has EXACTLY the same 16 pin layout as the L293D chip and all of the same features except that it can output 1.2 amps per channel rather than the now tiny 0.6 amps of the L293D. Pin configuration diagram below is the same for the L293D as it is for the SN754410, I recommend the SN754410 Arduino comination.

L293D Pin layout

Great I’ve now got more current to my motors, but their stall current is still at over 2 amps, I could add a heatsink to the chip and pass more current through it, but instead I got some more efficient motors than the Mabuchi FA-130’s that came with the Tamiya gearbox. These motors are made by Solarbotics and are their RM3 series which fit perfectly, can handle 4 times the voltage but use a fraction of the current – typically at 9v they use just over 1 amp. Perfect.

Having corrected this, larryBot v0.6 was go! I still faced a lack of power to the DC motors – either because my batteries were running low or not able to supply the current. But since my new motors could run up to 12 volts (instead of the puny 3v of the originals) I decided to use a 9v battery to power them instead of my 4 AA’s.

Watching larryBot move is great, even on carpet and with the tank tracks 9 times out of ten he can climb small obstacles or has enough traction to shunt them out the way. Anyway enough waffling – here’s how he’s made…

The Arduino Robot Tracked Chassis

You could use anything you want really – construction sets, your own custom fabricated chassis etc… But since I’m cheap I managed to get a pile of foamboard for my chassis. I can waste and reuse as much of this as I want so its no problem if I make a mistake or want to improve it. Also in theory this leads to rapid prototyping, so when I do decide to fabricate a chassis I know exactly where the best places are for holes, mounts etc…

The robot chassis parts and tools:

Small Phillips/ cross-head screwdriver
Craft knife
Assorted nuts and bolts – A good set of M series nuts and bolts
Foamboard 5mm thick – 1 A4 sheet is plenty
Tamiya gearbox 70097 – assembled in mode A
Tamiya track and wheel set 70100
Elastic bands (normally dropped by the postie)

Sizing up the robot base

First of all the size of our chassis design is dictated by a few things. The axle length: our tank tracks need about 5mm clearance so the space on the axle is roughly 65mm wide that I can mount on. Next we have the length of the tracks and how many wheels will be used, I kept my track footprint small so my chassis length didn’t need to be much bigger than the gearbox. Which leads on to gearbox positioning – the Tamiya gearbox I have is roughly 75mm in length and the shape of the tracks will dictate where to position the gearbox as the driving wheels are attached to this. The final consideration of course is mounting all the sensors, battery packs, breadboard and the Arduino board.

In my attempts so far I have a base that is just longer than twice the length of the gearbox (175mm) which gives me space at the front for sensors and space at the back for batteries. I then mount a smaller piece of foamboard on top of this that then houses the gearbox and spaces it far enough above the running wheels for the tracks at the bottom – also giving enough tension in the tracks for them not to slip off (unlike larryBot v0.4). From here I can continue to bolt on additional structures to position the breadboard and so on.

So using this knowledge you should be able to size up and cut the foamboard to the dimensions you need – a craft knife will be more than enough to cut this board. To make the holes needed for your screws and bolts just use a small Phillips/ Cross-head screwdriver to bodge a hole through – it won’t take any effort, then you can drive the screws through this guiding hole. If you have washers then use them but the foamboard seems to be able to support all the hardware fine.

Attaching the running wheels and tank tracks

First mark out the position of where you want your wheels, very important as you don’t want them wonky!


To mount the running wheel axles on to the chassis I used a couple of small hexagonal bolts for each side of the axle and then used the glue gun to fix them to the chassis – the best way to do this is to put the bolts on to the axle, use a small amount of glue to hold the bolts in place and then use a shit load of glue over the bolts to secure them properly.

When adding the wheels to the axles, don’t push them all the way on as these axles are slightly shorter than the Tamiya gearbox which will cause you problems with the tracks.

Mounting the Tamiya gearbox, DC motors, sensors, breadboard, Arduino and batteries

To attach the gearbox I just used the screws supplied with the gearbox and bolted this to my smaller piece foamboard. I then in turn bolted this to the main chassis using 4 long bolts and a series of spacers and nuts in between the layers to given the correct spacing and adjustment for my drive wheels.

For the SRF05 distance sensor I just used some blu-tack/ modelling plasticine to hold it in place for now.

The breadboard I mounted above the gearbox, which for this I just fixed it on top of 4 long bolts which then in turn attached the gearbox base. The Arduino board currently then sits on the breadboard held on by the multitude of wires running from it and the power supply cable.

And for the batteries, since I scrapped using the 4xAA’s to power the motor I only had to worry about two 9V batteries, 1 of which was my DC power supply for the board. I fixed them to the chassis just using an elastic band, since I’d want to get to them easily enough.


Simple Arduino Robot Circuit

The parts list doesn’t differ much from my other tutorials for motors and L293D. But I did find it was troublesome to get the parts from the same supplier, so be aware that you may need to look at multiple suppliers and postage may get expensive.

Robotic parts list

2 x Solarbotics RM3 motors
SN754410 motor driver chip
SRF05 Ultrasonic distance sensor
Arduino Deumilanove w/ ATMEGA328
Breadboard / Prototyping board
Jumper/ Connector wires
2x 220nF multilayer ceramic capacitor (Y5V)
2 x 50V 10uF Capacitor (although I’ve not used them here)
2.1 mm coaxial DC jack
2 x PP3 9Volt battery
PP3 9Volt Connector
9Volt battery holder


You can see that the circuit is pretty simple, nothing actually that fancy, I have the SRF05 using the +5v, GND and digital pins 12 and 13. The SN754410 then uses the digital pins 9 and 10 to control each channel – these can use PWM to do speed control, then there are the switch pins on the h-bridge that go to digital pins 3,4,5 and 6. The spare GND is used to join the GND connection between the motor power and Arduino power supply. Here are the instructions for the 9v battery DC supply. If you want to use the extra 50v 10 uF capacitors then these sit on the power supply for pins 8 and 16 on the SN751140 respectively.


Arduino Robot Code

Nothing much has changed from the larryBot v0.1-0.5 sketch except that I’ve altered the detection distances as I have a much faster response time from the robot.

const int numOfReadings = 10;                   // number of readings to take/ items in the array
int readings[numOfReadings];                    // stores the distance readings in an array
int arrayIndex = 0;                             // arrayIndex of the current item in the array
int total = 0;                                  // stores the cumlative total
int averageDistance = 0;                        // stores the average value

// setup pins and variables for SRF05 sonar device

int echoPin = 12;                               // SRF05 echo pin (digital 2)
int initPin = 13;                               // SRF05 trigger pin (digital 3)
unsigned long pulseTime = 0;                    // stores the pulse in Micro Seconds
unsigned long distance = 0;                     // variable for storing the distance (cm)

int motor1Pin1 = 3;                             // pin 2 on L293D
int motor1Pin2 = 4;                             // pin 7 on L293D
int enable1Pin = 9;                             // pin 1 on L293D
int motor2Pin1 = 5;                             // pin 10 on L293D
int motor2Pin2 = 6;                             // pin  15 on L293D
int enable2Pin = 10;                            // pin 9 on L293D

void setup() {
  // set the motor pins as outputs:
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
  pinMode(enable1Pin, OUTPUT);
  pinMode(motor2Pin1, OUTPUT);
  pinMode(motor2Pin2, OUTPUT);
  pinMode(enable2Pin, OUTPUT);
  // set enablePins high so that motor can turn on:
  digitalWrite(enable1Pin, HIGH);
  digitalWrite(enable2Pin, HIGH);

  pinMode(initPin, OUTPUT);                     // set init pin 3 as output
  pinMode(echoPin, INPUT);                      // set echo pin 2 as input

  // create array loop to iterate over every item in the array

  for (int thisReading = 0; thisReading < numOfReadings; thisReading++) {
    readings[thisReading] = 0;

void loop() {
  digitalWrite(initPin, HIGH);                  // send 10 microsecond pulse
  delayMicroseconds(10);                                // wait 10 microseconds before turning off
  digitalWrite(initPin, LOW);                   // stop sending the pulse
  pulseTime = pulseIn(echoPin, HIGH);           // Look for a return pulse, it should be high as the pulse goes low-high-low
  distance = pulseTime/58;                      // Distance = pulse time / 58 to convert to cm.
  total= total - readings[arrayIndex];          // subtract the last distance
  readings[arrayIndex] = distance;              // add distance reading to array
  total= total + readings[arrayIndex];          // add the reading to the total
  arrayIndex = arrayIndex + 1;                  // go to the next item in the array                                 

  // At the end of the array (10 items) then start again
  if (arrayIndex >= numOfReadings)  {
    arrayIndex = 0;

  averageDistance = total / numOfReadings;      // calculate the average distance

  // check the average distance and move accordingly

  if (averageDistance <= 10){
    // go backwards
    digitalWrite(motor1Pin1, HIGH);
    digitalWrite(motor1Pin2, LOW);
    digitalWrite(motor2Pin1, HIGH);
    digitalWrite(motor2Pin2, LOW);    


  if (averageDistance <= 25 && averageDistance > 10) {
    // turn
    digitalWrite(motor1Pin1, HIGH);
    digitalWrite(motor1Pin2, LOW);
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, HIGH);
  if (averageDistance > 25)   {
    // go forward
    digitalWrite(motor1Pin1, LOW);
    digitalWrite(motor1Pin2, HIGH);
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, HIGH);     


[ad#Google Ad in content]

Some problems you may face – if like my you don’ t have a spare 9V battery connector to hand check this connection if nothing is happening – I used blu-tack to hold my wires in place so it’s a bit temperamental.
Check that your motor wires are properly in contact with the motor terminals if you haven’t soldered them again using some blu-tack or tape is handy for getting a good connection.
Motor’s are under strain – your tracks are too tight.
Tracks come away from the wheels – check your tracks are not too loose and that your running wheels are in line with the drive wheels – the Tamiya gearbox is slightly wider than the Tamiya track and wheel set axles.


I’ve gotten a fairly cheap robot that avoids obstacles, next plan is to extend it to sense various things – for instance detect motion and move towards it, or a light/ heat source. The robot costs are quite high if you factor in the Arduino board and if you don’t have any of the parts – but this can be broken down and used for many other projects so you’ll get a lot of reuse out of these bits, but I reckon that the total cost is around £70-80 in total, so fairly cheap when compared to other bots. Of course if you don’t want tracks (?) then you can just use wheels instead, Tamiya do also make wheels that will fit the gearbox.

Just in case you have trouble getting parts, here’s a small list of people that can supply the various bits – although none of them will have the full set. Shipping from the states is an option, but check the shipping costs as it may negate the cost savings. Please let me know of other sources, the list is in no particular order.

Sparkfun – USA: motor controller and Tamiya parts
Pololu – USA: Tamiya parts and motors
Techbotics – UK: Tamiya parts – just about cheaper than getting parts from Sparkfun/ Pololu in the USA
Active robots – UK: motors, SRF05 but generally overpriced on everything
Rapid Electronics – UK/EU/USA: most component parts and hardware
Farnell – UK/EU/USA: SN754410 chip and most components but shit for orders if your billing and delivery addresses are separate
Mouser – UK/EU/USA: SN754410 chip and most components
SK Pang – UK: SN754410 chip but dodgy VAT calculations (charges tax on shipping as well) few other parts here.

If you need an Arduino board, I reliably found a seller on ebay from Hong Kong that will sell and ship you aboard for far less than paying for it the UK – downside is it takes about a week to arrive.


  • hi
    I Love it i have got stumpt by the breadboard, i cant work it out from the picture could you help. i have never don emuch with a breadboard since i studyed electronics.
    i understand thet you are probably a busy person, so sorry for bothering you.
    thank you

    • Hi Dan,

      What are you stuck on? I always start by breaking things down a bit on the breadboard. It took me a while to figure it out as there were so many other confusing things out there for similar topics and everyone just assumes you know.

      If you let me know what you need to make it easier to understand I’ll update the tutorial/ answer questions.

      • thanks for the quick reply.
        i am stuck with puting together the breadbord. I find it hard to distingush were the wires go. i have never done any thing like this befor on a breadbord, i studyed electronics for gcse but i never did complex things and it has been a wile since then. i don’ know what you can do to help but it would be greatly apriciated.
        i also noticed that on your picture it looks like you have an extra colum on each side althoug i baght it from the link on your site. I know that dosent matter but i thaght i would point it out incase you try to put down cowardenats of each wire.

        thanks again for your time

        • OK, lets start with the breadboard and we can do it in stages. I guess take it so the shortest side of the breadboard is in front of you and we’ll name the columns. I’m assuming that what you have is one with essentially 4 columns?

          Starting with the left side there should be a column of 2 holes wide (column A), then a column of 5 (column B), column of 5 (column C) and on the far right a final column of 2 (column D). The breadboard is divided into rails, so think of these as a wire strip running inside the breadboard linking the holes together. In columns A and D the rails run the length (longest side of the board). Yet in columns C and D they run across the width – this is important to note. So unless there is something linking these rails together power is never flowing through them and if it is it runs along the rail until you join them together.

          The outside columns A and D (that are 2 holes wide) are going to be purely for our power supplies, so power is either going in to these columns/ rails to the circuit or it is returning via the GND/ Negative. And the power will be running up and down these rails. Lets make sure to designate which is positive and which is negative/ GND.
          the left of column A will be + and the right of column A will be -. The same goes for column D, but really we only need column A for our power needs.

          Starting with the H-bridge chip, you need to plug this in so that it straddles the very middle of the board, so that 8 pins are in column B and the other 8 are in column C, think of each column as a separate entity, unless you connect them thery are completely separate. If you look at the chip there should be an indentation at one end, this indicates were pin 1 is of the chip. So lets place the chip at the very top of our board with the indentation towards the top – also fits my picture better that way in the original post.

          The chip straddles the 2 columns so that we can have 2 completely separate power sources/ motors unaffected by each other. If you don’t do this you won’t be able to control the chip effectively.

          Ok, so we should have a chip inserted at the top of the board? It should have 16 pins, 8 in each side.

          At the top left of the chip this is pin 1 based on this assumption we can explain each output of the chip.

          1 to pin 9 on Arduino board
          2 to pin 3 on Arduino board
          3 to motor1 (either + or -) it wont matter as its DC
          4 to the gnd rail on the breadboard
          5 to the gnd rail on the breadboard
          6 to motor1
          7 to pin 4 Arduino
          8 to power (+) rail.
          9 to pin 10 Arduino
          10 to pin 5 Arduino
          11 to motor2
          12 to GND rail
          13 to GND rail
          14 to motor2
          15 to pin 6 Arduino
          16 to power (+) rail.

          The capacitors have only 2 wires each, and they sit in pins 3 and 6 BEFORE the wires for the motor and likewise for the other capacitor on pins 11 and 14 for motor2.

          If you’ve got that working then we move to the other stuff. Essentially there is a 9v battery that connects to our power rails, everything else (the SRF05) I run off the Arduino board.

          Hope that helps explain it a bit more – bit of a late night reply but if you’re still stuck then I’ll do step by step diagrams tomorrow.

          Incidently I’m setting up a way to get all these parts together without having to pay multiple postage to numerous places if there’s anything that you need.

          • thank you again for the quick responce.
            I think this is what i need, ill give it a go when my new jump wires come as i have ordered some more as i dident count how many was needed.
            thanks dan

          • yeh you’ll need a few jump wires… let me know how you get on.

          • hi
            will i be able to test the circit befor i programed the Arduino?

          • hi again i can’t work out what ive done rong. i have followed the steps to how i enterprited it but it does no work. i am realy confused. Do you have any ideas on what i could have done rong?

          • hmm. just talking about setting up the motor control chip right?

            I’ll do step by step photos when I get in tonight/ over the weekend and do a diagram :)

          • hi sorry i diddn’t say what i was having problems with. I have put all the jump wires together and the chips and i also programed the adrino board, bu tit wont work

          • ah ok, I’ll do the steps in more detail – make it a bit easier to follow :)

          • also… where are the “2 x 50V 10uF Capacitor” meant to be posisioned?

            p.s. sorry for all the hasle

          • ok
            thanks a lot
            you have been brilliant.
            ive managed to convince my mate to have a go. 8D
            ill send some pics and vids when ive got it working well.

          • hi again i have spent ages trying to get it to work…
            i find that it runs for a few seconds then just dies
            i have been trying to get it to work i quite a few waya but have not managed to…
            when the circit on its own with the moters worked but when it is all atached it dosent im wondering if i have the rong capaceters but they seam to be right

          • Ah no this sounds like it will be down to the size of the motors and their stall current – I had the same issues. What motors are you using? and what motor controller chip are you using?

            If you’re using the RM3 motors and SN754410 then are you using a 9volt battery to drive your motors? and are you using a 9V for the Arduino (2x batteries).

            If thats all correct and its still stalling then check the layout of the chip and if its wired correct and send me a picture or mail it me at larry@ this website

          • hi
            i have the 2 9v batterys, and i baught everything else from the list

          • sounds like chip configuration – if you’ve got any pictures? Is the chip wired up like mine? Are you using tank tracks – Are they too tight? Sounds like something is stopping the motor when its under load or somethings not wired right from the motor control chip. I’m down near london if you’re still stuck – don’t mind meeting up to fix it.

  • also i cant work out were the negitive from the 9v battery gose


    • jab it into the ground rail on the breadboard :) – same as the gnd connections from the L293D/SN75441 motor controller chip.

      • thanks,
        i just realised that gnd stud for grond. i was going to past saying i workied it out. HaHa.

        • heh – took me a while to get used it to – Ground, GND, -, negative they all probably mean totally different things but in this case they all mean the black wire from the 9v! :)

  • Thanks for the help, me n Dan just rewired the whole thing and reuploaded the Arduino code. Dan then realised that he had not conected the two grounds together… Nice blog, I need to look around here 😛

    • Seriously you wouldn’t believe how much I struggled! Took me ages to realise that I was bridging connections between the chip at first (much more of a fundamental error than Dans).

      I’ve just been playing more with the ultrasound sensor and realised that I’ve been doing some dodgy code :/

  • it may be a few days yet as i brock my glue gun so i haven’t been able to finish my chassie. i am geting a new one so ill send you the finished pics and vid’s then.

  • HEY CAN YOU PLEASE HELP ME to build a robot that works on image processing and avoid obstacles(STATIC VEHICLES).

    • You’ll need a web cam and some way of processing images e.g. laptop using the Processing langauge maybe to look at pixel difference between images to detect objects.

    • yes u need to buy a ardurino bulider set :DDD

  • CAN YOU PLEASE HELP ME TO Build an automated robot that can traverse a complex arena consisting of Bi-lane roads with obstacles (static vehicles).

    • Has the robot got to find anything e.g. get to a certain point in the arena, or is it just purely obstacle avoidance?.

      Obstacle avoidance isn’t too bad and depending up on the lane you can get a sensor to check and keep with in the lines.

  • Hi,

    I’m building similar obstacle avoiding bot but with a bit different components. I have a problem with the srf05 (well I think its a problem with it) sensor. Sometimes, actually quite often, it goes into a strange mode where it works very slowly and the readings don’t make any sense. It makes only one reading in like 5 seconds or something (usually it should make more like 20 readings a second). Sometimes it seems to help to take the GND wire off and back again, so maybe its a problem with the wires. I wonder if you have had similar problems?

    When the sensor works, the bot is doing fine but that’s only like 10 seconds at a time. I have used my own code but I have also run it with your code and the problem remains the same.

    • Hmmm… not sure, check the wires but more importantly check your connections – are they soldered to the SRF-05? ensure a good connection.

      Also check your power consumption, does a basic circuit work and do you only have issues when its part of your bot?

      • sorry for the double post. Yes they are soldered so it should be ok. The power consumption might be a problem. I have run it when it is connected with USB and there is still the problem. I remember running it earlier when it was not part of my bot and it seemed to work ok, but I have to check that again.

        • The other thing is to use a Multimeter to check the continuity to make sure you’re constantly getting power, that there are no faulty wires. Also double check your circuit – make sure there’s nothing causing issues there and try just the SRF05 on its own circuit. It sounds very much like your bot is draining power away from the SRF05. I kept my motor supply completely separate from the sensors to avoid this. Run the bot but use the Multimeter to see the power being supplied to the SRF05 and watch for spikes and dips.

          • hi and thanks for the tips. I soldered the srf05 again and it seems to work ok now. Though it seems that sometimes the echo doesn’t return very well if the obstacle is not perpendicular to the sensor. Maybe the echo does not bounces straight back to the sensor in those cases.


            I took this video, its not the last version but its there if you want to chec out

          • Cool video. Looks exactly like mine! :)

            I did more work with the sensor. It has a conical detection range so will only see whats directly in front of it. also any small item it will see as a big obsticle so it’s not too hot at navigating a course. More sensors I think are needed.

  • Hi,

    I am building a similar obstacle avoiding bot but I have a problem with the srf05 sensor. Sometimes it seems to go into very slow mode where it only gives one reading in like 5 seconds (usually it should give more like 20 readings per second). sometimes it seems to help to unplug the GND wire and put it back so it might be a problem with the wires. Have you encountered any problems like this? I have run it with my own code and with your code and the problem remains the same

  • Hi Larry,
    I recently found this homepage and find it very helpful.
    I’m trying to build a fire seeking robot with the arduino platform.
    To build it I would be happy to use your circuit for the motors and the motor controls.
    I would use this sensor to find a candle: http://letsmakerobots.com/node/3888
    Which would be connected over I2C Bus to the arduino. Do you think this project would be possible?
    I hope you’ll see my massage and excuse me for my bad English.
    with kind regards

    • I was thinking about getting one of these same arrays myself :)

      I think you would need to add in servos to move the sensor around to ‘scan’ the environment so it could accurately detect the flame. You may also might want to use thermometers so the robot can find a heat source perhaps.

      For the thermal imaging sensor you would need to configure it to move the robot based on the angle of detection – maybe convert to a compass or something

  • Hi, thank you for your tutorial. I just have a few questions if you don’t mind:
    In your reply to Dan, you said that pin 1 and 9 of the motor controller chip are both connected to the arduino’s pin 9 and that pin 7 and 15 are both connected to pin 5 of Arduino. Does that mean that they share a same pin on the arduino? How is that acomplished? Also the pin correspondance on your scheme and in your reply are not the same. Is that normal?
    Lastly, I couldn’t find multilayer ceramic capacitors, but found another type of capacitor of the same value instead. Will that work?
    Thanks by advance for your answer.
    Greetings from France.

    • Hi Anthony,

      Think I made a misake there, I’ve just updated the comment to have correct pin numberings. Suprised you’re the first one to figure that out :) Pins below also…

      1 to pin 9 on Arduino board
      2 to pin 3 on Arduino board
      3 to motor1 (either + or -) it wont matter as its DC
      4 to the gnd rail on the breadboard
      5 to the gnd rail on the breadboard
      6 to motor1
      7 to pin 4 Arduino
      8 to power (+) rail.
      9 to pin 10 Arduino
      10 to pin 5 Arduino
      11 to motor2
      12 to GND rail
      13 to GND rail
      14 to motor2
      15 to pin 6 Arduino
      16 to power (+) rail

      As for capacitor it’ll only really matter about the value of capacitance rather than the type – I’ve used different types with no problem and also they’re not really needed as most times it works fine without them.

  • Hi thanks for the quick reply and sorry for my late reply. I didn’t have access to a computer since then. I built the robot and uploaded the code but it seems that there is a lack of power from the motors. I’m using 9v motors wich have a stall current of 150mA. I’m using the same controller chip and a nine volt battery. whenever I boot the arduino, Either will the robot just won’t run or run for 50cm and then stop slowly. By the way I’m not using the gearbox even though I bought it because the motor wouldn’t fit perfectly in it(too small), so the power should be even less reduced. I’m wondering if it is because of the battery not being able to supply enough current. I heard of specific 9v battery especialy made for electronic(high current drain) application. Do you think those may solve the problem?

    Thanks by advance. Anthony.

    • Hey Anthony, if you touch the motor control chip does it feel like it’s overheating? 150mA at stall shouldn’t be causing an issue – far from it but if the chip is over heating then the motors are causing too much of a drain.

      Next try running the circuit without any load e.g tracks and monitor the motor control chip see what happens there. Could also be that the gearbox is straining under the motors and seizing.

  • I tr8ed that but I don’t have any overheating problem. And I am not using any gearbox. By the way I am currently using a 160mAh Ni-Mh battery.

  • Thanks for posting all of this, it’s been invaluable! I’ve been building a robot out of an old r/c tank using an adaptation of this code to allow me to control it using a bluesmirf bluetooth modem. :)
    I’d never have got it moving at all without your stuff as a guide!

  • Hey man, just wanted to say thanks for the chip information & code.
    Gave me a few clear answers I was looking for.

    • Glad it helped.

  • Hi, Ive been working on this project for a while stuck trying to find why mine isnt working when i realized that im using a PING ultrasonic sensor, with the echo and trigger attached to the signal connection, instead of a srf05 ultrasonic sensor. any suggestions on how i can simply alter the code (i am horrible in code writing) or is it worth the $30 plus shipping to buy the srf05. thanks for your time

    • Just do a test sketch for your PING and then rewrite that into my code to provide the input value. I’ll have to see about getting a ping sensor and see if there’s any major differences.

  • hey larry thanks 4 ur big effort but i want u to help me in my project and i want to know how can i connect arduino to rc car it will be nice if u share a video that explaining how to wire rc car with arduino



    • Depends on what you want the Arduino to control, if it’s just the motors, it’s going to act like a speed controller. If you add sensors that then control the motors that would be pretty cool. You’re going to need an extra power supply for the Arduino or wire it into the RC cars loom using a voltage regulators. Also you could use a transistor (TIP120 etc…) to let the low power Arduino control the speed controllers and servos without needing to rewire them.

      I have an old Tamiya Madcap that I guess I could try to do this with if I get chance.

  • On behalf of all the people who used your website,

    I just wanted to thank you for your great help and support
    it encourages us more to learn and try new stuff and probably one day we will be able to help other people as you did

    Thanks again :)

  • Hi Larry, thanks for your time and effort to document how you made your bot. It works really well. Since the ultrasonic detector does not detect soft objects all that well I purchased a couple of ir sensors to attach to the bot. I just don’t know how to program them to work along with the program you wrote for the srf05 sensor. I assume I can just add additional code and it should all work together. I also am unsure if I can even connect all three sensors. I don’t know what I would do with out your post!

    • Hey Kris,

      So which IR sensors are you using? is it something like the Sharp IR ones?

      Basically you’ll need to write a chunk of code that looks at all 3 values and determines an action based upon:

      If the left sensor detects a shorter distance than the right then turn right. Or we know that there is an end to the object

      If all 3 match then the wall is flat – turn around 180 or something.

  • dan
    come to abouzar vocational school in Iran , Esfahan till i teach you how to work with breadboard

  • Interesting project. I think a good next step would be to add a second pair of sensors and then mount the two sensors at, say 30 degree angles on the front corners and then use a differential calculation to work out which way to turn. As you have it, the bot will always turn in one direction if is ‘sees’ an object, but if you head into a corner, that may result in getting stuck, or having to do a 180, which will send you back in the direction you’ve come rather than turning the other way which would result in the bot making better progress. Not sure how easy it is to interface a second sensor pair though…

  • Hi Larry, I echo amr hamed taher and his request for an arduino conversion of a stock RC car, I have several dirt track buggies around here, like to convert one. JD

  • In your parts listings it says 2x 220nF multilayer ceramic capacitor (Y5V). Did you actually mean a 220uf capacitor?

    I am asking because I have a 16V 220uf capacitor which came with a beginner kit and it is used with a small motor. Also I couldn’t really find any 220nf capacitors on the web. I don’t know much about electronic components yet so I am just following your guide.

  • Many thanks for this project. Getting chassis on Ebay.
    Chose SK Pang for the SN75441. Total Cost £8.88 for 2 chips! Posatage £3.60. VAT: £1.48
    Farnell – minimum order is £20 worth!

  • Hello i try to make the same bot for school project and its done but my 12v DC motor dont have enought power to push the robot.. i dont know what to do can you help me plz?

  • Hi Larry,

    First off; thanks for posting this, I’ve been wanting to build my first robot for some time but needed some guidance.

    I’m currently studying for a BEng in electronics at a university which offers nothing in the way of practical experience. So I’m attempting to get some myself this summer by trying to build this robot and then hopefully elaborating on it.

    I have no experience of Arduino, having only ever used PICAXE in the past, do you know if I could substitute the Arduino Nano 3.0 Atmel ATmega328 Mini-USB Board for the one you used?

    Thanks in advance


  • ..or any of the other Arduino chips available at the moment?

    Many thanks!

  • Privilege, happy and impressed i must say i am about your effort so far in putting these things together. you are doing really great and I join others to commend on your good effort.

    I am a graduating student and about to do a project. I am much interested in building this same project. but I have a few challenges.

    The first is about the DC motor connection.
    First you mentioned connecting the motor such that the driver chip powers it and again you talked about connecting the motor to dc supply directly. Am kind of confused about the connection. please can you explian how I should connect the motor.

    secondly, I browsed the arduino micro controller, and from the discription they gave concerning the digital pins. pin 4 was not included but in your discription, you made mentioned of it. This also get me confuse, even now!

  • hi..im interested with your project..
    can SRF05 sensor replaced with other type of sensor such as SRF02, SRF04?

  • Pretty good for your first bot. A few problems I can help you with.
    A. you need to use a larger battery your motors are pulling about an amp each and a regular 9V only supplies 500 mah so it can only supply 1/2 an amp draw for one hour. you need to get a 6 cell r/c car battery pack.I would say anything over a 2200 mah rating.
    B. Your ping sensor is mounted to close to the floor. it is probably get alot of interference. mount it up higher and it will work more efficient.
    C. Your code needs a little refinement I have basicly the same bot but my code is about a 1/4 of the size.the shorter you can keep your code the smoother your bot will run. It took me a while to learn how to clean up my code but the better I get at it the better my bot runs. Plus the faster you can get your basic code to run the easier it is to become more advanced.

    Keep it up and there are many cool people out there that will be willing to help just for the love of robotics. One site that has helped me allot is http://letsmakerobots.com/ .

  • i would LOVE to do this with a electric R/C car! or even with the stress a gas one that would drive it self!

  • ola man soy un estudiante mecatronico y ps quiero felicitarte por todo ese trabajo ya que una ves no es censillo super encerio

  • hello a question in the Arduino programming error goes I do
    const int numOfReadings = 10; // number of readings to take/ items in the array

  • What is the dimension of the smaller foam board between the motors and the main foam board chassis..

    • umm. can’t remember, I don’t think I was too specific on that, just cut a piece down until it was small enough to fit.

  • thanks for the quick reply.

    just wondering what wheels did you use for the tracks?? I see its a large drive sprocket on top..

    but on the bottom, is it a small drive sprocket on the front and small wheels behind it OR just all small wheels for the bottom??

  • also how many links does the tracks have??

  • why distance = pulstetime/ 58? why not other number. ^^ and cant understand some of the code. I have less experience in programming. ” for (int thisReading = 0; thisReading < numOfReadings; thisReading++) {
    readings[thisReading] = 0;" and the next one.
    total= total – readings[arrayIndex];
    readings[arrayIndex] = distance;
    total= total + readings[arrayIndex];
    why the total will subtract then in the next code will add?? i try to understand your code so that i can create my own.

    • for 58, I measured the time the signal took over a set distance.

      In terms of the averages, it’s probably the wrong way of doing it e.g. taking multiple readings and then an average. What I should have done is remove any values that are outside of a threshold.

  • also in your in OBR 0.5 .maybe i can experience the same problem because the SN754410 is not available. can i amplify 0.6 A to 2 A or more?? and i’m trying to create a larger size of this robot. 2 ft long and 1.5 ft wide. so bigger motors and much current is needed.

    • I would use a different h bridge chip entirely, voltage seems to be ok for most but it’s the current that’s the issue. Too much current will burn the chip out and stall the motors.

  • great! i’m going to use this as my project. thanks a lot

    • You may want to actually improve this or make the project your own rather than just copying it wholesale.

      I really should start to leave more bugs in the code to make you think about it before just copying it all 😉

  • What kind of sensor need to measure the speed of a car. I have LV-max sonar -EZO and Arduino uno?

  • Hello there, first of all, thank you for the information/tutorial! I’ve bought the tamiya twin gear motor and tamiya tracks, 2x sn754410ne.

    I only use one sn754410ne.

    So my setup is
    – new 9v battery
    – T-twin gear with original motors
    – Arduino

    When I power it up, it runs for about 20 seconds and then it slows down. When I power it off and then on it does not even move anymore. When I run the motor, it is in the air, so no pull/push power of the ground.
    Can I use a bigger battery pack? for example 7 times 9V battery or one LIPO RC car pack?

    And are the capacitors necessary? And what about if I use a bigger battery?
    Could you please provide me with a link to the right capacitors? Because I could not find the right one on the internet…

    Thank you in advance!

    • i’m having same problem with. did you manage to solve this?

  • Do you have any sketch available of your robot, of the cabling using for example fritzing?

  • i have 4 motors. 4 wheels. so can a single 6 volts battery can power up the motor? I will use two L293D . the stall current each motor is 470 mA.

  • hye larry,below is my code for coding obstacle avoidance robot. i use 2 type of sensor which is Ping sensor and IR Sharp sensor..my problem is when i running the robot its look like my both of sensor is not functioning. Can you detect my problem..i also use L293D motor driver chip..

    int i;
    int dist1;
    int dist2;
    int pingPin= 7;
    int redpin=0;

    int motor1Pin1=4;
    int motor1Pin2=3;
    int enable1Pin=9;
    int motor2Pin1=5;
    int motor2Pin2=6;
    int enable2Pin=10;
    int duration;

    void setup () {
    pinMode(motor1Pin1, OUTPUT);
    pinMode(motor1Pin2, OUTPUT);
    pinMode(enable1Pin, OUTPUT);
    pinMode(motor2Pin1, OUTPUT);
    pinMode(motor2Pin2, OUTPUT);
    pinMode(enable2Pin, OUTPUT);

    digitalWrite (enable1Pin, HIGH);
    digitalWrite (enable2Pin, HIGH);

    pinMode(redpin, OUTPUT);


    void loop() {
    pinMode(pingPin, OUTPUT);
    digitalWrite (pingPin, LOW);
    digitalWrite (pingPin, HIGH);
    digitalWrite (pingPin, LOW);

    pinMode(pingPin, INPUT);
    duration=pulseIn(pingPin, HIGH);

    i= analogRead(redpin);

    if (dist2 > 10 || dist1 10 || dist1 > 5 ){

    if (dist2 5 ){

    if (dist2 < 10 || dist1 < 5 ){

    void forward() {
    digitalWrite (motor1Pin1, LOW);
    digitalWrite (motor1Pin2, HIGH);
    digitalWrite (motor2Pin1, LOW);
    digitalWrite (motor2Pin2, HIGH);

    void backward(){
    digitalWrite (motor1Pin1, HIGH);
    digitalWrite (motor1Pin2, LOW);
    digitalWrite (motor2Pin1, HIGH);
    digitalWrite (motor2Pin2, LOW);

    void turn(){
    digitalWrite (motor1Pin1, HIGH);
    digitalWrite (motor1Pin2, LOW);
    digitalWrite (motor2Pin1, LOW);
    digitalWrite (motor2Pin2, HIGH);

  • can you post how to connect the SRF05 to Arduino?
    I’m trying to do this robot and take it for my graduation exam,but I faced some problems:
    -using your arduino code,the robot doesn’t stop near the objects,but tries to avoid them, and often collides with them;
    -the SN754410 with the 9 Volt battery goes into overheating(but maybe it’s only because I’m still using the RM2);
    If you don’t mind, I can ask my Teacher to overhaul your arduino code and,if the new code is better, I can post it to you so you can upgrade this wonderful project.
    Thank you from an italian student

  • hey
    i want to know whether i can add co ordinate system to it?
    like i can give starting end ending points and in between it can also avoid obstacles?
    can u help me on that?

  • hi,
    im really new to using microcontrollers. and i dont really have much knowledge in it.
    just asking, is the program for the obstacle avoidance bot similar to the the program of a robot which lifts obstacle and puts it to his back? (the program of detecting the obstacles only)


  • i want to a proper code for obstacle avoidance & finds a destination using ultrasonic 3 pin sensor,servo motor.

  • hi larry, im trying to do this project but with a variation, i want to use this h-bridge (http://www.electronicaestudio.com/docs/ESQ_1437-2.pdf), but i cant find the way to make it work, can you help me? (by the way, i like a lot your webpage its really useful )

Join the Discussion

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>