Neeraj R
Published © GPL3+

Controlling LED Using LDR Sensor

In this circuit LDR sensor determines the intensity of light. If the intensity is less, LED will be turned on or else it will be turned off.

IntermediateFull instructions provided1 hour363
Controlling LED Using LDR Sensor

Things used in this project

Hardware components

LDR, 5 Mohm
LDR, 5 Mohm
×1
3 mm LED: Yellow
3 mm LED: Yellow
×1
Resistor 330 ohm
Resistor 330 ohm
×2
Jumper wires (generic)
Jumper wires (generic)
×1
Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1

Story

Read more

Schematics

Circuit Diagram

Code

Python3 code for Controlling LED Automatically

Python
This code checks Intensity of light every 10 seconds. if it is less than 15 LED will Turn ON else it will turn OFF
from boltiot import  Bolt
import json, time
api_key="Your Bolt cloud API Key"
device_id="Your Bolt Device ID"
minimum_limit = 15
mybolt=Bolt(api_key,device_id)
print(format("Auto LED Controller",'_^50'))
error='{"success": "0", "message": "A Connection error occurred"}'
offlne='{"value": "offline", "time": null, "success": 1}'
result=mybolt.isOnline()
if result==error:
	print("\n Check weather your computer or bolt device is connected to Internet.....")
elif result==offlne:
	print("\n Bolt Device is offline....")
else:
	while True:
		print ("\n Recognizing Value from Senser.......")
		response = mybolt.analogRead('A0')
		data = json.loads(response)
		inten=int(data['value'])
		print("value from senser is: " + str(inten))
		if inten<minimum_limit:
			result=mybolt.digitalWrite('0','HIGH')
			print("LED is Sucessfully Turned ON")
		else:
			result=mybolt.digitalWrite('0','LOW')
			print("LED is Sucessfully Turned OFF")
		time.sleep(10)

Credits

Neeraj R

Neeraj R

1 project • 1 follower

Comments