-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.txt
More file actions
37 lines (33 loc) · 1019 Bytes
/
code.txt
File metadata and controls
37 lines (33 loc) · 1019 Bytes
1
#include "LiquidCrystal.h"LiquidCrystal lcd(9, 8, 7, 6, 5, 4); // Pins of the lcdvolatile int pirState = LOW; // Stores the PIR sensor statevoid setup(){ Serial.begin(9600); lcd.begin(16, 2); lcd.setCursor(0, 0); lcd.print(" PIR Sensor "); pinMode(2, INPUT); // PIR sensor output pin connected // Attach the interrupt handler function to the interrupt pin (INT0 on pin 2) attachInterrupt(digitalPinToInterrupt(2), pirInterrupt, CHANGE);}void pirInterrupt(){ pirState = digitalRead(2); // Read the PIR sensor state and store it in the global variable}void loop(){ // You can remove this line, as the interrupt will handle updating the pirState variable // val = digitalRead(2); Serial.println(pirState); // See the value in the serial monitor in Arduino IDE if (pirState == HIGH) { lcd.setCursor(0, 1); lcd.print(" DETECTED "); } else { lcd.setCursor(0, 1); lcd.print(" NOT DETECTED "); }}