Yash Shamnani
Published

Temperature Level Signifier

It is necessary to monitor the temperature in different ranges for the industries. Therefore this project tells the temperature range.

IntermediateProtip2 hours566
Temperature Level Signifier

Things used in this project

Hardware components

LED (generic)
LED (generic)
×4
Resistor 330 ohm
Resistor 330 ohm
×4
Breadboard (generic)
Breadboard (generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Temperature Sensor
Temperature Sensor
×1
Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1
Male/Male Jumper Wires
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Snappy Ubuntu Core
Snappy Ubuntu Core
Bolt IoT Android App
Bolt IoT Android App

Story

Read more

Schematics

LED Connection Schematic

The LEDs are connected to digital pins 1-4 and common ground. A particular LED shows a particular range of temperatures. For example, for the first range, one LED glows, for second range two LEDs glow and so on.

Code

Code for the Project in Python

Python
import email_conf, conf, math, statistics
from boltiot import Email, Bolt
import json, time

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]

minimum_limit = 10
maximum_limit = 50
mybolt = Bolt(email_conf.API_KEY, email_conf.DEVICE_ID)
mailer = Email(email_conf.MAILGUN_API_KEY, email_conf.SANDBOX_URL,
email_conf.SENDER_EMAIL, email_conf.RECIPIENT_EMAIL)

while True:
  print ("Reading sensor value")
  response = mybolt.analogRead('A0')
  data = json.loads(response)
  print ("Sensor value is: " + str(data['value']))
  
  try:
    sensor_value = int(data['value'])
    if sensor_value > limit1 and sensor_value <= limit2:
      print("Temperature is normal")
      response1 = mybolt.digitalWrite('1','HIGH')
      response2 = mybolt.digitalWrite('2','LOW')
      response3 = mybolt.digitalWrite('3','LOW')
      response4 = mybolt.digitalWrite('4','LOW')
     
    elif sensor_value > limit2 and sensor_value <= limit3:
      print("Requesting mailgun to send an email")
      mail_response = mailer.send_email("Attention", "The Current temperature          sensor value has risen to "+str(sensor_value))
      print("Mailgun response is" + response.text)
      response1 = mybolt.digitalWrite('1','HIGH')
      response2 = mybolt.digitalWrite('2','HIGH')
      response3 = mybolt.digitalWrite('3','LOW')
      response4 = mybolt.digitalWrite('4','LOW')

    elif sensor_value > limit3 and sensor_value <= limit4:
      print("Requesting mailgun to send an email")
      mail_response = mailer.send_email("Attention", "The Current temperature          sensor value has risen to "+str(sensor_value))
      print("Mailgun response is" + response.text)
      response1 = mybolt.digitalWrite('1','HIGH')
      response2 = mybolt.digitalWrite('2','HIGH')
      response3 = mybolt.digitalWrite('3','HIGH')
      response4 = mybolt.digitalWrite('4','LOW')
      
    else: 
      print("Requesting mailgun to send an email")
      mail_response = mailer.send_email("Alert", "The Current temperature sensor       value has risen to a very high value of "+str(sensor_value))
      print("Mailgun response is" + response.text)
      response1 = mybolt.digitalWrite('1','HIGH')
      response2 = mybolt.digitalWrite('2','HIGH')
      response3 = mybolt.digitalWrite('3','HIGH')
      response4 = mybolt.digitalWrite('4','HIGH')
 
  except Exception as e:
    print ("Error occured: Below are the details")
    print (e)
    
  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'])
  except e:
    print("There was an error while parsing the response: ",e)
    continue
    
  bound = compute_bounds(history_data,conf.FRAME_SIZE,conf.MUL_FACTOR)
  
  if not bound:
    required_data_count=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)
    continue
  try:
    if sensor_value > bound[0] :
      print("Requesting mailgun to send an email")
      mail_response = mailer.send_email("Alert", "The Current temperature sensor       value has suddenly risen to "+str(sensor_value))
      print("Mailgun response is" + response.text)
      response1 = mybolt.digitalWrite('1','HIGH')
      response2 = mybolt.digitalWrite('2','HIGH')
      response3 = mybolt.digitalWrite('3','HIGH')
      response4 = mybolt.digitalWrite('4','HIGH')
      
    
    elif sensor_value < bound[1]:
      print("Requesting mailgun to send an email")
      mail_response = mailer.send_email("Alert", "The Current temperature sensor       value has suddenly dropped to "+str(sensor_value))
      print("Mailgun response is" + response.text)
      response1 = mybolt.digitalWrite('1','LOW')
      response2 = mybolt.digitalWrite('2','LOW')
      response3 = mybolt.digitalWrite('3','LOW')
      response4 = mybolt.digitalWrite('4','LOW')
      

  except Exception as e:
    print ("Error",e)
    
  time.sleep(10)

Credits

Yash Shamnani
1 project • 0 followers

Comments