Mayank Mohan
Published

Automate Light using LDR, BOLT Cloud & IFTTT

An Automated Light System created on BOLT IoT Platform. The Intensity of light can be controlled using the LDR sensor or By using IFTTT

IntermediateFull instructions provided1 hour637
Automate Light using LDR, BOLT Cloud & IFTTT

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 330 ohm
Resistor 330 ohm
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1

Software apps and online services

Snappy Ubuntu Core
Snappy Ubuntu Core
Bolt Cloud
Bolt IoT Bolt Cloud
Maker service
IFTTT Maker service
Assistant SDK
Google Assistant SDK

Story

Read more

Schematics

Schematic Diagram of Automated LED

Code

Schematic Diagram of Automated LED

Python
"""impoting libraries
    Bolt for connecting to our bolt module using api_key and device_id
    json to convert data from sensor into json format [key:value]
    time to read value after equal interval of time
"""
from boltiot import Bolt
import json, time 

api_key = "9de89bb2-5ef4-47b3-9aea-757b64898d85"
device_id = "BOLT3849213"

mybolt = Bolt(api_key, device_id)

"""creating a function to set the value of LED automatically(0-255)
"""

def set_intensity(pin, value):
	mybolt.analogWrite(pin, value)

"""create a function to calculate Required LED Intensity
   corresponding to the LDR sensor value
   subtract from 255? - if LDR value=1024(sufficient light)-led will be off(0)
                        if LDR value=0(no light)-led will be on(255)
   intermediate value of LDR will corresponds to a specific LED intensity value(0-255)
   """

def converter(sensor_value):
	led_intensity= 255-(sensor_value*255/1024)
	return led_intensity


while True: 
    print ("Reading Sensor Value")
    response_ldr = mybolt.analogRead('A0') # Read the LDR Sensor Value from A0 Pin
    data = json.loads(response_ldr)   # Convert value in Json format 
    print("Sensor value is: " + str(data['value'])) # Print the value
    try: 
        sensor_value = int(data['value'])
        print("Calculating required Light Intensity for LED")
        led_value_float=converter(sensor_value)  # convert ldr sensor value in required
        led_value= int(led_value_float)          # led value in float and then typecast 
        print(led_value)                         # float into int type
        set_intensity('1',led_value)             # this will make LED to glow
                                                 # with calculated intensity value

# in case of any error encountered        
    except Exception as e: 
        print ("Error occured: Below are the details")
        print (e)
    time.sleep(10)

Credits

Mayank Mohan
2 projects • 2 followers
Contact

Comments

Please log in or sign up to comment.