Introduction: IR-Distance (Analog Value) Sensor 2$
This Homemade IR Distance Sensor can easily sense distance betwwn 55 cm to 0.5 cm and display it on a 16X2 LCD
it does not require any costly sensors or drivers.....
all it uses is an IR Pair and a few resistors ............
the cost of the finished sensor is under 2$ !!!! Happy Constructing
Step 1: Getting Started
You will require these materials for the build :-
-- IR LED Pair(Transmitter and Reciever)
-- 16X2 LCD
-- 10 K Resistor
-- LED (Normal)
-- Breadboard
-- Jumper Wires
-- Arduino (or other microcontroller) ...
Step 2: The Circuit !!!
just follow the fritzing diagram :-
also add the lcd from pins 7 to 2
like this wiring :-
* LCD RS pin to digital pin 7
* LCD Enable pin to digital pin 6
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor: ends to +5V and ground
* wiper to LCD VO pin (pin 3)
Step 3: Code It !!!!
the code is :-
[CODE/]
#include
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int ledpin = 9 ;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
}
void loop() {
int sensorValue = analogRead(A5);
sensorValue = map (sensorValue,3,20,0,1000);
if (sensorValue > 60){
lcd.print("Motion Detected");
lcd.setCursor(0,1);
lcd.print(sensorValue);
}
Serial.println(sensorValue);
sensorValue = map (sensorValue,0,1000,0,255);
analogWrite(ledpin,sensorValue);
delay(50);
lcd.clear();
}
[/CODE]
Step 4: Caliberating the Sensor !!!!!
when there is no object in front of the sensor then the value that is displayed on the lcd is the minimum value
just place it into the
minValue of the given code:-
in my case it was 58 so i decided to go onto 60..
put the value in the map function...