Passive Infra-Red sensor with LCD
This is my first project in blog and i am gonna so you how to interface Passive Infra-Red (PIR) sensor with Arduino UNO R3 and 16*2 LCD.
Hope you know whats PIR sensor is because i am not discussing about PIR sensor, LCD and the main brain of this project the Arduino.
Ok lets start from pin to pin.
LCD PIN TO ARDUINO PINS:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* 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
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
NEXT PIR PIN TO ARDUINO PINS:
*VCC TO 5V
*GND TO GND
*OUTPUT(OUT) TO digital pin 7
Ok lets look the circuit in bread-board.
CODE:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int LED = 13;
const int PIR = 7;
int state = 0;
int calibrationTime = 0;
void setup() {
lcd.begin(16,2);
pinMode(LED, OUTPUT);
pinMode(PIR, INPUT);
lcd.print("LOADING");
delay(2000);
lcd.clear();
for(int i = 10; i > calibrationTime; i--){
lcd.setCursor(8,0);
lcd.print(i);
delay(1000);
lcd.clear();
}
lcd.setCursor(0,0);
lcd.print("DEVICE");
lcd.setCursor(0,1);
lcd.print("ACTIVE");
delay(2000);
lcd.clear();
}
void loop() {
state = digitalRead(PIR);
if (state==HIGH) {
digitalWrite(LED, HIGH);
lcd.print("SOMEBODY IS IN YOUR ROOM");
delay(1000);
for (int positionCounter = 0; positionCounter < 9; positionCounter++)
lcd.scrollDisplayLeft();
delay(1500);
lcd.clear();
} else {
digitalWrite(LED, LOW);
lcd.print("NO ONE IS IN YOUR ROOM");
delay(1000);
for (int positionCounter = 0; positionCounter < 9; positionCounter++)
lcd.scrollDisplayLeft();
delay(1500);
lcd.clear();
}
}
Hope you that you are the genius one so i haven't written comments in this code.
For the video click the following link
https://www.youtube.com/watch?v=1R9F92_I5hg&feature=youtu.be
Hope you know whats PIR sensor is because i am not discussing about PIR sensor, LCD and the main brain of this project the Arduino.
Ok lets start from pin to pin.
LCD PIN TO ARDUINO PINS:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* 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
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
NEXT PIR PIN TO ARDUINO PINS:
*VCC TO 5V
*GND TO GND
*OUTPUT(OUT) TO digital pin 7
Ok lets look the circuit in bread-board.
CODE:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int LED = 13;
const int PIR = 7;
int state = 0;
int calibrationTime = 0;
void setup() {
lcd.begin(16,2);
pinMode(LED, OUTPUT);
pinMode(PIR, INPUT);
lcd.print("LOADING");
delay(2000);
lcd.clear();
for(int i = 10; i > calibrationTime; i--){
lcd.setCursor(8,0);
lcd.print(i);
delay(1000);
lcd.clear();
}
lcd.setCursor(0,0);
lcd.print("DEVICE");
lcd.setCursor(0,1);
lcd.print("ACTIVE");
delay(2000);
lcd.clear();
}
void loop() {
state = digitalRead(PIR);
if (state==HIGH) {
digitalWrite(LED, HIGH);
lcd.print("SOMEBODY IS IN YOUR ROOM");
delay(1000);
for (int positionCounter = 0; positionCounter < 9; positionCounter++)
lcd.scrollDisplayLeft();
delay(1500);
lcd.clear();
} else {
digitalWrite(LED, LOW);
lcd.print("NO ONE IS IN YOUR ROOM");
delay(1000);
for (int positionCounter = 0; positionCounter < 9; positionCounter++)
lcd.scrollDisplayLeft();
delay(1500);
lcd.clear();
}
}
Hope you that you are the genius one so i haven't written comments in this code.
For the video click the following link
By the way this is my first project so i am not writing anymore then this and mainly learn the concept of this code not to save in mind without knowing anything.
Comments
Post a Comment