Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Balkrishna Raut Dessai
Published

Engine Failure Detection and Alert system

An IoT based system that will send a SMS and buzzer alert upon temperature increase in the engine.

IntermediateFull instructions provided320
Engine Failure Detection and Alert system

Things used in this project

Hardware components

Buzzer
Buzzer
×1
Resistor 330 ohm
Resistor 330 ohm
×2
5 mm LED: Green
5 mm LED: Green
×1
5 mm LED: Red
5 mm LED: Red
×1
Temperature Sensor
Temperature Sensor
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1

Software apps and online services

SMS Messaging API
Twilio SMS Messaging API
Snappy Ubuntu Core
Snappy Ubuntu Core
Bolt Cloud
Bolt IoT Bolt Cloud

Story

Read more

Schematics

CIRCUIT SCHEMATIC

Make the connections as per the schematic

Code

conf.py

Python
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"

alarm.py

Python
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()

Credits

Balkrishna Raut Dessai
1 project • 0 followers

Comments