Published

Street Light automation using LDR

BoltIot project which saves electricity by starting and switching off the street light according to the intensity of light falling on ldr.

IntermediateFull instructions provided1 hour332
Street Light automation using LDR

Things used in this project

Hardware components

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

Story

Read more

Schematics

Basic image

Basic image

Basic image

working video

whole project in video!!!

Code

ldr code

Python
It is self explanatory!
#importing all required modules
from boltiot import Bolt
import json, time 

API_KEY = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
DEVICE_ID = 'BOLTxxxxxxx'
mybolt = Bolt(API_KEY, DEVICE_ID)

#creating function for setting LED value
def set_intensity(pin, value):
	mybolt.analogWrite(pin, value)

#creting function for calculating value of LED intensity
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
    #exception handling
    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      
    except Exception as e: 
        print ("Error occured: Below are the details")
        print (e)
    time.sleep(15)

Credits

Comments