The IoT is a pretty simple concept, it means taking all the things in the world and connecting them to the internet.
So the idea behind my project is to determine whether the anomaly was due to human error or due to any intruder trying to access it. I have created a temperature tracking system for the refrigerator along with the stage-wise anomaly detection.
In stage 1 if the door of the refrigerator is not closed properly or it is left open then the buzzer will ring at low frequency and we will be alerted via Mail saying that the Door is open, close it. In stage 2 if the door is opened by an intruder than the buzzer will ring at high frequency for a longer period of time and we will be alerted via SMS that someone has opened the door also the time is displayed when the anomaly was detected.
Real-life implementation can be seen in the pharmacy sector or any sector involving COLD storage.Steps for Building This Project
➤ Hardware SectionStep 1. Hardware Components
We need the following components to build the whole project:
i.Bolt WiFi module
ii. LM35 Temperature sensor
v. USB cable
vi. Power Source
First, we will identify the pins of LM35 with the help of the image provided below.
Now we will make our circuit.
1 ) We will take Gnd from the bolt module and place it in the breadboard as shown in the circuit. Now we will connect the negative (i.e shorter leg ) of buzzer with the Gnd taken from the bolt module while the positive ( i.e longer leg ) will be connected to the pin 0 of the bolt module.
2) Now we will connect the middle leg (i.e Output ) of the LM35 sensor with the A0 of the bolt module and the VCC of the LM35 with the 5V of the Bolt Module.
The final circuit looks like this.
➤ SoftwareSection1 ) Digital Ocean
- Creating an account on DigitalOcean
First we need to create a digital ocean account. You need to click the following link to create account https://www.digitalocean.com/ Type your email id and password for Signing up and you will receive an account verification email.
- Choosing the droplet
In this step, we will choose the appropriate image. First, click on the Create button and choose Droplet from the drop-down menu and the 'Create droplet' screen will appear.
- Choosing a Size
In this step we will choose the size of the droplet i.e. the amount of RAM and storage space it should have.
- Choosing a Datacenter Region
Datacenter region is the place where our droplet will be deployed. I am from India, so I kept Banglore as the default datacenter region. Once you have selected your options, click Create. A progress bar displays how close your Droplet is to be ready.
Step 1: Open https://www.twilio.com/ in the browser.
Step 2: Click on the GET API Key button to sign up.
Step 3: Fill all the necessary details in the SIGN-UP form.
Step 4: Verify they will ask for your phone number.
Step 5: Click on "Products".
Step 6: Now enable the SMS services by clicking on two checkboxes for Programmable SMS and Phone Numbers.
Step 7: Now, you will need to give a name for your project.
Step 8: Click on "Project Info" to view the account credentials which are required for your projects.
Step 9: You can view the Account SID and Auth Token on this page.
Step 10: From the drop-down menu, choose "Programmable SMS". Now click on the Get Started button to generate phone number.
Step 11: Click on Get a number button.
Step 12: Click on Choose this number button.
Step 13: Then a popup will appear which will have the final number. Copy this number and save it to notepad for future references.That's it. You have successfully created the account on Twilio.
Step 1: Open https://www.mailgun.com/ in browser.
Step 2: Click on
Step 3: Fill up the SIGN UP form.
Step 4: You will get a verification mail having a link.
Step 5: Verify they will ask for a phone number.
Step 6: After verification, Click on
Add Recipient button.
Step 7: Click on
Invite New Recipient button.
Step 8: Enter your Email ID.
Step 9: After adding an email ID a new sandbox will be generated. Click on the ID of the newly generated sandbox.
Step 10: All the necessary credentials are displayed here.
Step 1: Connect the temperature monitoring circuit as we have done above.
Step 2: Login into the server by entering the IP address of your digital ocean droplet.
Step 3: Now we will make a conf file with all the configuration details as below.
SID = 'You can find SID in your Twilio Dashboard'
AUTH_TOKEN = 'You can find on your Twilio Dashboard'
MAILGUN_API_KEY = 'This is the private API key which you can find on your Mailgun Dashboard'
SANDBOX_URL= 'You can find this on your Mailgun Dashboard'
SENDER_EMAIL = 'This would be test@your SANDBOX_URL'
RECIPIENT_EMAIL = 'Enter your Email ID Here'
FROM_NUMBER = 'This is the no. generated by Twilio. You can find this on your Twilio Dashboard'
TO_NUMBER = 'This is your number. Make sure you are adding +91 in beginning'
API_KEY = 'This is your Bolt Cloud accout API key'
DEVICE_ID = 'This is the ID of your Bolt device'
Step 4: Now we will make the main file to execute our code, let's name it as lm_sms. You can set any other desired name of yours.
from boltiot import Sms, Bolt, Email
import json, time
from datetime import datetime
L = 
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
mailer = Email(conf.MAILGUN_API_KEY, conf.SANDBOX_URL, conf.SENDER_EMAIL, conf.RECIPIENT_EMAIL)
return sum(L) / len(L)
output = mybolt.analogWrite('0','100');
output = mybolt.analogWrite('0','255');
output = mybolt.digitalWrite("0","LOW")
response = mybolt.analogRead('A0')
data = json.loads(response)
sensor_value = int(data['value'])
T = sensor_value/10.24
print("The Tempreture inside is : " ,T)
average = Average(L)
if( len(L) >= 2 ):
if( (T > (average + 0.20)) and (T < (average + 0.30)) ):
print("STAGE 01 ANOMALY : " , T)
print("Making request to Mailgun to send email")
response = mailer.send_email("Alert", "Looks like door of Refrigerator is open Please close the door" + str(T) )
response_text = json.loads(response.text)
print("Response received from MAILGUN is : " + str(response_text['message']))
tz_IN = pytz.timezone('Asia/Kolkata')
datetime_IN = datetime.now(tz_IN)
print("Door is Open since :", datetime_IN.strftime("%H:%M:%S"))
elif( (T > (average + 0.30 )) ):
print("STAGE 02 ANOMALY : " , T)
print("Making request to Twilio to send SMS")
response = sms.send_sms("Someone Has Opened the Door: " +str(T))
print("Response received from Twilio : " +str(response))
print("Status of SMS at Twilio : " +str(response.status))
tz_IN = pytz.timezone('Asia/Kolkata')
datetime_IN = datetime.now(tz_IN)
print("Someone Opened the door at : " , datetime_IN.strftime("%H:%M:%S"))
except Exception as e:
NOTE: Here the values used for the threshold ( Fluctuations ) have been calculated separately by taking the difference between the average of all data points and the rise of temperature when the door is opened for 90 Readings.
Step 5: Now we will run the lm_sms.py file.
⮞ STAGE 1 IMPLEMENTATION
As we can see that the stage 1 anomaly was detected and we were alerted via mail.
⮞ STAGE 2 IMPLEMENTATION
As we can see that the stage 2 anomaly was detected and we were alerted via SMS also the time of the anomaly is displayed.
⮞ Working of the Project
Here is the working video of Stage Wise Temperature Intrusion Detection System.