layeba faheem
Published © GPL3+

Light Monitoring System

A light monitoring system which will automatically turn on the light when it will detect that the intensity of the light has reduced.

IntermediateFull instructions provided1 hour1,415
Light Monitoring System

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
LED (generic)
LED (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1

Software apps and online services

Mailgun

Story

Read more

Schematics

uploads2ftmp2f3a27634e-5b22-4b5b-9b15-25012efba96f2fimg_20190831_190007_hdr_1Mg6tn0aBE.jpg

Code

light_system

Python
import email_conf
from boltiot import Email, Bolt
import json, time

limit=250

mybolt= Bolt(email_conf.API_KEY, email_conf.DEVICE_ID)
mailer = Email(email_conf.MAILGUN_API_KEY, email_conf.SANDBOX_URL, email_conf.SENDER_EMAIL, email_conf.RECIPIENT_EMAIL)

while True:
	print("Reading sensor value")
	response = mybolt.analogRead('A0')
	data= json.loads(response)
	print("Sensor value is: " +str(data['value']))
	print("Getting status of LED")
	response1 = mybolt.digitalRead('0')
	data1 = json.loads(response1)
	print("Status of LED:" +str(data['value']))
	try:
		sensor_value = int(data['value']0
		status1 = int(data1['value']0
		if status1 == 0 and sensor_value < limit:
			print("Lights on!")
			response = mailer.send_email("Lights are turned on","Light sensor detected low light")
			response_text= json.loads(response.text)
			print("Response from mailgun: " +str(response_text['message']))
	except Exception as e:
		print("Error occured: Below are the details ")
		print(e)
	time.sleep(3600)

email_conf

Python
MAILGUN_API_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXX"
SANDBOX_URL = "XXXXXXXXXXXXXXXXXXXXXXXXX.mailgun.org"
SENDER_EMAIL = "test@XXXXXXXXXXXXXXXXXX.mailgun.org"
RECIPINE_EMAIL = "youremail@gmail.com"
API_KEY = "XXXXXXXXXXXXXXXXXXXXXXXX "
DEVIVE_ID = "BOLTXXXXXXX"

Credits

layeba faheem

layeba faheem

0 projects • 0 followers

Comments