Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
Software apps and online services | ||||||
| ||||||
|
In this video I have shown the demo of my project with a buzzer sound... soon after the fridge is opened the user is alerted with a buzzer sound... in my code mentioned in this site along with this project I have also added code about how to generate a message to users phone, if the fridge is opened.
code_fridge_open_alert
PythonThis code is Written to get the sensor values and check if the temperature is increased or not... if the temperature is increased then it indicates that the fridge is open and gives a buzzer sound... also alerts the user with a message
import conf, json, time
from boltiot import Sms, Bolt
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
history_data=[]
while True:
response = mybolt.analogRead('A0')
data = json.loads(response)
if data['success'] != 1:
print("There was an error while retriving the data.")
print("This is the error:"+data['value'])
time.sleep(10)
continue
print ("This is the value "+data['value'])
sensor_value=0
try:
sensor_value = int(data['value'])
history_data.append(sensor_value)
except e:
print("There was an error while parsing the response: ",e)
continue
print(history_data)
if(len(history_data)<=7):
print("require some more values to process")
time.sleep(10)
continue
else:
if(history_data[-1]>history_data[-2]):
if(history_data[-1]>100):
print("somebody opened the fridge.... sending alert")
mybolt.digitalWrite(0, 'HIGH')
print("Making request to Twilio to send a SMS")
response = sms.send_sms("somebody ope ned the fridge door...")
print("Response received from Twilio is: " + str(response))
time.sleep(5)
mybolt.digitalWrite(0, 'LOW')
time.sleep(20)
else:
time.sleep(5)
continue
time.sleep(10)
API_KEY='your bolt API key'
DEVICE_ID = 'your Bolt device id'
FRAME_SIZE = 10
MUL_FACTOR = 3
SSID = 'Your Twillo SSID'
AUTH_TOKEN = 'TWillo authorized token.. THis token is present in your Twillo Dashboard'
FROM_NUMBER = 'this can be got from your Twillo page'
TO_NUMBER = 'This is the to_number to which you can send message..... You need to verify this number(This can be done with your Twillo page)'
Comments