Industrial IoT Cloud and ESP8266 with Magnetic Door Sensor with reed switch with Telegram Notifications

The output of the voltage regulator is connected with the Vin pin of the Nodemcu ESP8266 Wifi module and the GND of the power supply is also connected with the ground of the Nodemcu Module.
A magnetic Reed Switch is connected in series with a 10k resistor. This is a Pull Up resistor. When the two contacts of the Reed Switch are open it gives 3 volts to the digital pin D0 of the Nodemcu Module. On the other hand, when the two contacts of the Magnetic Reed Switch are closed, then GND is given as a signal to the digital pin D0 of the Nodemcu Module.
Normally the reed is ‘open’ (no connection between the two wires). The other half is a magnet. When the magnet is less than 13mm (0.5″) away, the reed switch closes and the contact is made between two wires. One part with wire is fitted on the frame of the door and is wired to Arduino. The other part viz., magnet is fixed on the door such that the distance between both elements is less than 13mm when the door is closed.
At present, door sensors are installed on the doors and windows for home security purposes. These sensors allow you to know once somebody has opened/closed a door. Many house owners utilize door sensors to guard entrances. However, these sensors work on any type of door. Actually, door sensors are so adaptable, so they are becoming very popular within activity triggers within smart home design. This article discusses an overview of a door sensor – working with applications
You’ll receive a message in your Telegram account whenever the door changes state: opened or closed. As long as you have access to the internet on your smartphone, you’ll be notified no matter where you are. The ESP8266 board will be programmed using Arduino IDE.
In this project, we’ll create a Telegram Bot that will send messages to your Telegram account whenever a door changes state. To detect the change, we’ll use a magnetic contact switch.
Telegram Messenger is a cloud-based instant messaging and voice over IP service. You can easily install it on your smartphone (Android and iPhone) or computer (PC, Mac, and Linux). It is free and without any ads. Telegram allows you to create bots that you can interact with.
“Bots are third-party applications that run inside Telegram. Users can interact with bots by sending them messages, commands, and inline requests. You control your bots using HTTPS requests to Telegram Bot API“.
The ESP8266 will interact with the Telegram bot to send messages to your Telegram account. Whenever the door changes state, you’ll receive a notification on your smartphone (as long as you have access to the internet).

Creating a Telegram Bot

Go to Google Play or App Store, download, and install Telegram.

If your bot is successfully created, you’ll receive a message with a link to access the bot and the bot token. Save the bot token because you’ll need it so that the ESP8266 can interact with the bot.

Sending a Message to the Bot

This step is very important. Don’t miss it. Otherwise, the project will not work.
You must send a message to your Telegram Bot from your Telegram account before it can send you messages.

Get Your Telegram User ID

To send a message to your Telegram account, the bot needs to know your user ID.
In your Telegram account, search for “myidbot” or open this link t.me/myidbot on your smartphone.
Start a conversation with that bot and type /getid. You will get a reply back with your user ID. Save that user ID, because you’ll need it later in this tutorial. Universal Telegram Bot Library
To interact with the Telegram bot, we’ll use the Universal Telegram Bot Library created by Brian Lough that provides an easy interface for the Telegram Bot API.

Click here to download the Universal Arduino Telegram Bot library.

Go to Sketch > Include Library > Add.ZIP Library…
Add the library you’ve just downloaded.
Important: don’t install the library through the Arduino Library Manager because it might install a deprecated version.
For all the details about the library, take a look at the Universal Arduino Telegram Bot Library GitHub page

ArduinoJson Library

You also have to install the ArduinoJson library

Follow the next steps to install the library.

Now when someone opens/closes your door, you receive a message in your Telegram account.