We know that a lot of engine failures occur due to temperature rise within it. This accounts to huge amounts of loss in terms of property and finances. Engines, machines are used everywhere from vehicles to industries, from hospitals to offices, etc. Hence it becomes crucial to develop a solution to this problem and save a lot. Engine failures can also lead to fire.
A better solution would be to monitor the temperature of the engine continuously and perform a Z score analysis to detect anomalies. We’ll be doing this by using a LM35 temperature sensor with Bolt IoT module connected to analog pin to monitor the temperature. With Z-score analysis, we’ll be able to detect sudden rise in temperature of the system and send an alert to the user via SMS through Twilio api.
2)Proceeding with the project:Before we proceed, lets look at the quick set up of BOLT wifi module.
If you'll have already done this part then you'll can skip to the circuit connections module.I have taken this writeup with reference from the BOLT IOT trainings platform so yes credits to them.
Process of Setup, Power ON and Link with Bolt Cloud:
Connect the USB cable to the BOLT module and it should show power LED on. Follow the steps as told:
1: Download the Bolt Iot app on your android or IOS device.
2: Create a new account on the Bolt Cloud through the Bolt Iot app. Next you'll receive a mail, complete the steps given in the mail to activate the Cloud account. Next you'll get this screen on your device that tells about the configured devices.
3: Now by clicking on 'ADD DEVICE' setup your bolt device with your Wi-Fi network. Next power ON your Bolt device module by connecting with the USB cable provided in your BOLT IOT kit.
4: Now turn OFF the mobile data and switch ON the mobile location and click on the "READY" button.. Then we are almost done. You can now see your device connected and its ID is shown.
Click on contiune and we are done.Now, we our Bolt device is connected to our Wi-Fi network succesfully.
Make sure your Wifi network is using 2.4GHz band since BOLT is not compatible with 5Hz Wifi network.
LEDs on BOLT module and what their colours indicate:
Blue LED blinking slowly:The bolt's Wi-Fi network has been powered ON and it is ready to be linked via the Bolt app.
Blue LED blinking fast: The bolt is trying to connect to the Wi-Fi network.
Blue LED ON: Finally, the bolt is connected to the Wi-Fi network.
The Blue LED on my Bolt is not blinking:You need to power on your Bolt device. Use a 5V Micro USB Power Adaptor connected to a power supply mains to power on the Bolt.
The Blue LED is blinking but it's not stable: You need to connect your Bolt to your WiFi network. Download the Bolt IoT App in your Android phone and follow the onscreen instruction to connect your Bolt to your home WiFi network.
Green LED ON means The bolt is connected with the bolt Cloud.
Blue LED is stable but Green LED is not On.: It means you Bolt is connected to your WiFi network but not getting the internet access. Enable the internet access from your wifi network.
[a] MAKING CIRCUIT CONNECTONS
Connections for LM35 temperature are as follows:The LM35 sensor has 3 pins namely VCC(+5V), output and ground{ as shown in the pin diagram image below}. Connect the output pin to the analog pin (A0) of the Bolt module.
LED has 2 terminals where the longer terminal indicates positive terminal and shorter one is the negative. Green LED is used to indicate that the device is ON and its positive terminal is connected to GPIO pin 1 of the Bolt module.
The buzzer also has 2 terminals with the longer one being the positive terminal. Red LED’s positive terminal alongwith the positive of the buzzer goes to the GPIO pin 0 of the module.
The 330 ohms resistors are connected in series with the LEDs.
Given below is the pinouts of individual components and full circuit diagram for circuit connections.
[b] Setting up the Twilio API
Twilio is a third-party SMS functionality provider. It is a cloud communications platform as a service (PaaS) company. Twilio allows software developers to programmatically make and receive phone calls and also send and receive text messages using its web service APIs.
- Go to twilio.com and create a free trial account.(If you already have an account you can use the same)
- Upon verifying your email id and your phone number, you’ll have ACCOUNT SID and AUTH TOKEN. This will be used in the conf.py file while coding.
- Go to the dashboard and click Get a Trial number.
- Then you’ll be assigned a number by Twilio which will be used to send the SMS.
- Save this number in notepad as this will be used again in the conf.py file.
[c]SETTING UP YOUR SERVER AND CODING :
We'll be using VMware Ubuntu device on our PC(Windows). You can Download the Virtual Box and Ubuntu Server.
To set up the server, follow the steps as shown in below video:
Coding part will be exclusively done using Python language. It will be done in an Ubuntu server.(any other server may be used but here I have used UBUNTU).Before starting with the code, make sure you install the Bolt IoT library.
This can be done in 3 steps:
Step 1: Update the packages on Ubuntu
sudo apt-get -y update
Step 2: Install python3 pip3
sudo apt install python3-pip
Step 3: Installing boltiot library using pip
sudo pip3 install boltiot
Codes for the program involves 2 parts: conf.py and alarm.py
Configuration File (conf.py)
API_KEY = "YOUR_API_KEY"
DEVICE_ID = "BOLTXXXXXXX"
SID = "FOUND_IN_TWILIO_ACCOUNT"
AUTH_TOKEN = "FOUND_IN_TWILIO_ACCOUNT"
FROM_NUM = "FOUND_IN_TWILIO_ACCOUNT"
TO_NUM = "YOUR_NUMBER"
Enter the fields in the code as per your Bolt device and Twilio account.
The API KEY is found in your Bolt Cloud under the API section.
The device id is found in the devices section in the bolt cloud. The SID and the AUTH_TOKEN are found in the twilio dashboard. The FROM_NO is the twilio trial number found in the dashboard and the TO_NUM is your number to which sms will be sent.The device id is found in the devices section in the bolt cloud. The SID and the AUTH_TOKEN are found in the twilio dashboard. The FROM_NO is the twilio trial number found in the dashboard and the TO_NUM is your number to which sms will be sent.
Attached below are the screenshots for the same for your reference.
-----------------------------------------------------------------------------------------------------------------------
MAIN SOURCE CODE (alarm.py)
from boltiot import Bolt , Sms
import time , conf , json , sys , statistics
r = 5
c = 5
data_set = []
alarm_state = 0
mybolt = Bolt(conf.API_KEY,conf.DEVICE_ID)
sms = Sms(conf.SID,conf.AUTH_TOKEN,conf.TO_NUM,conf.FROM_NUM)
def check_device():
data = json.loads(mybolt.isOnline())
if data["value"]=="online":
print('Device online')
mybolt.digitalWrite("1","HIGH")
else:
print('Device offline.')
sys.exit()
def get_temp():
data = json.loads(mybolt.analogRead("A0"))
if data["success"]==1:
val =float(data["value"])
temp = 100 * val / 1024
return temp
else:
return -999
def set_limits(data_set,r,c):
if len(data_set)<r:
return None
if len(data_set)>r:
data_set=data_set[len(data_set)-r:]
Mn = statistics.mean(data_set)
Variance = 0
for data in data_set:
Variance += (data - Mn) ** 2
Zn = c * ((Variance / r) ** 0.5)
H = data_set[r-1] + Zn
return H
def run_alarm(val):
print('Risk of a possible firm.Raising alarm.')
sms.send_sms('Sudden raise in temperature.Can be possibly a fire.The temperature is '+str(val))
mybolt.digitalWrite('0','HIGH')
global alarm_state
alarm_state = 1
def stop_alarm(val):
mybolt.digitalWrite('0','LOW')
check_device()
while 1:
try:
temp = get_temp()
print('The temperature is ',temp)
limit=set_limits(data_set,r,c)
if not limit:
print('Need more values to conduct Z-score analysis.')
data_set.append(temp)
else:
if temp > limit:
run_alarm(temp)
else:
if alarm_state:
stop_alarm(temp)
alarm_state = 0
data_set.append(temp)
time.sleep(10)
except KeyboardInterrupt:
print('Device Stopped.')
mybolt.digitalWrite('1','LOW')
mybolt.digitalWrite('0','LOW')
sys.exit()
The above main code does all the execution part of checking the temperature and comparing it so as to send an alert before any fire accident occurs.
Since we are doing Z-score analysis, we have used variables r and c.
Above, the variable r refers to the data frame and c refers to the multiplication factor required for calculating the Z-score.For accurate results, the value must be adjusted based on the surroundings.
check_device() function checks whether the device is connected to the bolt cloud. The get_temp() function returns the temperature of the surroundings. The sensor value read from the sensor is not in degree celcius. It is converted into the corresponding temperature using the formula temp = (val* 100)/1024.
Z-score is calculated by the set_limits(data_set, r, c) function. When an anomaly(sudden temperature change in this case) is detected, an sms will be sent using the send_sms function which is called in the run_alarm() function defined in the BoltIot library. Consequently bolt api requests will be sent and the warning led and buzzer are set off.
The temperature is checked once in every 10 seconds using an infinite while loop.
NOTE: Ctrl + C can be used to exit the loop and stop the execution.
3)Working video and pictures:PROJECT DEMO:
Comments