Sejal
Published © GPL3+

Bolt Light Magic

Automatic Light control with SMS alerts.

BeginnerFull instructions provided1 hour51
Bolt Light Magic

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
LED (generic)
LED (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 330 ohm
Resistor 330 ohm
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
SMS Messaging API
Twilio SMS Messaging API
Snappy Ubuntu Core
Snappy Ubuntu Core

Story

Read more

Schematics

Connections of the System

Code

main.py

Python
The main functionality to detect LDR reading and give output by LED and Twilio update.
import conf
from boltiot import Sms, Bolt
import json, time

maximum_limit = 800
minimum_limit = 500

mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)


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 > maximum_limit:
            print("Making request to Twilio to send a SMS")
            response = sms.send_sms("ALERT:Light(LED) DOWN,The current brightness value is " +str(sensor_value))
            print("Response received from Twilio is: " + str(response))
            print("Status of SMS at Twilio is :" + str(response.status))
            response = mybolt.digitalWrite('0','LOW')
        elif sensor_value < minimum_limit:
            print("Making request to Twilio to send a SMS")
            response = sms.send_sms("ALERT:Light(LED) UP,The current brightness value is " +str(sensor_value))
            print("Response received from Twilio is: " + str(response))
            print("Status of SMS at Twilio is :" + str(response.status))
            response = mybolt.digitalWrite('0','HIGH')
          else:
            print("Cannot predict")
    except Exception as e: 
        print ("Error occured: Below are the details")
        print (e)
    time.sleep(10)

conf.py

Python
Configuration details for security
API_KEY = 'API from your Bolt Cloud API section'
DEVICE_ID = 'BOLTxxxx from Bolt Cloud dashboard'
SID = 'Account SID from Twilio dashboard of your project'
AUTH_TOKEN = 'Authentication token from Twilio dashboard of your project'
FROM_NUMBER = 'The generated Twilio number from Programmable SMS/Learn and build section'
TO_NUMBER = 'The number to receive updates in the form of SMS'

Credits

Sejal

Sejal

1 project • 0 followers

Comments