Sandhya Mohan
Published

Light Monitoring System with Message Alert using Bolt IOT

This project monitors the light of the room continuously and informs the user whenever the light is turned on or turned off with SMS.

IntermediateFull instructions provided5 hours1,001
Light Monitoring System with Message Alert using Bolt IOT

Things used in this project

Hardware components

LDR, 5 Mohm
LDR, 5 Mohm
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
SMS Messaging API
Twilio SMS Messaging API

Story

Read more

Schematics

Connection of system

Code

confy.py

Python
This contains all the configurations such as API key, SSID, Twilio details that are required for this project.
SSID = 'Your_Twilio_SID' 
AUTH_TOKEN = 'You_Can_Find_in_your_twilio_control_panel' 
FROM_NUMBER = 'YOUR_TWILIO_NUMBER'
TO_NUMBER = '+91YOUR_PHONE_NUMBER'
API_KEY = 'BOLT_API_KEY'
DEVICE_ID = 'BOLT_DEVICE_ID'
FRAME_SIZE = 3
MUL_FACTOR = 10

Light Montoring

Python
This shows how the light monitoring system is programmed.
import confy, json, time, math, statistics
from boltiot import Sms, Bolt
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]

mybolt = Bolt(confy.API_KEY, confy.DEVICE_ID)
sms = Sms(confy.SSID, confy.AUTH_TOKEN, confy.TO_NUMBER, confy.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'])
    except e:
        print("There was an error while parsing the response: ",e)
        continue

    bound = compute_bounds(history_data,confy.FRAME_SIZE,confy.MUL_FACTOR)
    if not bound:
        required_data_count=confy.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 ("The light level increased suddenly. Sending an SMS.")
            response = sms.send_sms("Someone turned on the lights")
            print("This is the response ",response)
        elif sensor_value < bound[1]:
            print ("The light level decreased suddenly. Sending an SMS.")
            response = sms.send_sms("Someone turned off the lights")
            print("This is the response ",response)
        history_data.append(sensor_value);
    except Exception as e:
        print ("Error",e)
    time.sleep(10)

Credits

Sandhya Mohan
1 project • 0 followers

Comments