Naveen
Published

Capstone4.0

This project can be used to send an alert when the temperature crosses the threshold and also does a z-score analysis to find any anomaly.

IntermediateWork in progress8 hours722
Capstone4.0

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Temperature Sensor
Temperature Sensor
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×1

Software apps and online services

Bolt IoT Android App
Bolt IoT Android App
Bolt Cloud
Bolt IoT Bolt Cloud
SMS Messaging API
Twilio SMS Messaging API
MailGun

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires

Story

Read more

Custom parts and enclosures

Circuit Diagram

This circuit is show how Lm35 interface with Bolt wifi module .The circuit makes with the help of fritzing simulator software.

Circuit

Connection on cloud

Schematics

Circuit Diagram of Lm35

This Circuit diagram shows how an LM35 convert change in temperature to change in Voltage. Temperature is directly proportional to Voltage.

Lm35 sensor

Pin digram

Lm35 working

Practical circuit

Working and practical circuit

Code

Python code

Python
The Main Code
This is the main working code. Inside the code, there is an import of conf.py which is the file that contains all the confidential credentials and is not to be shared. Kindly make that file on your own.
from boltiot import Bolt, Sms, Email
import json
import conf
import statistics
import math
import time


def get_bound(history_dat, frame_size, mul_factor):
    if len(history_dat) < frame_size:
        return None
    if len(history_dat) > frame_size:
        del history_data[0:len(history_data)-frame_size]

    mean__ = statistics.mean(history_dat)

    variance_ = 0
    for data1 in history_data:
        variance_ += math.pow((data1-mean__), 2)

    z_score = mul_factor*(math.sqrt(variance_/frame_size))

    up_lim = history_dat[frame_size-1] + z_score
    low_lim = history_dat[frame_size-1] - z_score

    return [up_lim, low_lim]


my_bolt = 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)
history_data = []
while True:
    response = my_bolt.analogRead("A0")
    data = json.loads(response)
    sensor_value = 0
    try:
        sensor_reading = float(data["value"])
        if data["success"] != 1:
            print("Request not successful")
            print("This is the response:   ", data)
        sensor_value = sensor_reading/10.24
        print("The Current Temperature is {}".format(sensor_value))

    except Exception as err:
        print("Something went wrong while returning the sensor value")
        print(err)

    bounds = get_bound(history_data, conf.FRAME_SIZE, conf.MUL_FACTOR)

    try:
        if not bounds:
            req_data_count = conf.FRAME_SIZE - len(history_data)
            print("Not enough data to compute Z-score Analysis. Need {} more data points".format(req_data_count))
            history_data.append(sensor_value)
            time.sleep(10)
            continue

        if sensor_value > bounds[0]:
            print("The temperature has increased suddenly. Requesting Twillio to Send an SMS")
            response1 = sms.send_sms("Temperature has suddenly increased to {}.\n Someone has opened the fridge door".
                                     format(sensor_value))
            response_text1 = json.loads(response1.text)
            print("Response Received from Twillio: ", str(response_text1["message"]))
            print("Making request to Mailgun to send an email")
            response2 = mailer.send_email("Alert", "The Current temperature sensor value is {}. Someone has opened the "
                                                   "fridge door".format(sensor_value))
            response_text2 = json.loads(response2.text)
            print("Response received from Mailgun is: " + str(response_text2['temperature']))
        elif sensor_value < bounds[1]:
            print("The temperature has decreased suddenly. Requesting Twillio to Send an SMS")
            response1 = sms.send_sms("Temperature has suddenly dropped to {}. \n Someone has changed the configuration"
                                     .format(sensor_value))
            response_text1 = json.loads(response1.text)
            print("Response Received from Twillio: ", str(response_text1["message"]))
            print("Making request to Mailgun to send an email")
            response2 = mailer.send_email("Alert", "The Current temperature sensor value is {}. Someone has changed the"
                                                   "configuration".format(sensor_value))
            response_text = json.loads(response2.text)
            print("Response received from Mailgun is: " + str(response_text['message']))
        history_data.append(sensor_value)
    except Exception as error_msg:
        print("Error: ", error_msg)

    time.sleep(10)

Graph code

Java
Graph plotting using google chart library
setChartLibrary('google-chart');
setChartTitle('Your Graph Title');
setChartType('areaGraph');
setAxisName('X-Axis Name','Y-axis Name');
plotChart('time_stamp','temperaturet_');

Credits

Naveen

Naveen

2 projects • 1 follower
An Engineering professional pursuing a Bachelor's degree in Electronic and Communivation Engineering.Always happy to learn new things.

Comments