During this pandemic as all are restricted to homes. And some warehouses which which need to store their products in certain range of temperatures like restaurant storage, pharmaceuticals and These Warehouses need to be monitored continuously at regular intervals. As this process may be a bit difficult during these pandemic times, I came up with this basic idea that alerts the owners by sending bot message via telegram. If at all in some rare cases when the message is not seen, the sensor also alerts the people nearby by glowing emergency.So, that anyone could take action.
Creating Telegram Bot :1. Go to Play store and install new version of telegram application and sign in.
2. After signing in, go on the main chat screen and swife left.
3. Then click on "New Channel".
4. Type your channel name and put up a display picture if you want to. And add suitable description to the channel, something like "Temperature alerts".
5. Keep the channel as public for further uses. and Below a permanent link has to be given after t.me/xxxxxx, you can give your suitable name.
6. In main chats screen search for BotFather and then do /start -> /newbot -> Give a name to bot -> give username for bot.(Save the channel token given)
7. Open the chat of the channel you created and in the info make the bot as on the administrators and give power to send messages.
Connections of LM35 sensor on the Breadboard:1. Connect VCC pin of the LM35 to 5v of the Bolt Wifi module.
2.Output pin of the LM35 connects to A0 (Analog input pin) of the Bolt Wifi module.
3.Gnd pin of the LM35 connects to the Gnd.
ADDITIONALCONNECTIONSTOTHEBREADBOARD(connectingLED):
1. Connect Positive pin the of the LED to the 0th GPIO pin.
2. Connect Negative pin of the LED to the GND pin.
NOTE:Boththeabovestepsshouldbeconnectedalongwiththeprevioussetup.
The image looks like this:
Connections may look a bit clumsy, but are accurate.
CODE:
The Algorithm for this code can be divided into three parts:
1. Take Values from the Temperature sensor
2. Compare the Values with the Threshold value.
3. If the Values exceeds the threshold value, connect to telegram using bolt cloud and give alerts via telegram bot created and also Turn On LED for the indication.
For this we need to save the information of the details in a separate file for safety purposes.
We need a configuration file with details of
1. Bolt API Key
2.Device_Id:
It will be "BOLTXXXXXXXX" in your devices list.
3.Telegram channel Id
It will be given as token in the BotFather Chat.
4.Telegram Chat Id
check your telegram_chat_id (this will be after t.me/)and it is starting with “@XXXX”.
MAINCODE:
The main code consists of two functions:
1. For Taking sensor value from the LM35, which has only one parameter pin.And returns the sensor value.
2. For Sending Message from telegram. This has only message as a parameter.This contains url
url = "https://api.telegram.org/" + conf.telegram_bot_id + "/sendMessage"
and returns the telegram_data. ie., response from telegram.
And while all these is true :
1. Take the sensor value from the pin("A0").You can covert the sensor value to degrees celsius for much better understanding, it can be done by
temperature = (100*sensor_value)/1024
2. Compare the threshold value with the sensor value. If it exceeds then take another response as digitalWrite funtion for glowing LED. And send alert message to from telegram. Using Configurations file.
For more detailed explanation of code you can visit Telegram Module from the Bolt IOT course.
OUTPUT:
Comments