Introduction: Cheap Obstacle Sensor - With Arduino!

Picture of Cheap Obstacle Sensor - With Arduino!

When I started with arduino, and electronics, I always wanted to do things the cheap way.

Nothing has changed.

Step 1: Parts

Picture of Parts

You will need:
- Infrared LED
- Infrared photodiode
- Arduino
- Wires of some sort
- Electrical tape, duct tape, even hot glue!
- Heat shrink
- Perhaps a breadboard for testing

Step 2: Constructing the Sensor 1, Soldering

Picture of Constructing the Sensor 1, Soldering

First off the sensor will be soldered together.

As you can see in the pictures, both the LED and the photodiode have a long and a short leg. The short legs should be connected to eachother like you can see in the picture. Any questions?

Step 3: Constructing the Sensor 2, Covering

Picture of Constructing the Sensor 2, Covering

The photodiode will be covered, so any ambient light won't affect the readings. This will be done with some heatshrink tubing, or duct tape. Heat shrink is recommended.

Cut off a section of heat shrink a bit longer the black blob on your photodiode. Put it on and heat it! Easy, right?

Step 4: Finishing, Arduino.

Picture of Finishing, Arduino.

You will now have an LED and a photodiode soldered together. You can either glue these together, tape them together (wich I think is neater) or heatshrink together(neatest).
What results is something like picture

Connect the long pin of the LED with +5v, the short pins to GND and the long photodiode lead to a pin on your Arduino. Preferably an analog pin. Set it as INPUT and write it HIGH to activate the internal pullup resistor. The lower the value analogRead() gives, the closer something is.

an example code, you can upload this to your arduino board. The LED will light as soon as the obstacle comes close. Increasy the integer sensitivity to increase the distance to activate. Watch out though! Too much and you won't be able to sense because of ambient light!

int LED = 13;
int sensor = A0;
int distance;
int sensitivity = 700

void setup()
pinMode(LED, OUTPUT);
pinMode(sensor, INPUT);
digitalWrite(sensor, HIGH);

void loop()
distance = analogRead(sensor);
if (distance < sensitivity)
digitalWrite(LED, HIGH);}




FiZZii (author)2017-08-16

how A0 can use as a digitalwrite HIGH and analogread, if already HIGH than it will always give 1023 reading.

Pushkar Jog (author)2015-12-25

I tried to do it

But instead got my IR LED Burnt..!!

SheetalP1 (author)2015-12-12

Help me Please!! i did almost exactly like this but on my own, just had added resisters( but i dont remember the values :( ),, at that time it worked but now this is not working,,,,i searched internet and found this which is almost exactly like mine version,, but mine readings are mostly zero's and few values up for 5 to 10 steps and then again zero, Help PLZ !!!! else tell me some way to do ir sensor simply

KrityatirthaP (author)2015-11-21

hey I am a new user to instructables,

I am correctly working on a project to find the speed of an moving metal ball(about 1mm of radios) but, I have a question, your idea is really good and cheap.

Will this circuit be able to recognize the ball(1mm radios) at high speeds ??

zack195610 (author)2015-07-19

Nice! I like it. Compact, simple, and it works.

P.S. I like your profile pic. Very funny.

rajarshi24 (author)2014-09-25

awesome project.........really cheap.............i nly changed the sensitivity to 500......thanks

us241098 (author)2013-07-21

hii dunnos ! cheap and cool instructable but there is a problem for me .i am going to make a efficient road lightning system as my school project . using your ideaa i want streetlights to turn on when there is a obstacle say car in front. but i want to connect different 3 pairs of sensors on different points on miniature road say at distance of 5 cm and when obstacle comes in front of any sensor the led connected should turn on. Could u help me

diy_bloke (author)2011-12-24

Since the program seems to measure amount of light reflected, I presume the outcome also depends on reflection of the approaching object. Also as it is IR, a warm object wld probably give a different reading than a cold object. (I understand the code is only to test the functionality of yr sensor design)

Nevertheless an interesting set up

One wld be tempted to use the same sensor you constructed and send a pulse to the LED, measuring the time it took for that pulse to come back

dunnos (author)diy_bloke2012-01-02

This is just a very crude sensor, one would just use it for obstacle detection in a cheap robot.

Interesting idea with the pulse but I don't know if that would be that easy... light travels at 300 000 m/s so the reading would be too fast for your average microcontroller.

If you try, make a picture :)

diy_bloke (author)dunnos2012-01-02

:-) Did not want to critcize, I understand it is just a crude (but useful thing).
It is actually even worse. Light goes 300.000 Km/sec. I think I was being a bit too academic about it

waterlubber (author)diy_bloke2012-09-03

Just to say, IR is the slowest light. (I think)

dunnos (author)waterlubber2012-09-04

cute :)

all light has the same speed, just the energy is different because it's a wave.

Or I am completely missing something and making a fool of myself :p

diy_bloke (author)diy_bloke2012-01-06

OK, on an academic level: modulating the outgoing light with a lower frequency and measuring the frequency shift :-)
Hmm, better to keep it simple :-)

waterlubber (author)diy_bloke2012-09-03

doppler effect?

theinventor.programmer (author)2012-07-14

Don't worry, is working again


great instructable

theinventor.programmer (author)2012-07-06

It doesn't work for me

i connect the pins correctely and the serial port give me always 0

What happens when you disconnect the sensor? Perhaps try another analog port?

samwhiteUK (author)2011-10-31

Great intro!

About This Instructable




More by dunnos:Cheap obstacle sensor - with Arduino!Digital Dice: an Arduino project.How to clean a keyboard
Add instructable to: