IR-Distance Sensor Homemade Tutorial
by HarshV in Circuits > Arduino
15213 Views, 32 Favorites, 0 Comments
IR-Distance Sensor Homemade Tutorial
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 ...
The Circuit
-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 ........
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]