Introduction: IR-Distance Sensor Homemade Tutorial

this instrument can detect precisely any object from a distance of 40 cm to 0.5 cm.
and this can actually calculate the distance of the object .
Here i will use this feature to analogWrite the LED.  which will incerease its brightness as the distance gets lesser ...

Step 1: The Circuit

You Can Build this with these Materials :-

-Arduino (Uno)
-Jumper Wires
-Breadboard
-Resistors(10K,330OHMS)
-LED(Indicator ,any colour)
-IR LED Pair

You should follow The Schematict to make your own sensor then you may follow ahead ........

Step 2: Coding and Caliberating the Sensor

the code is as follows :-

when there is no object is in front of it then my serial monitor reads 168..

so only if the value is above 170 then the sensor will read the value hence the bolded number is a bit more than your normal sensor value .......

The minvalue is the variable used for that purpose ...!

[CODE/]

int led = 9 ;

int minValue = 170;


void setup() {
Serial.begin(9600);
pinMode(led,OUTPUT);
}

void loop() {
int sensorValue = analogRead(A5);
if (sensorValue > minValue){

int val = map(sensorValue, minValue, 980 , 0, 255);

analogWrite(led,val);
Serial.println(sensorValue);
}

else {
digitalWrite(led,LOW);
}
}


[/CODE]

Comments

author
johnyradio made it! (author)2015-01-05

So, the sensor output value is a voltage in the range of 170 to 980, correct? is that millivolts? microamps?

The sensor output range will depend on your power supply, right?

i'm thinking you could take the Arduino out of the circuit, and drive the LED directly from the sensor, no? Maybe with a boost transistor.

thx

author
dudes made it! (author)dudes2016-03-17

It's the Arduino's ADC value, each unit is equivalent to roughly 4.8 millivolts. The scale is 0v-5v.

author
HarshV made it! (author)HarshV2016-04-17

Dudes is right .

author
Danger is my middle name made it! (author)2014-06-30

Nice job!

author
HarshV made it! (author)HarshV2016-04-17

Thanks

author
AlfredoO5 made it! (author)2016-04-14

could i get rid of the arduino and just mesure the voltage output of the ir led?, will it be proportional to the distance?

author
HarshV made it! (author)HarshV2016-04-17

Yeah sure . But the voltage will be inversly proportional . As amount of IR light reflected is inversly proportional to distance . You might have to do some careful caliberations .Go ahead and tell me how it worked ..!

author
johnyradio made it! (author)2015-01-05

confused, because i thought the IR sensor outputs only low or high. How does it detect distance? thx

author
HarshV made it! (author)HarshV2015-12-13

you are reading the voltage drop across the IR Sensor ! that is analog voltage !

author
SheetalP1 made it! (author)2015-12-13

i made it too but works sometimes and sometimes it dont(shows frequent zero's and high numbers) Help me plzz

author
HarshV made it! (author)HarshV2015-12-13

Is it the same code ? or have you modified it ?

author
HarshV made it! (author)2014-05-17

I Made It

DSC00509.jpg

About This Instructable

7,929views

30favorites

License:

More by HarshV:Automatic Temperature Sensor IR-Distance (Analog Value) Sensor 2$Opto-Isolator  Homemade (9 - 35 Volts with Arduino)
Add instructable to: