This is a Capstone project, that aims in building a Temperature anomaly detector device with the help Bolt Wi-Fi module(esp8266), a temperature sensor LM35, some jumper wires, a breadboard and on top of that a Power Bank to supply power to the device. In this project, Python language is used in writing the code and Z-score analysis(part of Machine learning) for anomaly detection. Sending an Alert using Telegram messaging services when the chamber is opened.
STEPS:1)Connecting LM35 and Bolt Module
Step1: Look for the pinout of LM35, if you already knowing it, GOOD!. Otherwise here is the following pinout of LM35.
Step2: Now connecting the LM35 sensor to Bolt Module, through jumper wires and breadboard.
- The first image shows, connection of LM35 and breadboard, the three pins are placed in three different slots of breadboard. From left to right, the pins are VCC, OUTPUT, GND respectively.
- IN second image, male-to-male jumper wires are connected in breadboard. From left to right, violet jumper wire is connected to VCC pin-column, orange jumper wire is connected to OUTPUT pin-column, grey jumper wire is connected to GND pin-column.
Here pin-column means, the respective column of slots in which the pins of LM35 sensor are placed as the connections in breadboard are column-wise.
- In the last image, the final connections are shown. VCC pin of LM35 connects to 3v3 of Bolt Wi-Fi Module through violet jumper wire. OUTPUT pin of LM35 connects to A0 of Bolt Wi-Fi Module through orange jumper wire. GND pin of LM35 connects to GND of Bolt Wi-Fi Module through grey jumper wire.
2)Creating product on Bolt cloud
Step1: Firstly create a product in bolt cloud, uniquely name it and set the configurations as shown above.
Step2: Then click configure this product and configure the hardware and software accordingly as shown below.
Step3: After writing the code, save it and exit.
Step4: Now click on the link icon and link the Bolt device to the created product and deploy it.
4)Keep the device in fridge for 2hrs and analyze graph
As we can see the graph gradually decrease, and after a certain time(3:00 PM) lies within a range i.e. the temperature of the refrigerator ranges form 4 to 5 degree Celsius. And the sudden changes in the graph (after 3 PM) shows that someone has opened the refrigerator.
5)Creating Bot to send Alert messages on Telegram
First you need create a bot channel in Telegram that will send alerts when there is a sudden change in temperature of cooling chamber. In that case refer to your bolt Iot trainings or the following steps below:
step1: Open Telegram messaging app in our device, click the pen icon down the right corner and select New Channel.
step2: Give suitable name and description to channel.
step3: Now set the channel as public and enter a permanent link for the channel.
step4: Now in the homescreen of the app click the search icon and type " botfather ".
step5: Choose the correct bot father, it has a blue tick mark. here the highlighted one is the correct bot father.
step6: Open the chat, it will some items already, but we need a new bot. So type "/newbot". after this it will ask to type some more details like, Bot name and Bot username.
step7: After the bot is created successfully, a message will appear that will contain the Bot Token. This token is used to control the Bot as well as send messages. Please keep this token secure as it will allow anyone to access your Bot.
step8: Now open the channel that you created and click on channel info.
step9: click administrators, then click Add Admin and search the bot that you created.
step10: select the bot and check whether the bot has the rights to "post message".
- Now you have successfully created a channel that has a Bot to send alert messages.
6)Writing Python Codes in Virtual Systems
After creating Bot, We need to write python codes to detect anomalies.
First we need to create a folder/directory in the virtual system in which we are going to work. The following commands can create the same:
mkdir Anomaly_detection
cd Anomaly_detection
After this we need to create a python file named conf.py
in the Anomaly_detection directory. This file will contain required configurations for the main code to run. We can create the same with the command:
sudo nano conf.py
Inside the conf.py file we need to write:
telegram_chat_id = "@XXXXXXX" # This is the channel ID of the created Telegram channel. Paste after @ symbol.#
telegram_bot_id = "botXXXXXXX"
# This is the bot ID of the created Telegram Bot. Paste after bot text.#
API_KEY = "This is your bolt cloud account API key"
DEVICE_ID = "This the id of your Bolt device"
FRAME_SIZE = 10
MUL_FACTOR = 6
And another python file named anomaly_detection.py
in the Anomaly_detection directory. This file will contain the main code.
sudo nano anomaly_detection.py
ALGORITHM:
- Fetching current sensor value from Bolt device.
- Storing the sensor values in form of a list, for further Z-score computing.
- Computing Z-scores, High and Low bounds for normal and anomalous readings.
- Check if the sensor value is in the normal range.
- If not, send Alert message through telegram bot.
- Wait for 5 seconds.
- Again, Repeat fromstep1.
Comments
Please log in or sign up to comment.