Instructables
loading
loading
Picture of Simple IR proximity sensor with Arduino
DSCN2359.JPG
DSCN2378.JPG
Hello guys! In this instructable I'll teach you how to make a very simple proximity sensor using infrared LEDs and Arduino.
After several times trying to optimize it, I finally came up with something that is quite simple e precise. Just like my first instructable, this project is perfect for beginners in the arduino's world, with a few components anyone can make it. I hope you all enjoy it.

 
Remove these adsRemove these ads by Signing Up

Step 1: Materials

Picture of Materials
For this instructable you are gonna need:
- Arduino
- 1 IR LED receiver (photodiode with 2 pins, not the phototransistor with 3 pins)
- IR LED emitters (as much as you can get, but at least 2)
- 100K resistor (brown black yellow)
- Jumper wires
- Breadboard
- Electrical tape
- Buzzer(optional)

Be careful to don't mix up the LED receiver with the LED emitter, they all look the same.
 

Step 2: Preparing the sensor

Picture of Preparing the sensor
DSCN2312.JPG
DSCN2318.JPG
DSCN2324.JPG
DSCN2330.JPG
Before mount it, we should prepare the IR LED receiver to don't receive light from the sides, so than the sensor is more directional.
I use electrical tape to make it, but you can use a straw or anything that blocks the light from the sides.
Cut a small piece of electrical tape and wrap it around the IR LED receiver, forming a tube. Trim the edge with a pair of scissors until it's about 1cm long.
Have a look at images to see how I made it with electrical tape.
1-40 of 120Next »
mgupta152 years ago
I think there is some error in schematic ...... I think that the reverse bias should be added to photodiode ( IR LED Receiver) and not forward bias. I connected up with forward bias and could not get any reading. I have even triple checked my arduino's analog input pins. Mostly at many other IR sensor tutorials and schematic it is reversed biased. I think Arduino is not sensitive to voltage changes in forward bias. Please double check your schematic and your project.

i her you but i dont understand where you see a issue? can you post a quick pencil sketch pic of the proposal diagram of the renewed schematic? thanks

RukLo mgupta1516 days ago

Thanks for the very good example and the error logs in this posts. Keep up the good work. I will try to move brushless motors through ESCs by using IR proximity sensors (probably 2). I will post the example when I'm done.

Cheers

did you ever got this esc and motors done?>

Yeah, actually the vast majority of the IR sensors are supposed to be reverse biased, and forward biasing them would create almost the same effect of a normal IR emitter, and sometimes it may even burn the diode.

I have been faced to the same problem. My ir receiver didn't worked in forward (I have tried with different bipolar IR receiver) but it nicely works on reverse bias. Like you said the arduino wasn't sensible in forward. Your comment help me much. Thank you @mgupta15

why 4 ir's emitters ? why not just 1 if is only going to be in a upwards direction? or any direction really this works by reflecting of waves coming back from a object in proximity and waves expands like water ripples so why 4?

JulianV22 months ago

Hello, nice work for putting this together, I'm wondering if there's a possibility to replace the buzzer for a servo, I'm trying to make an IR proximity sensor that moves the servo depending on the distance but I can't figure it out yet, any help will be very much appreciated!

RukLo JulianV216 days ago

The output of the IR sensor is Vcd at certain level which in this case Ricardo is sending it to OutPin11 "pinMode(11,OUTPUT); // buzzer in digital pin 11"

When the voltage is too low you won't be able to move your servo but with this same output you could move it to a certain extent. Im gonna try this approach for a prototype but I will connect the output of the micro controller to an ESC and a brushless motor. Before I do that I will try it on a servo because I will be using a similar code in the ESC.

SOLUTION:

Have you tried just plugging the servo control signal to pin 11 and making the changes in the code using the example on arduino's webpage and replacing the pot for the IR output? See images attached and weblinks...

This webpage shows what you are attempting exactly to do but with IR integrated sensors. SHARP brand (see image 3)http://electronics.stackexchange.com/questions/594...

Arduino's forum for servo control:

http://playground.arduino.cc/Learning/SingleServoE...

Important: You will have to make some changes to the code posted in Ricardo's example and combining it with what the servo needs.

Let me know how it goes? I will have my code in about a week. I am using a SHARP IR sensor instead due to the application but it is the same principle.

Cheers, I hope everything works. Otherwise do not hesitate to contact me.

IMAGES ARE NOT MINE. CREDIT TO THE REFERENCES.

simpleservocontrol.jpgpot-servo-circuit.pngQIvK9.jpg
reemsaleh2 months ago

there are 2 green wires in which pin did u insert it

jpineda121 year ago
What does 150-distance mean? Help!
The value 150 he imposed as a "threshold", where the "beeps" from the buzzer will repeat at decreasing rates, since the distance(variable) will get higher(because the object is getting close) providing the distance variable value to be inversely proportional to the real, physical distance measure.

on line 55 and 57, I am wondering what happened more than 151 negative number of distance? if 150 - 151(151 is convert distance number) will be negative 1. because it said delay(150 - distance); , so will it work if delay(-1) function?

here example code...

```

void buzzer(){

if (distance>1){

if(distance>100){ // continuous sound if the obstacle is too close

digitalWrite(11,HIGH);

}

else{ // beeps faster when an obstacle approaches

digitalWrite(11,HIGH);

delay(150-distance); // adjust this value for your convenience

digitalWrite(11,LOW);

delay(150-distance); // adjust this value for your convenience

}

}

else{ // off if there is no obstacle

digitalWrite(11,LOW);

}

}

```

any ideas on how to get this to work in the raspberry

stunito0o07 months ago

Hello, i followed every step of your tutorial, but i get values raging from -5 to -6. I have made sure that every component is okay and working.Do you have any idea why i get this values and how to fix it.

P.S. I did disconnect the IR leds and the IR receiver(the photodiode) and then i am getting 0 as a value.Which means that the leds and the IR receiver work...?

FiggyT7 months ago

Where do you recommend buying the IR LED receiver and multiple IR LED emitters? All the electronic parts shops I've talked to only sell them in pairs so I can't get more than one emitter at a time.

blorgggg8 months ago
DhruvB9 months ago

I've been doing this with on IR Transmitter but it isn't working

neetahar1 year ago

am trying this code...but in my project i connected buzzer ...and the problem is no voltage at pin 11...bcoz of that buzzer is not genrated sound..wt can i do???Please help me.

look at my comment in this post, would you? ;)
FahimSarower9 months ago
I am done making it successfully, Alhamdulillah!

I am seeing a lot of people planning that instead of buzzer if you use an led, it doesn't blink. It's because you haven't done the following,
" Clear The Double Slash to Make the Function Call Uncommented in the Last Line within the Void Loop".

Even if you used a buzzer, it wouldnt work if you haven't uncommented the following.
temp_-2066780674.jpg

Hi, your setup works great! However, I want to change it to a setup where the receiver and transmitter are disconnected from each other. That is: I will need 2 arduino's. For a correct setup I need to know at what frequency the receiver and transmitter LED's are flashing. How to find this frequency?

bilal.tiger made it!10 months ago

Good one. It can be used to sense distance and adjust value in code,where as if an IR Receiving IC is used it can only give ON or OFF state

DSC04364.JPGDSC04363.JPGDSC04362.JPG
aaaaoooo11 months ago

HEAT SHRINK TUBING MAY be used instead of the tape tube

dushu11 months ago

Would it make sense to switch off the LEDs in your code after checking the distance. The current code only switches them off momentarily. Considering that you're not using any current limiting resistors - the LEDs could get damaged.

sghosh2111 months ago

everything works fine .........but in the serial monitor i can see some negative values coming up randomly.......which make my LED go crazy sometimes even in a static position(i used an LED instead of a buzzer).......i fixed it......but i wanted to know why was it happening .....????

dushu made it!1 year ago

Works like a charm. Thanks

2014-06-21 15.23.46.jpg
jobo991 year ago

does itwork with a phototransistor?

mintesinot1 year ago

we are trying to use a photo diode with for our project which is fire fighting robot with two continuous servo and one castor wheel but it does not work can you help us

ricardouvina (author)  mintesinot1 year ago

Sure!

What is the problem? Have you tried using the Serial Monitor for debugging?

If you are using it outside, the sunlight may cause it to not work properly. The fire may cause it too.

Great sensor Mr Ricardo! I really enjoyed making it and even used it to create a gesture controlled LED cube. Check it out......but forgive the bad lighting in the vid.

http://www.youtube.com/watch?v=LADpkeqRgic
ricardouvina (author)  MikeJGarcia1 year ago

Thank you! Excellent project you have made!

MauS092 years ago
Can ANYONE help me please. I have the project ALMOST running. The problem for me is that when i give the microcontroller power and burn the program to it it does absolutely nothing. But when i touch the cable that goes from A0 to the board it comes on. Why is that? Please help me.
ZacWolf MauS091 year ago
I ran into the same issue for awhile, and it turns out I had the anode/cathode wires for the receiver mixed up. I flipped it around and it worked prefectly.
ricardouvina (author)  MauS092 years ago
Probably you are using the resistor after the IR LED receiver, I recomend you to look up carefully the schematic and follows as it is, and check if all the wires are well fixed.
jpineda121 year ago
Specifically, what type of photodiode is needed here?
Commonly, we buy the emitter and receiver in pairs(at least I do), and I see mostly the pair TIL-32 and TIL-78. I can't assure you that these are the names since I don't remember, but with a lil' google search you can differ the emitter and receiver and their names.
jrešetar1 year ago
Hello.
I did it as you said and I have one problem.
It works great but only when light is on. When I turn light off LEDs turn on with no obstacle in front of it.
Why is that so?
Please help me.
marios85431 year ago
Can you work this out with one ir led
1-40 of 120Next »