The lightning system used in any street light is still working on century old principle of ON and OFF which needs to be modernized to save energy. During day time we can use natural light, but in the early morning, evening or during bad weather, when less natural light is available, we have to use artificial means of light. Using current lighting systems we simply turn the street light ON at full power instead of complementing it with natural light. And this results in wastage of a lot of energy. So in order to save energy we need to build a lightning system intelligent enough that it can complement the natural light with the artificial light when necessary instead of simply turning on and consuming maximum power.
Let's get started !
STEP 1 : HARDWARE CONNECTIONS
The circuit connections are shown in the diagram:
(Download the Fritzing part for the Bolt WiFi module using this link:
https://www.boltiot.com/hubfs/cloud_files/Fritzing/Bolt%20WiFi%20Module.fzpz )
According to the diagram:
Using Jumper Wires connect:
(a) 3V3 (From Bolt WiFi module) to J6 (of the Breadboard) (Orange Wire)
(b)GND (From Bolt WiFi module) to J7 (of the Breadboard) (Blue Wire)
(c)0 (From Bolt WiFi module) to J8 (of the Breadboard) (Green Wire)
(d)A0 (From Bolt WiFi module) to J9 (of the Breadboard) (Red Wire)
1. LIGHT SENSOR(a)Connect one leg of the LDR (Light Sensor) to 3V3 pin and the other leg to A0 pin.
(b)Connect one leg of the Resistor into GND pin and the other leg into the A0 pin.
2.LED
Connect the positive end (longer pin) of the LED to pin 0 and the negative pin (shorter pin) into the GND pin using male-female connecting wires.
(Connections to be made via breadboard)STEP 2 : CODE
1.ConfigurationFile
The python coding for this project has been done in Ubuntu (Linux). Before we start coding of the automating controlling of LED brightness in python, we need to make a configuration file which will have the specific keys for each user/device. We will import this file in our main code.
The following is the configuration file (named as configuration.py):
bolt_api_key = "XXXXXXXXXXXXXXXXXX"
device_id = "BOLTXXXXXXXX"
#Enter the api key and device id of your Bolt WiFi module
2.Mapping of LDR readings to LED intensity
The range of values of the LDR are from 0 to 1024 and that of the LED is from 0 to 255. As evident, one to one mapping is not possible but an approximate mapping is done as follows:
led_intensity = 255 - (sensor_value*255 /1024)The output from LDR is subtracted from 255 (maximum intensity of LED) because the mapping must be done inversely, i.e., more brightness in the surroundings must correspond to less brightness of the LED.
3. Code for controlling the intensity of the LED:
The following is the code for controlling the intensity of the LED on the basis of the brightness of the surroundings (named as led_control.py):
import json
import time
import configuration
from boltiot import Bolt
mybolt = Bolt(configuration.bolt_api_key, configuration.device_id)
def intensity(pin,value):
mybolt.analogWrite(pin,value)
def convert(sensor_value):
led_intensity = 255 - (sensor_value*255/1024)
return led_intensity
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'])
print("Calculating light intensity for LED.....")
led_value_calculated = convert(sensor_value)
led_value = int(led_value_calculated)
print("Light intensity for LED is: ", led_value)
print("_____________________________________________________")
intensity('0',led_value)
except Exception as e:
print("Error occured : Details :")
print(e)
time.sleep(10)
STEP 3 : TEST THE CODE
Connect the Bolt IoT device using USB and power it on. Then, run the above code.
Here is a screenshot of the output on Ubuntu:
Comments