PIR Sensor Interfacing with ESP8266
Program
#define pir D1
#define LED D2
void setup() {
Serial.begin(9600);
pinMode(pir, INPUT); // declare pir sensor pin as input
pinMode(LED, OUTPUT); // declare LED as output
}
void loop() {
long state = digitalRead(pir);
if(state == HIGH) {
Serial.println("Motion Detected");
digitalWrite (LED, HIGH);
delay(5000);
}
else {
Serial.println("Motion not detected");
digitalWrite (LED, LOW);
delay(1000);
}
}
Comments
Post a Comment