Introduction: Wirless Alarm and Remote Based Nodemcu and TelegramBot
This project used for saves shops from theft and fire and some places in
combines as server room or electricity room that no entry from everyone. this device monitor temperature and fire flame and motion and will send alarm for user. the alarm and control commands send through telegram application. we can control by add shield of relay for device.
We discuss our device component and now will
build it, the figure below show us the block diagram Illustrates what we want to construction and we will explain it through steps of build
Connecting wires sensors and LED with MCU like the figure
below and the Table defined the number of pin of sensor this number will use in code to defined the sensor.
Step 3: Create Bot
It simple to create bot in telegram if we follow this points
1-open telegram Application from your computer or smart phone.
2-search on BOTFATHER this bot is manage all bot in telegram and have a many commands to do it.
3-Use the /newbot command to create a new bot. The BotFather will ask you for a name and username, then generate an authorization token for your new bot.
4- the name and username and API token must save it to use in our code.
The name of our bot that we created is AlramStation and anyone can search on it, the figure below show chatting with Bot-father.
connect nodemcu with
computer through microusb cable and open Arduino IDE select the port of usb that you connected nodemcu on it.
The first one do in our code calling library that define microcontroller board and telegrambot that you can see code
The main points of code:
1- To make sensor run and send measure variable must define the pins of nodemcu that wired through it.
2- define the information of bot that we created (bottoken, username, botname).
3- Create mothed to parse Massage from and to telegramBot
4- Configuration the value of sensor and write condition code for mange it as we like
As an example, pirsensor we initialize if anyone pass in front on it
The measure value of it is HIGH and this will be send a massage to user and on blue led in device, for more details about code this sensor and other sensor and led you can show it in apendex
5- Make a connect with access point of internet
The Wi-Fi manger is open source library to manage connect between
access point and microcontroller. this libaray make a process to connect to ssid of access point very easy to use by user and not need for programmer to do that and can to use another access point if problem happen with the first access point. And it can to configure microcontroller in two mode when we start the device will be run in AP mode after we select the ssid will turn in station mode.
And have a template page to control on Wi-Fi we Designed It According to our need and we use local IP for mange Wi-Fi the IP is 192.168.4.1 the figure29below shows as the Home webpage of sitting Wi-Fi. And figure 30 ,31 shown About device and Scan WIFI Respectively.
the link of wifi manger from github
now will upload the code to nodemcu board and run device for test
and repair the problem if happen.
This is overview of code we use to programed device and connected to telegram the first think does it connect to Wi-Fi ssid of device and its name (sittingwifiofdevice) and open the web browser and write the IP of device (192.168.4.1) and select scan Wi-Fi to select the
access point provide internet.
After that search on our bot in telegram application in smart phone and press start to run device the device will replay to you message proofing the device run. Will send you alarm message if problem happen in workplace.