I have a very simple code of door sensor (magnetic) which gives results in 1 & 0 format. But I want to run the NodeMCU only when a door is open or close. Rest of time I want to keep it in deep sleep mode. Here is my code looks like :
int doorClosed = 1;
#define REED_SWITCH D5
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(BUILTIN_LED, OUTPUT);
digitalWrite(BUILTIN_LED, HIGH);
pinMode(REED_SWITCH, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly
Serial.println(digitalRead(REED_SWITCH));
if ((digitalRead(REED_SWITCH) == HIGH) && (doorClosed == 1))
{
Serial.println("DOOR OPEN!!");
doorClosed = 0;
digitalWrite(BUILTIN_LED, LOW);
ESP.deepSleep(0);
}
else if ((digitalRead(REED_SWITCH) == LOW) && (doorClosed == 0))
{
Serial.println("DOOR CLOSED!!");
doorClosed = 1;
digitalWrite(BUILTIN_LED, HIGH);
ESP.deepSleep(0);
}
delay(500);
}
Here I am able to put the NodeMCU in deep sleep. But it never wakes up. How can I wake up my chip. After attaching the D0 with RST, I don't event get Serial Logs. I am not sure what kind of behaviour is this. If someone can help me to fix this code will be great!
Thank you!