Introduction: Autonomous Race Car

Picture of Autonomous Race Car

Build this autonomous driving robot car based on a old RC toy car. I removed the radio control board from the car and replaced it with a brain in the form of an Arduino UNO board (plus a motor driver board) and gave it an ultrasonic distance measuring module to see the world through.

Step 1: Components

  • Radio controlled toy car
  • Arduino Uno
  • Motor driver board (2 channel)
  • Ultrasonic sensor distance measuring module
  • Bread board

Step 2: Brain Transplant

Picture of Brain Transplant

Remove the radio control board from the RC car cutting all wires close to the board. Connect wires to the motor driver board - rear wheel motor in one channel - front wheel steering motor in the other channel.

"Steal" power from the cars batteries.

Step 3: Connect Arduino Board and the Ultrasonic Sensor

Picture of Connect Arduino Board and the Ultrasonic Sensor

Connect the ultrasonic sensor and the motor driver to the Arduino board.

Step 4: The Programming

The cars intelligence is pretty simple. It's based on different modes that controles speed & direction depending on distance to objects ahead of the car:

FULL SPEED MODE - No objects ahead - full speed

CRUISE MODE - Object is X cm away - slow down

AVOID MODE - Object is too close for comfort - slow down and turn in random direction

REVERSE MODE - Object is very close - stop and reverse for 2 seconds

Step 5: The Code

Note: you need to find the "Ultrasonic.h" online. As I remember, I had to download a couple of different versions before I found one that worked.


sasdsdferrcfd (author)2017-12-05

plz .how i can do it with L298 driver .what the changing in code?

m0ebius (author)2017-09-15

Watching this work roaming is impressive! but reading through your code I don't see how the Random Seed influences the steering choices. Is this your early code for the project?

ShayanN1 (author)2017-02-09

the front motors are not working and the rear motors are moving front only when an I move my hand in front of the ultrasonic sensor. need help

ilkergureli (author)2016-10-27

Hi :)
First of all, Congratulations..
I wonder how many motors(dc or servo) in car? And lastly, is there any hardware circuit of this project ? Please help me :)
Thanks :)

Dod5 (author)2016-06-06

Can it used for 2WD smart car? do you have sketch code for 2WD which uses L9110s and ultrasonic sensor?

yaseenninja (author)2016-02-09

Hey I actually tried it with the l298 motor module and it's not working because. The l298 has pwm (pulse width modulation) so it has 3 pins for each motor. 2 of them are Standard and one more is pwm pin so please can u suggest. Me the code it's not working pls

ayush mandavgane (author)2015-11-19

can i adjust the sensor distance

YashuY (author)2015-09-18

please make it fast as soon as possible...

jesper birk (author)YashuY2015-09-18

see step 5

YashuY (author)2015-09-18

please, can i get the program code for this one..

arduinoarpan (author)2015-04-10

Hey actually the car i am using has only one motor ie fr rear wheel so will it work on such car

jesper birk (author)arduinoarpan2015-04-13

hmmm - does it have a servo steering the front then? You would need to tweek the program - but it should be possible...

GarrukApex (author)jesper birk2015-08-18

This is an old thread, but if you are reading this-

Instead of one motor turning either fully right or left, with a servo you would have the option of turning in either direction in varying intensities. You would need a single channel motor driver for you rear wheel, and you would be able to connect the servo directly to arduino. Instead of just turning the front steering motor left or right, you would have to specify the angle for the servo to turn to to control steering. However, you would have the option to control the intensity (ie degree) of the turn based on the scenario.

*In case you do not already know, the Servo.h library comes standard with the arduino ide and would be perfect for your purposes.

TejeshB (author)2015-07-01

can we do it with an old motor car not a rc one

ChrisA7 (author)2015-04-20

I cannot get the car to move forward, only reverses. any suggestions on what could be the problem?

jesper birk (author)ChrisA72015-04-21

It could be a problem with the sensor. If it reads out a zero value, the program will go in reverse mode.

ChrisA7 (author)jesper birk2015-04-22

I was able to get it moving forward, but now it wont seem to turn.

zerger (author)2015-04-19

I am not able to get your code. It keeps saying that there is a fault.

amir.leboss1 (author)2015-04-17

i didn't find the motor driver board 2 channel and i bought the Motor Drive Shield Expansion Board L293D .... can i use it ? and how should i connect it ?

Waiting your answer!

thank you .

Nidhal Yousuf (author)2015-04-08

which is the model number of ultrasonic sensor and motor driver board?

HC-SR04 Ultrasonic Sensor / L9110 2-Channel Motor Driver

Ulytaw (author)2015-03-30


my car just turns right, how can I fix it?

jesper birk (author)Ulytaw2015-03-31

Sounds like the front/steering motor gets a is always ON. Check if the motors are wired to the motor shield correctly.

dawitd (author)2015-03-31

Okay so I fixed the Ultrasonic.h library problem I was having, but now I get a new error. It says the following:

Arduino: 1.6.2 (Windows 7), Board: "Arduino Uno"

ArduinoProj1.ino:36:28: error: 'class Ultrasonic' has no member named 'Ranging'

ArduinoProj1.ino:36:36: error: 'CM' was not declared in this scope

ArduinoProj1.ino: In function 'void loop()':

ArduinoProj1.ino:66:24: error: 'class Ultrasonic' has no member named 'Ranging'

ArduinoProj1.ino:66:32: error: 'CM' was not declared in this scope

ArduinoProj1.ino:85:28: error: 'class Ultrasonic' has no member named 'Ranging'

ArduinoProj1.ino:96:28: error: 'class Ultrasonic' has no member named 'Ranging'

ArduinoProj1.ino:102:32: error: 'class Ultrasonic' has no member named 'Ranging'

ArduinoProj1.ino:107:28: error: 'class Ultrasonic' has no member named 'Ranging'

ArduinoProj1.ino:123:32: error: 'class Ultrasonic' has no member named 'Ranging'

ArduinoProj1.ino:139:32: error: 'class Ultrasonic' has no member named 'Ranging'

ArduinoProj1.ino:145:32: error: 'class Ultrasonic' has no member named 'Ranging'

ArduinoProj1.ino:152:32: error: 'class Ultrasonic' has no member named 'Ranging'

ArduinoProj1.ino:158:32: error: 'class Ultrasonic' has no member named 'Ranging'

Error compiling.

any ideas on how to correct this?

jesper birk (author)dawitd2015-03-31

I have added the library I use to step 5 in the instrutable. Try using that one.

dawitd (author)2015-03-31

does anyone have the Ultrasonic.h library that works with this project, I can't find one that works.

jesper birk (author)dawitd2015-03-31

I have added the library I use to step 5 in the instrutable.

phil.grimley (author)2015-03-30

Trying to build something very similar to this. I've modded your code a little (to sort my motor shield etc) but I'm loving the ideas. *nearly* got it to work.... (I think it's actually my sensor that's screwed)

But cheers anyway! :)

arduinoarpan (author)2015-03-29

Hey can you name which ultrasonic sensor model have u used??

jesper birk (author)arduinoarpan2015-03-30

I believe it's a HC-SR04 Ultrasonic Sensor

AdrianP2 (author)2015-03-24

F3E7GSUHZI8QI9Q:41: error: 'class Ultrasonic' has no member named 'Ranging'

can you help me please? I can´t fix this error, I install the "ultrasonic.h" library but still not working

jesper birk (author)AdrianP22015-03-25

Try finding a different (newer) version of the ultrasonic.h library

cabad2 (author)2015-03-24

Hello, I'm having a hard time getting this to work. I have the arduino connected to a 9v battery and a separate power supply of 3 AAA batteries connected to the motor board but the car will not run while on the ground. The wheels only turn when held up in the air. Any suggestions???

jesper birk (author)cabad22015-03-24

Hi :) it sounds like you maybe don't get enough power from the 3 AAAs to drive the car forward. Even if this was enough to drive the car unmodified, the motor-board may 'eat' up a lot of the 'juice'. Hope this helps! Let me know how it goes :)

rgthevamp (author)2015-03-18

hello, this is an amazing project.

Actually I'm new to the world of electronics so I don't know many stuffs.

I've a techfest and I'm thinking of building the same model.

It's autonomous RC car you've built but in my techfest I'd need to run it on a specific track and there'd be some obstacles too. So I wanted to know if I'll be able to control how the car moves once it comes in front of an obstacle. Like if it just stops there and then I tell it what to do. Would it be possible?

Please reply ASAP.

jesper birk (author)rgthevamp2015-03-20

This setup is designed/programmed to run on its own and make its own 'decisions' and there is no way to communicate with the car while it's running...

0r7iz (author)2014-11-17

Hey man, great tutorial. I have a question that maybe you can answer: I followed your GREAT tutorial and My motor drive is heating up within seconds of inducing power and it suddenly stops within those seconds also, Have any idea what's going on there?

jesper birk (author)0r7iz2015-02-17

hmmm .... I'm using the same motor driver with more power and no overheating problems. Perhaps there is something wrong with the driver or it's getting more power than you think it is???

0r7iz (author)0r7iz2014-11-17

i used the HG7881 Two-Channel Motor Driver, the car is powered by 3 AA batteries (4.5V) and the arduino one has it's own power source

joelfomenky12 (author)2014-11-17

hi i got a pin sensor,

Parallax PING))) Ultrasonic Sensor #28015. wish to know how i could change the coding to suit this sensor

looks pretty standard - no need to change code. You may however need to experiment with different versions of the ultrasonic.h library

cscrivens (author)2014-11-25

where do u add

Ultrasonic.h code in ur code where do u paste it

jesper birk (author)cscrivens2015-02-17

iTaz1 (author)2014-12-12

Hey there, great work. Excellent coding.. I found all libraries I need online and Arduino software compiles fine.
I'm using an L298n control motor board and connected everything as you mentioned. But for some reason my motors aren't running after I upload the code and connect both (Arduino + Control board) back to stealing power from batteries.

jesper birk (author)iTaz12015-02-17

Hi Taz. SORRY for the late reply (all work and no play...) Did you solve your problem or did you give up??

From your photos, it looks like the motor control has power ... question is, if it's get enough power. Or perhaps it steal all the power from the board/sensor... See my reply above to check what the sensor is doing.

iTaz1 (author)iTaz12014-12-12

Another thing, do I have to connect anything from the motor board to the breadboard? or a wire from battery to breadboard?

Apologies I'm a mechanical engineering student so what I reached so far is the closest to an accomplishment.

ten987456 (author)2015-02-12

I made this but motors are always working.

Could you please check the code, upload suitable ultrasonic.h or do anyone else.

Really I want to build this. Please help me.

Thank you!

jesper birk (author)ten9874562015-02-17

The reason could be that the distance sensor isn't giving any (or giving wrong) output. Try removing the '//' from the '// Serial.println(ultrasonic.Ranging(CM));' at the beginning of void loop()

Then check the output in the serial monitor:

If you get weid values, check connections - check if the sensor is getting enough power or try a different version ultrasonic.h (I'll try to find the version I'm using and add it to the instructable, as it seems a few people have problems with this)

Khairul FaidhiJ (author)2015-02-12

Hello there... Who have done successfully do this project? May I rent it for a while or just sell it to me. I'm interested to own this one.

kylealexander23 (author)2014-10-16

um hi.... this project was awesome.. i manage to made it by following every step u show in here... it kinda fun because this is my 1st time getting started to this kind of project... lol....

About This Instructable




More by jesper birk:Autonomous Race Car
Add instructable to: