Introduction: Autonomous Arduino Car

My questions for the Make-to-Learn Youth Contest :)

What did you make?
This goal of this project was to take commonly available electronic equipment and create an inexpensive, self-controlled vehicle. In simpler terms, this is an attempt at basic autonomy. It uses an arduino logic board coupled with a cheap remote control car along with a 9 volt power supply to accomplish this.

How did you make it?
The idea came to me while I was researching infrared sensors and light for a laser synth project I was planning. It seemed to me like a very viable technology for sensing objects, so after a little more research into motors and how I could control them with analog input, this project was born.

Where did you make it?
Without my school classes, I might never have done this. It was an assignment to come up with something cool involving computers, with a fair degree of freedom. I settled with an arduino-based project. Much of the programming and testing was done on the floor of my classroom, and the construction of the car in my bedroom. It took over my life for a week or two, all I was thinking about was bugs in my code and better methods of measuring and processing the infrared.

What did you learn?
Most importantly, the input of others is an invaluable source of ideas and solutions. Whenever I came to a halt in my production, a classmate might chime in and say something I had not previously thought of, like measuring the resistance across the car's motors to see if some object had stopped the car. This is one of the more challenging projects I have completed, and the first to really combine hardware and code, which I feel is a great accomplishment. Looking back, I could have used a bit more planning and done more research (rest in peace, poor LEDs) so that I had less issues. 


This car uses an arduino logic board to process the input from an infrared sensor at an attempt at very basic collision detection/prevention.

This project was only marginally successful. Do not attempt this with high expectations. The low-tech nature of the sensors are very inefficient ways of detecting objects, and in different environments may work better or worse with the code provided. This is only a general guide, modifications will be necessary to make the car work as intended depending on your choice of parts.

That being said, hopefully you're able to make it work a little better than I did!

Step 1: List of Parts

Important Stuff
Arduino
Arduino Motor Shield*
RC Car**
Solder
Soldering iron
Infrared Emitter (IRED)
Infrared Detector
9v Battery with clip
Power switch

General Tools
Screwdriver
Glue of some sort
Copious amounts of wire

*Note: If your car of choice contains a large controller chip, it is likely the TX2 or RX2 chip. If so, you can save a lot of money and use the motor controller built in to the car to control it. Techbitar provides a good tutorial for that here: https://www.instructables.com/id/Arduino-controls-cheap-RC-car-transmitter/

Step 2: Teardown

Your first step will be taking everything out of the car. Remove screws securing the body of the car to the chassis, then remove all circuit boards from the car. The motors should be left in their place, this projects only requires the chassis, wheels, and motors to function properly.

Step 3: Preparing the Sensors

It's time to begin preparing the electronics. To begin, solder a 100 ohm resistor to either lead of your IRED. Solder wires to the other end of the resistor and the other lead of the IRED.

Next, solder two lengths of wire to both leads of your IR Detector.

Check your motor wires, make sure each terminal of the motor has at least 4-5 inches of wire depending on the size of your car.

Step 4: Securing the Arduino and Sensor

After clearing some plastic off the chassis, I chose to use some small zip ties and holes in the chassis to hold my arduino to the car.

Next, you'll want to choose a location on the front of the car for your emitter and detector. You'll want to make sure they are level with the ground, and possibly consider adding heat shrink tubing around the emitter to prevent some light from hitting the detector before it reaches an object.

Another consideration would be to add another set of leds on the back of the car to avoid obstacles while backing, but are not included in this instructable.

Once you have glued your leds in place, go to the next step.

Step 5: Power Supply

This project will run off of a single 9v battery. Take your switch and solder one piece of wire to a pin, and the positive terminal of the battery to another pin.

After this, secure your battery with double sided tape, zip ties, or any other method you prefer.
Mine fit nicely into the cars original battery compartment.

To extend the life of the car you might also connect two batteries in parallel.

Step 6: Wiring

The provided diagram should make this very simple, but here is a list form of the pinout.

Note: The positive lead of an led is the longer leg. If you are unsure of which that is you should consult google about your particular led.

IRED
Pos - 5v
Neg - Ground

Sensor 
Pos - Analog pin 5
Neg - Ground

Drive Motor
Pos - Motor Shield Channel A +
Neg - Motor Shield Channel A -

Steering Motor
Pos - Motor Shield Channel B +
Neg - Motor Shield Channel B -

9v
Pos - Motor Shield Vin
Neg - Motor Shield Gnd

Step 7: Programming

Given the dynamic nature of this project, it is very likely you will need to make many modifications to the code based on the size, shape, turning radius, speed, and weight of your car, as well as the ambient lighting of your testing environment (which I've attempted to compensate for).

int irsensor = A5;
int motorspeed;
int run = 0;
int measure = 1;
int ambientir = 0;
int distance;

void setup() {
  //Setup Channel A
  pinMode(12, OUTPUT); //Initiates Motor Channel A pin
  pinMode(9, OUTPUT); //Initiates Brake Channel A pin
  pinMode(irsensor, INPUT);
  digitalWrite(irsensor, HIGH);
  Serial.begin(9600);
}

void loop(){
  if(run == 0)
  {
    delay(1000);
    do{
      ambientir = ambientir + analogRead(irsensor);
      delay(1000);
      measure = measure + 1;
    }
    while(measure < 10);
    ambientir = ambientir / 10;
    run = run +1;
  }

  distance = analogRead(irsensor);

  if(distance < ambientir - 50){
    digitalWrite(12, HIGH); //Establishes backward direction of Channel A
    digitalWrite(9, LOW);   //Disengage the Brake for Channel A
    analogWrite(3, 100);   //Spins the motor on Channel A at half speed
  }
 
  if(distance > ambientir - 50){
    digitalWrite(12, LOW); //Establishes forward direction of Channel A
    digitalWrite(9, LOW);   //Disengage the Brake for Channel A
    analogWrite(3, 100);   //Spins the motor on Channel A at full speed
  }
  Serial.println(distance);
}

That being said, good luck. I think any programmer will agree, this will not work on your first attempt.

Step 8: Finishing, Testing, and Thoughts

I painted and secured the original body onto my car before I began testing.

Some of the problems I ran into:
Limited range of the sensor
Speed of the car (unable to quickly stop)
Ambient infrared light
Collision
Cheap Chinese plastic

It is possible, I think, to compensate for changing ambient light as the car moves around different environments, but testing that portion of the code would have taken longer than the time I had allotted to this project. The car does a very nice job of avoiding walls, but when it drives towards smaller objects (chair/table legs in my instance) it will frequently run into them because the range and spread of the two leds don't work well together on seeing smaller objects. This is likely also fixable with an increased number of emitters, a higher quality sensor, or clearing the room of obstacles. Another solution to this, which I have yet to complete testing, is reading the resistance across the drive motor when the car is stopped by an object. 

Comments

author
abencomo (author)2014-03-21

Nice article! We built a similar project. However, we installed an Android device onto a RC car and used an IOIO board to control it autonomously. Here is the preliminary result:

author
met7 (author)abencomo2017-05-13

Can you guys send me how you did that. yulianduranvaldez@gmail.com

author
qlouis76 (author)abencomo2014-03-26

hi, do you mind to share more detail of your work?

author
abencomo (author)qlouis762014-03-26

You can find more details here:

http://www.socsci.uci.edu/~jkrichma/ABR/index.html#SOURCE%20FILES

author
SaedS (author)2017-03-03

Hey everyone,

If you are looking for a fully assembled Arduino car (you don't have to assemble it at all), which includes all of the code for it to move and instructions on how to use it, program it, and develop it -

go to: http://www.ebay.com/itm/172559577475?ssPageName=STRK:MESELX:IT&_trksid=p3984.m1555.l2649

author
animeequalzlyfeboi (author)2017-02-21

Can someone tell me where they got their ired?

author
nicholaskheinrich (author)2016-12-04

Rather than avoid obstacles, could this be made to stop and start on a line?

author
RikerinoBlu956 (author)2016-01-01

I have a question about the steering motor part of the RC. What part of the programming affects the steering motor of the RC? It doesn't seem to specify what happens to B channel on the motor shield.

author
mridulzzzzz (author)2015-05-23

I have to make a wireless car with ultrasonic sensor,motion sensor,humidity sensor,gas sensor,wireless camera,light sensor etc is it possible

author
HSa38 (author)2015-01-16

Can I get the code please

author
hankobot (author)2014-12-31

yes i just finished

author
SebastianG2 (author)2014-11-23

This is actually the coolest thing i have ever seen, I quit my job the instant I saw this and dedicated the rest of my life to achieving the euphoria i experienced watching u make this extraordinary work of art. I thank you good sir, you have made my life worth living.

Flanders.jpeg
author
LightningJimmy (author)2014-09-27

Would this project work with a ultrasonic sensor?

author

Yeah, but you'll have to modify the code, an ultrasonic sensor is going to return different readings than an infrered sensor.

author
rvanhart (author)2014-10-09

Do you possibly have a schematic to follow? I'm having trouble following the pictures.

author
xzayveon Benavidez (author)2014-05-16

do I have to use the 9v battery or could I use this 6.7v lithium battery that came with the car

author
deqwer (author)2013-03-07

you should try to add a few more infrared around the car to increase the accuracy of the length between walls and do more math on the turning part

author
absolute zero (author)deqwer2013-03-07

I had considered that, unfortunately time and finances were some limiting factors in this project. The turning function has been improved today, but it still contains bugs. It now will read the resistance across the motors to tell if the car has backed into an obstacle. I also added a little function to calculate the distance the car has traveled, and incorporated random numbers from the noise on unused pins to have the car take different paths instead of going in a straight line.

Thanks for your input!

author
vgruen (author)absolute zero2014-02-03

Hello !
I have to build myself a self-driving rc car for a school project and I believe that I will use an apporach rather similar to yours. Sadly I do not have much experience at all with the arduino or how you program it. I know that I am almost a year to late but do you think you could give me some help ?

author
absolute zero (author)vgruen2014-02-03

Sure. It's not terribly hard, under 50 lines of code if I remember correctly. You'll need an arduino, a motor shield, and the arduino IDE from their website. Let me know when you have that much set up.

author
vgruen (author)absolute zero2014-02-04

Thanks a lot ! Will do !

author
jordantallent (author)2013-12-01

I have been working on a little robot car as well and have found a way to make it stop quick. right before you turn off the motor, run it the opposite direction in the line of code directly before you turn off the motor. this will give you a quick stop.

author
gpotvin (author)2013-06-16

Anybody else notice OMFGDOGS running on the screen?

author
fenix8k (author)2013-03-13

u just say "ir detector" u don t say it a ir led or a real ir detector (like the tv s uses) i read the instructables again, u don t specified what ir detection u use.

author
absolute zero (author)fenix8k2013-03-13

There is no other type of ir detector, they are all the same (albeit some with different ranges), mine was salvaged from a remote control receiver. Ir emitter, ir led, IRLED, those are all the same thing.

author
zack247 (author)absolute zero2013-03-14

the things he speaks of are the IR sensors like televisions use. if im not mistaken, those have phototransistors in them, triggered by a specific frequency of infrared light. it would eliminate the issue regarding ambient light affecting the sensors.

author
absolute zero (author)zack2472013-03-15

Ah okay, his grammar had me very confused. Regaurdless, both types will work (albeit the code must be altered for the three pin remote receiver type, I originally had this until I had an oopsie and it caught fire on me).

author
fenix8k (author)2013-03-13

lol, they are not all the same, and ir led give u a analog output, a true ir reciver give u a digital output and have 3 pin ground vcc and output if u use one of that u have to make a diferent code because they are make to recive ir signal and have a horizontal range of 120° x 90° vertical

author
absolute zero (author)fenix8k2013-03-14

An ir led gives you no input. It is an led. Light emitting diode. It only shines infrared light. Neither of them give you output either, they give you input. Either the two pin or the three pin receiver can be used if the signal pin is connected to the correct analog pin on the arduino.

author
fenix8k (author)2013-03-13

what type of ir sensor u use? you can use 1 ir led to send the light and another ir led to recive the light :p (yes it work) if u connect the ground pin of the ir led to ground and the positive pin to the analog pin on arduino u can sence the light xD test it is a cheap way xD 2 ir led + 1 resistor :P

author
absolute zero (author)fenix8k2013-03-13

Did you actually read the instructable? The intro and step 3 clearly outline all the parts I used. That is exactly what I did. There is a detector and an emitter mounted on the front of the car.

author
shotgunshane (author)2013-03-11

(removed by author or community request)

author
Mic100 (author)2013-03-09

bumpers are micro-ruteurs connectteds by 1,5K resitors one the arduino inputs .
you can use 2 bumbers (left and right) and 2 inputs
or 1 bumper in the midle of front  and 1 input

see picture below.

i've found micro-ruptors on ebay.com

Robot-EP.jpgRobot-EP.jpg
author
absolute zero (author)Mic1002013-03-09

Ahhh okay. I know those as "reed switches". They aren't necessary though as the motor shield allows me to read the current across the motors which will increase if the car contacts any object. Although this would be a good idea if you planned on using the TX2/RX2 chip already in the car since it won't allow the reading of the current across the motors.

author
Mic100 (author)absolute zero2013-03-10

yes to read courant by resistor is good idee to :)

author
Mic100 (author)2013-03-08

hi
you can add bumpers mounted on front and rear contact to complete the infrared
detection.

author
absolute zero (author)2013-03-08

I'm sorry, I fail to see how bumpers have anything to do with infrared detection. Could you explain?

I have a pretty decent ir emitter, it does a good job of projecting the light straight forward so I tried what you suggest with the tape (shrink tubing actually) but it actually made it harder to sense objects because of the displacement between the emitter and detector!

About This Instructable

103,508views

238favorites

License:

More by absolute zero:Faux ivory ring carved from boneControl your computer with Arduino and a JoystickAutonomous Arduino Car
Add instructable to: