Dhanesh Tolia
Published © GPL3+

Automatic Lights for Two-Door Hall

Turns lights on when people enter and turns them off when they leave. Also sends email notifications regarding number of people in the hall.

IntermediateFull instructions provided1 hour476
Automatic Lights for Two-Door Hall

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
IR Infrared Obstacle Avoidance Sensor Module
×2
Breadboard (generic)
Breadboard (generic)
×1
LED (generic)
LED (generic)
×1
Resistor 330 ohm
Resistor 330 ohm
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×6
Male/Male Jumper Wires
×5
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Bolt IoT Android App
Bolt IoT Android App
Bubble Visual Programming Platform

Story

Read more

Schematics

Circuit Diagram

Form the circuit exactly as shown.

Code

Code for Automatic Lights System

Python
Just type/copy the code on your Virtual Private Server and execute.
from boltiot import Bolt, Email
import conf	#contains all confidential information like API Key, Device ID, Sandbox URL, etc.
import json, time

mybolt = Bolt(conf.api_key, conf.device_id)
mailer = Email(conf.mg_api_key, conf.sandbox_url, conf.sender_EM, conf.recipient_EM)

people = 0

while True:
	try:
		# Read Input and determine number of people entering the room

		response = mybolt.digitalRead('0') #IP Sensor for Entry Door
		data = json.loads(response)
		if data['value'] == "0" :
			people = people + 1


		#Read Input and determine number of people exiting the room

		response = mybolt.digitalRead('1') #IP Sensor for Exit Door
		data = json.loads(response)
		if data['value'] == "0" :
			people = people - 1
			if people < 0:
				people = 0

		#Take action on Lights

		if people > 0:
			mybolt.digitalWrite('4', 'HIGH') #To Relay or LED
		else:
			mybolt.digitalWrite('4', 'LOW')


		#Send Email with details when asked to do so through web-app

		response = mybolt.digitalRead('3') #Detects whether pin-2 is HIGH
		data = json.loads(response)
		if data['value'] == '1' :
			response = mailer.send_email("Room Info.", "The number of people in the room =" +str(people))
			print("Email Sent")
			response = mybolt.digitalWrite('2', 'LOW')
		print("The number of people in the hall = "+str(people))
		print("Sleep for 2 seconds") #Use delay of 20 seconds if you do not have Pro Pack of Bolt Cloud
		time.sleep(2)

	except Exception as e:
		print("Something went wrong: ", e)
		print("Restarting Bolt...")
		response = mybolt.restart()

Credits

Dhanesh Tolia

Dhanesh Tolia

1 project • 0 followers
I am currently an undergraduate student at NIT Jamshedpur. Computers fascinate me. To watch them transform our physical world is my passion.

Comments