Cheap Obstacle Sensor - With Arduino!

26,971

37

18

Intro: 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

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

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

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.

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);
Serial.begin(9600);
}

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

Serial.println(distance);

}

Share

    Recommendations

    • Optics Contest

      Optics Contest
    • Electronics Tips & Tricks Challenge

      Electronics Tips & Tricks Challenge
    • Audio Contest 2018

      Audio Contest 2018

    18 Discussions

    0
    None
    FiZZii

    1 year ago

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

    0
    None
    Pushkar Jog

    2 years ago

    I tried to do it

    But instead got my IR LED Burnt..!!

    0
    None
    SheetalP1

    2 years ago

    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

    0
    None
    KrityatirthaP

    2 years ago

    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 ??

    0
    None
    zack195610

    3 years ago on Introduction

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

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

    0
    None
    rajarshi24

    4 years ago on Introduction

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

    0
    None
    us241098

    5 years ago on Introduction

    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
    THANKS !!

    0
    None
    diy_bloke

    6 years ago on Step 4

    interesting.
    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

    6 replies
    0
    None
    dunnosdiy_bloke

    Reply 6 years ago on Step 4

    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 :)

    0
    None
    diy_blokedunnos

    Reply 6 years ago on Step 4

    :-) 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

    0
    None
    dunnoswaterlubber

    Reply 6 years ago on Introduction

    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

    0
    None
    diy_blokediy_bloke

    Reply 6 years ago on Introduction

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