Devices & Components
Arduino Uno Rev3
Male/Male Jumper Wires
I2C LCD display
PIR Sensor
jumper wires male to female
Hardware & Tools
Breadboard, 830 Tie Points
Software & Tools
Arduino IDE
Project description
Code
PIR sensor code
1#include <Wire.h> 2#include <LiquidCrystal_I2C.h> 3 4// Create LCD object with I2C address 0x27, 16 columns, 2 rows 5LiquidCrystal_I2C lcd(0x27, 16, 2); 6 7// PIR sensor pin 8const int pirPin = 2; 9int pirState = LOW; 10 11void setup() { 12 pinMode(pirPin, INPUT); 13 14 // Initialize LCD with proper arguments 15 lcd.begin(16, 2, LCD_5x8DOTS); 16 lcd.backlight(); 17 lcd.clear(); 18 lcd.setCursor(0, 0); 19 lcd.print("PIR sensor Ready!"); 20 delay(2000); 21 lcd.clear(); 22} 23 24void loop() { 25 int motion = digitalRead(pirPin); 26 27 if (motion == HIGH) { 28 if (pirState == LOW) { 29 lcd.clear(); 30 lcd.setCursor(0, 0); 31 lcd.print("Motion Detected"); 32 pirState = HIGH; 33 } 34 } else { 35 if (pirState == HIGH) { 36 lcd.clear(); 37 lcd.setCursor(0, 0); 38 lcd.print("Not Detected"); 39 pirState = LOW; 40 } 41 } 42 43 delay(500); 44}
Downloadable files
This is the circuit diagram
Epic Hillar-Turing.png

Comments
Only logged in users can leave comments