Software & Tools
Arduino IDE
Project description
Code
PIR Sensor Integration
arduino
1//Interface a PIR sensor to detect motion and display "Motion detected" or 2//"No motion" depending on the output from the sensor 3 4#include <LiquidCrystal.h> 5 6//variable declarations 7uint8_t readPIR = 0; 8uint8_t nomotionflag = 0; 9const int RS = 2, EN = 3, D4 = 4, D5 = 5, D6 = 6, D7 = 7; 10 11LiquidCrystal lcd(RS,EN,D4,D5,D6,D7); //set Uno pins that are connected to LCD, 4-bit mode 12 13void setup() { 14 lcd.begin(16,2); //set 16 columns and 2 rows of 16x2 LCD 15 pinMode(8, INPUT); //output of PIR sensor (input to Uno) 16 pinMode(9, OUTPUT); //input to PIR sensor to enable (output of Uno) 17 digitalWrite(9, HIGH); //enable PIR sensor 18 19} 20 21void loop() { 22 readPIR = digitalRead(8); //check if motion detected 23 24 if (readPIR == 1){ //motion detected 25 nomotionflag = 0; //reset flag 26 lcd.home(); 27 lcd.print("Motion Detected"); 28 delay(500); 29 } 30 31 else{ //no motion detected 32 if (nomotionflag == 0){ 33 lcd.clear(); 34 lcd.print("No motion"); 35 nomotionflag = 1; 36 } 37 38 } 39 40}
Downloadable files
Final Circuit Schematic
Final Circuit Schematic

Final Circuit Schematic
Final Circuit Schematic

Comments
Only logged in users can leave comments