Comments on: ESP8266 NodeMCU Door Status Monitor with Telegram Notifications https://randomnerdtutorials.com/esp8266-nodemcu-door-status-telegram/ Learn ESP8266, ESP32, Arduino, and Raspberry Pi Sun, 11 May 2025 18:41:21 +0000 hourly 1 https://wordpress.org/?v=6.8.2 By: Arnie https://randomnerdtutorials.com/esp8266-nodemcu-door-status-telegram/#comment-1042660 Sun, 11 May 2025 18:41:21 +0000 https://randomnerdtutorials.com/?p=106963#comment-1042660 Added this code for a second reedswitch which set as const int however I seem to have done something wrong as it just sends messages when the first reedswitch is closed

// Read the current door state
pinMode(reedSwitch, INPUT_PULLUP);
pinMode(reedSwitch2, INPUT_PULLUP);
state = digitalRead(reedSwitch);
state2 = digitalRead(reedSwitch2);

// Set LED state to match door state
pinMode(led, OUTPUT);
pinMode(led2,OUTPUT);
digitalWrite(led, state);
digitalWrite(led2,state2);

// Set the reedswitch pin as interrupt, assign interrupt function and set CHANGE mode
attachInterrupt(digitalPinToInterrupt(reedSwitch), changeDoorStatus, CHANGE);
attachInterrupt(digitalPinToInterrupt(reedSwitch2), changeDoorStatus2, CHANGE);

// Connect to Wi-Fi
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
}
Serial.println(“”);
Serial.println(“WiFi connected”);

bot.sendMessage(CHAT_ID, "Bot started up", "");

}

void loop() {
if (changeState){
unsigned long currentMillis = millis();
if(currentMillis – previousMillis >= interval) {
previousMillis = currentMillis;
// If a state has occurred, invert the current door state
state = !state;
if(state) {
doorState = “closed”;
}
else{
doorState = “open”;
}

digitalWrite(led, state);
changeState = false;
Serial.println(state);
Serial.println(doorState);

//Send notification
bot.sendMessage(CHAT_ID, "The door is " + doorState, "");

state2 = !state2;
if(state2) {
doorState2 = "2closed";
}
else{
doorState2 = "2open";
}

digitalWrite(led2, state2);
changeState2 = false;
Serial.println(state2);
Serial.println(doorState2);

// Send notifiaction
bot.sendMessage(CHAT_ID, "The door2 is " + doorState2, "");

}

}

}

]]>
By: Arnie https://randomnerdtutorials.com/esp8266-nodemcu-door-status-telegram/#comment-1039314 Fri, 09 May 2025 09:21:19 +0000 https://randomnerdtutorials.com/?p=106963#comment-1039314 In reply to Larry.

Very interested in seeing your code as I am also learning

]]>
By: Arnie https://randomnerdtutorials.com/esp8266-nodemcu-door-status-telegram/#comment-1036386 Thu, 08 May 2025 15:55:28 +0000 https://randomnerdtutorials.com/?p=106963#comment-1036386 In reply to Larry.

Can you post the code please, i need to monitor 2 doors

]]>
By: Sebastian https://randomnerdtutorials.com/esp8266-nodemcu-door-status-telegram/#comment-900029 Thu, 21 Mar 2024 16:34:10 +0000 https://randomnerdtutorials.com/?p=106963#comment-900029 Hello Sara, hello Rui,
Thank you very much for posting those very detailed and helpful tutorials.
Is there a code line I can add to get a timestamp (sent when the event happend) in the message?
But without setting up a #include <NTPClient.h> ?
BR,
Sebastian

]]>
By: Sebastian https://randomnerdtutorials.com/esp8266-nodemcu-door-status-telegram/#comment-900028 Thu, 21 Mar 2024 16:30:36 +0000 https://randomnerdtutorials.com/?p=106963#comment-900028 Hello Sara, hello Rui,
Thank you very much for posting those very detailed and helpful tutorials.
Is there a code line I can add to get a timestamp (sent when the event happend) in the message?
But without setting up a #include <NTPClient.h> ?

BR,
Sebastian

]]>
By: joseph https://randomnerdtutorials.com/esp8266-nodemcu-door-status-telegram/#comment-895006 Tue, 27 Feb 2024 06:18:26 +0000 https://randomnerdtutorials.com/?p=106963#comment-895006 In reply to Sara Santos.

So if I were to use a ESP12-F Doiting ,what would I need to change in the code to make it work correctly? Using the code as it is ,is not stable, for instance on my breadboard I have made the connection(simple), if I jumper the connection to imitate a magnetic switch led is on then I get a response that the door is open then closed , remove the jumper it again does the same , door is open then closed.
Thanks

]]>
By: Larry Fostano https://randomnerdtutorials.com/esp8266-nodemcu-door-status-telegram/#comment-827849 Sat, 01 Apr 2023 22:48:41 +0000 https://randomnerdtutorials.com/?p=106963#comment-827849 In reply to khokan.

I’ve had same issues, tried with several devices. Never really got it to work to my satisfaction but have had suggested to me to put a 22 mfd cap in parallel with door contact. Again, for me it wasn’t satisfactory but it may work for you.Good luck

]]>
By: Sara Santos https://randomnerdtutorials.com/esp8266-nodemcu-door-status-telegram/#comment-827796 Sat, 01 Apr 2023 14:48:42 +0000 https://randomnerdtutorials.com/?p=106963#comment-827796 In reply to khokan.

Here is some information about debouncing: https://docs.arduino.cc/built-in-examples/digital/Debounce
It can be applied to the door switch.
Regards,
Sara

]]>
By: khokan https://randomnerdtutorials.com/esp8266-nodemcu-door-status-telegram/#comment-827781 Sat, 01 Apr 2023 13:08:25 +0000 https://randomnerdtutorials.com/?p=106963#comment-827781 In reply to Sara Santos.

Thank you for the reply. I have used the same magnetic reed switch you used i think and tested with multimeter where it seems okay and also as a newbie to arduino and coding i don’t actually know how to “debouncing” the code. it would be a great help if you can assist me to solve the problem.

]]>
By: Sara Santos https://randomnerdtutorials.com/esp8266-nodemcu-door-status-telegram/#comment-827766 Sat, 01 Apr 2023 10:16:21 +0000 https://randomnerdtutorials.com/?p=106963#comment-827766 In reply to khokan.

Hi.
It might be an issue with your circuit or with the door sensor you’re using.
You might need to add some debouncing code to prevent that.
Regards,
Sara

]]>