@shoeb.ahmed @rahul.singh1 @yeshwant.naik Can anyone help me with the python code for light sensor application where I want to make the LED ON as soon as the room goes dark and LED OFF as the room light is switched ON? Also, darker the room goes, brighter the LED glows kind of code with analogWrite() would be great.
When I run the below code, it continuously measures the sensor value but the LED keeps blinking instead of staying steady ON until I switch ON the room light. I want the LED to be ON until the room light is switched ON, not in a blinking fashion but steady ON.
import conf
from boltiot import Bolt
import json
threshold = 30
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
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 < threshold:
mybolt.digitalWrite ('0', 'HIGH')
else:
mybolt.digitalWrite ('0', 'LOW')
except Exception as e:
print ("Error",e)