Instructables
loading
loading
Picture of IR-Distance Sensor Homemade Tutorial
DSC00515.jpg
DSC00516.jpg
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 ...

 
Remove these adsRemove these ads by Signing Up

Step 1: The Circuit

Picture of 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

Picture of Coding And Caliberating the Sensor
DSC00514.jpg
DSC00510.jpg
DSC00511.jpg
DSC00512.jpg
DSC00516.jpg

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]

johnyradio2 months ago

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

johnyradio2 months ago

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

Nice job!

HarshV (author) made it!10 months ago

I Made It

DSC00509.jpg