TCHAMIE B.A. Edmund
Published © GPL3+

Temperature & Anomalie Detection Using LM35 and Bolt IoT

Temperature monitoring system and anomalie Detection using an LM35 + Bolt IoT to keep the tablet in the case of the pharmaceutical companie.

AdvancedFull instructions provided3 hours1,028
Temperature & Anomalie Detection Using LM35 and Bolt IoT

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
This one of awesome Wifi Module.
×1
Temperature Sensor
Temperature Sensor
Most of temperature Sensor are available but LM35 is good and easy to use for this project.
×1
Jumper wires (generic)
Jumper wires (generic)
As his name indicate ,help you to make connection between your LM35 and you bolt module.
×1
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
AH, yeah!! everybody knows his utility as everyone have an android phone.
×1

Software apps and online services

SMS Messaging API
Twilio SMS Messaging API
This app just sends an sms or other messagering through a code running in a server.
@Mailgun
His also have the same fonctionality as *Twilio app but here it's for an email sending in the case of this project.
Bolt Cloud
Bolt IoT Bolt Cloud
Free to get an account check now.!
Bolt IoT Android App
Bolt IoT Android App
This app enable you to connect your wifi module to bolt cloud
Oracle VM (virtual box manager)
VirtualBox is powerful Cross-platform Virtualization Software for x86-based systems.

Hand tools and fabrication machines

android phone
Refrigerator
As you donc have a cooling chamber which exist in pharmaceutical companie then we have used an refrigerator to do the experience in it.
Personal computer
haha !!! you will be surprise but you need a PC in which we would all the work.

Story

Read more

Schematics

Hardwares used in the project

Bolt Iot Module
LM35 Temperature sensor
Connection Jumpers wire (male/female)
USB cable

Conection of devices

In this position, identify the pins of the sensor as
VCC indicates by blue wire
Output indicates by red bordaux wire
and Gnd indicates by ash wire
from your left to right.

connecting the LM35 to the bolt module

1. VCC pin of the LM35 connects to 5v of the Bolt Wifi module.
2. Output pin of the LM35 connects to A0 (Analog input pin) of the Bolt Wifi module.
3.Gnd pin of the LM35 connects to the Gnd.

Powering on and connecting to WIfi of the device

I) Just connect all components by a USB cable to a PC or Power Bank;==> That is indicate by a blue LEDs.
II) Finally connect its to internet through a WIFI (uses a phone to share the internet ) ==> That is indicate by a green LEDs.

Code

Temperature_prediction graph

JavaScript
Here is the code to view the temperature prediction in a graph
#Set the chart library used to visualize the data
setChartLibrary('google-chart');

#Set the title of the graph according to your choice
setChartTitle('Polynomial Regression');

#Set the type of chart to be plotted
setChartType('predictionGraph');

#Set the display name for each of the graph axis
setAxisName('time_stamp','temp');

#The mul function is present to multiply a every value retrieved from the Bolt WiFi module
mul(0.0977);

#Display the graph on the screen for the given variables
plotChart('time_stamp','temp');

Temp_Anomalie_ detecion.py

Python
Here is the all code to define the threshold limit of temperature and perform the Z-score analyse with an alert when something happen .
   """Code for Capstone project"""
   
import email_conf, sms_conf, json, time, math, statistics
from boltiot import Email, Bolt, Sms

#Function to set upper and lower bound by Z-score analysis
def compute_bounds(history_data,frame_size,factor):
    if len(history_data)<frame_size :
        return None
    if len(history_data)>frame_size :
        del history_data[0:len(history_data)-frame_size]
    Mn=statistics.mean(history_data)
    Variance=0
    for data in history_data :
        Variance += math.pow((data-Mn),2)
    Zn = factor * math.sqrt(Variance / frame_size)
    High_bound = history_data[frame_size-1]+Zn
    Low_Bound = history_data[frame_size-1]-Zn
    return [High_bound,Low_Bound]
    
critical_limit = 8 #the critical_value of temperature
maximum_limit = 10 #the maximum_value of temperature

# Configuring bolt device
mybolt = Bolt(email_conf.API_KEY, email_conf.DEVICE_ID)
# Configuring email alert requirement
mailer = Email(email_conf.MAILGUN_API_KEY, email_conf.SANDBOXURL, email_conf.SENDER_EMAIL, email_conf.RECIPIENT_EMAIL)
# Configuring sms alert requirement
sms = Sms(sms_conf.SSID, sms_conf.AUTH_TOKEN, sms_conf.TO_NUMBER, sms_conf.FROM_NUMBER)
# setting up empty list to save the temperature sensor readings
history_data=[]
  
  
while True:
    
    # saves bolt module response in a variable
    response = mybolt.analogRead('A0')
    
    # saves the response data in a variable
    data = json.loads(response)
    
    if data['success'] != '1':
        
        # display an error when the response in data equals to '0'
        print("There was an error while retriving the data.")
        print("This is the error:"+data['value'])
        time.sleep(10)
        continue
    
    #display the value of data while the error occured  
    print ("The is the value"+data['value'])
    
    # initialization of sensor_value to 0
    sensor_value=0
    try:
       # saves current sensor value in variable
        sensor_value = int(data['value'])
    except e:
        print("There was an error while parsing the response: ",e)
        continue
      
     # saving the upper and lower bounds by Z-score analysis in a variable named bound  
    bound = compute_bounds(history_data,email_conf.FRAME_SIZE,email_conf.MUL_FACTOR)
    
    # checks if bound is empty or not
    # if it is empty, then it will save the current sensor value in the history_data list otherwise, will directly go to try.
    if not bound:
        required_data_count=email_conf.FRAME_SIZE-len(history_data)
        print("Not enough data to compute Z-score. Need ",required_data_count," more data points")
        history_data.append(int(data['value']))
        time.sleep(10)
        
    try:
      #convert the temperature to display in degree celsus
        temp = sensor_value/10.24
        
        # condition for when the temperature crosses the maximum_limit
        if temp > maximum_limit:
            print ("The Temperature value increased suddenly. Sending an sms.")
            # display the temeprature value in degree celsus
            print ("The Current temperature is: "+str(temp)+" °C")
            response = sms.send_sms("Alert ! Someone has opened the fridge door")
            print("This is the response ",response)
            
        # condition for the temperature value is between  the critical_limit and the maximum_limit     
        elif temp > critical_limit or temp < maximum_limit:
            print("Urgent! Temperature condition can destroy the tablets. Sending an email.")
            #display the temperature value in degree celsus
            print (" The Current temperature is:" +str(temp)+ "°C")
            response = mailer.send_email("Alert !","The level temperature can destroy the tablets.")
            print("This is the response",response)
        history_data.append(sensor_value)
    
    # in case of any error    
    except Exception as e:
           print ("Error",e)
    time.sleep(10)

sms_conf.py

Python
This is the code file for sms configuration . Here are all the credentials about the sms sending .
''''YOU have to enter here your propely credentials about Twilio''''

# You can find SSID in your Twilio Dashboard
SSID = 'AC97511aba573580dea93b6d667017fd9d'

#You can find  on your Twilio Dashboard
AUTH_TOKEN = '7eeb796f09df1d059d4af3caa02d6b8b'

#This is the no. generated by Twilio. You can find this on your Twilio Dashboard
FROM_NUMBER = '+18173396173'

#This is your number. Make sure you are adding +91 in beginning
TO_NUMBER = '+918580812249'

#This is your Bolt Cloud account API key
API_KEY = 'eed9c637-cf6c-4cad-849b-c46282df4946'

#This is the ID of your Bolt device
DEVICE_ID = 'BOLT11692220'

FRAME_SIZE = 10

MUL_FACTOR = 6

email_conf.py

Python
This is the code file for email configuration . Here are all the credentials about the email sending
"""api keys and emails for sending the alert email"""

#private API key for Mailgun
MAILGUN_API_KEY = '0b1f04eee42d099d8e100a70862f10ac-9ce9335e-81d62f38'

#sandbox url for mailgun
SANDBOX_URL= 'sandbox879cd1469fc946e4a09c4d57fe23ac6d.mailgun.org'

#postmaster@sandbox_url
SENDER_EMAIL = 'test@sandbox879cd1469fc946e4a09c4d57fe23ac6d.mailgun.org'

#receiver email id
RECIPIENT_EMAIL = 'cartersedmund@gmail.com'

#Bolt Cloud accout API key
API_KEY = 'eed9c637-cf6c-4cad-849b-c46282df4946'

#Bolt device id
DEVICE_ID = 'BOLT11692220' 

FRAME_SIZE = 10

MUL_FACTOR = 6

Credits

TCHAMIE B.A. Edmund
1 project • 1 follower
Contact

Comments

Please log in or sign up to comment.