The main motive of this project is to control the intensity of light by manually changing it from the Bolt Android App or self alteration.
Self alteration of the brightness is done by input of the surrounding brightness using an Light Detecting Resistor (LDR), it's reading is mapped to the range of the intensity of the LED and the variable output is generated using Pulse Width Modulation (PWM).
To manually control it we have a user interface that has access to the BOLT Cloud. In this interface, we can see a Pulse Width Modulation(PWM) value that ranges from 0 to 255, 0 being LED OFF and 255 being LED ON at maximum intensity of brightness. This interface is accessible on the bolt cloud and on the smartphone BOLT application.
View schematic at end.
2. AUTOMATED CONTROL OF LED BRIGHTNESSIn this section we will see how to automatically control the brightness of the LED based on the surrounding brightness which is measured by LDR.
2.1Circuit Connection of LED and LDR
Given below is the hardware connection.
The input from the LDR is taken on A0 and output is written on Pin 1. Power supply to LDR is given using 3.3V pin of the BOLT Module. The resistance across LDR changes with the change in the intensity of light falling on it. Bolt Module can read voltage values, hence a voltage divider circuit is made and the input to the Bolt module is the voltage across 10k resistance which depends on the resistance across LDR. The positive (longer) terminal of the LED is connected to the digital pin 1 and the negative (shorter) terminal to the ground. The digital pin 1 output acts as the power supply for the LED and hence determines its intensity.
2.2CodeFile
The code for this part has been written in python on Ubuntu(Linux). We need a configuration file which will have the specific keys for each user/device. We have to import this file on our main code file to use the various attributes.
(named as conf.py):
API_KEY = "XXXX" //Bolt Cloud API Key
DEVICE_ID = "BOLTXXXX" //Device ID of the Bolt Module
The API key and Device ID of the Bolt module can be determined as follows:
- Connect your Bolt Device to the Bolt Cloud as per instructions given at https://cloud.boltiot.com/.
- The following screen will appear after that.The Bolt Device ID is highlighted in yellow.
- Go to the API section to know the API Key.
2.3Mapping of LDR values to LED values
The range of values of the LDR are from 0 to 1024 and that of the LED is from 0 to 255. An approximate of 4:1 mapping is done input to LED = 255 - (output from LDR / 4).
3.Code
3.1 Code for automatic functionality
from boltiot import Bolt
import json,time //importing python libraries
mybolt= Bolt(conf.API_KEY,conf.DEVICE_ID)
def set_intensity(pin,value)
mybolt.analogWrite(pin,value)
def control(sensor_val):
led_int= 255-(sensor_val*(255/1024) #output value of led
return led_int
while True:
print("Reading sensor value")
resp_ldr=mybolt.analogRead('A0') #read LDR value from A)
data=json.loads(resp_ldr) #convert value to json format
print("Sensor value is: " + str(data['value'])) #print the value
try:
sensor_val=int(data['value'])
print("Light intensity")
led_float=control(sensor_value)
led_value=int(led_float)
print(led_value)
set_intensity('1',led_value)
# in case of any error
except error as e:
print("Error occured:- ")
print(e)
time.sleep(5)
3.2 OutputOFPython
3.3ManualFunctionality
- Select the Products tab, and click on ADD PRODUCT.
- Enter Product Name and add an Icon.
- Click on Configure this product symbol, and go to the Code tab.
- Give a name and select file type as html and paste the following code in the code window.
<html>
<head>
<title>Bolt IoT Platform</title>
<script type="text/javascript" src="https://cloud.boltiot.com/static/js/boltCmmands.js"></script>
<script>
setKey('{{ApiKey}}','{{Name}}');
var last_pwm_value=-1;
function updateBuzzer(){
var pwm_value=document.getElementById('pwm_value').value;
if(last_pwm_value!=pwm_value){
analogWrite(1,pwm_value);
document.getElementById('pwm_value_display').innerHTML=pwm_value;
}
last_pwm_value=pwm_value;
}
setInterval(updateBuzzer,1000);
</script>
</head>
<body>
pwm value:
<input type='range' id='pwm_value' min="0" max="255" value="0">
<div id='pwm_value_display'>0</div>
</body>
</html>
- Click on Save to save your configuration then return to the product screen.
- Click on 'Link device to this product', and select your BOLT WIFI module.
- Click on 'Deploy configuration' icon to successfully deploy the application and use the smartphone Bolt application.
- Control the light intensity using the knob on the interface.
Comments