PIR-SB312 and ESP8266

Hello everyone, I'm doing a motion sensor alarm project. I wanted to do arming via a button. If you press the button, it should start a timer for 30 seconds. After the timer, it should Serial.println("timer stop"); and start the motion sensor. If you do not press the button after turning on the power or the timer does not end after pressing the button, then the motion sensor should not react.

int pirPin = D7;
void setup() {
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(D3, INPUT_PULLUP);
}

void loop() {
  if (digitalRead(pirPin) == HIGH)
  {
    Serial.println("MOVEMENT");
  }
  else
  {

    Serial.println("Too soon");
  }

}

add to setup reading the button and delay, like this:

while (digitalRead(Button) == HIGH) {};   // wait for button press
delay(30000);
Serial.println("timer stop");

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.