Samir Khan
Published

Smart street light using Bolt wi-fi module, Pir sensor & LDR

Building a smart street light and then converting it to a windows.exe file.

IntermediateFull instructions provided1 hour1,048
Smart street light using Bolt wi-fi module, Pir sensor & LDR

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
5 mm LED: Yellow
5 mm LED: Yellow
×2
Resistor 10k ohm
Resistor 10k ohm
×3
Jumper wires (generic)
Jumper wires (generic)
×30
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1

Story

Read more

Schematics

Circuit connection of LDR with BoltIot.

To connect a LDR with bolt iot wi-fi mode connect one leg of Ldr with 3v power supply and the other leg with A0 pin which is also known as analog pin.Now take 10K Ohm resistor and insert one leg of the 10k Ohm resistor into the GND pin and the other to A0 pin.

Circuit connection of PIR sensor with BoltIot.

There are three pins in PIR motion sensor namely VCC,OUT and GND connect VCC pin with 5v power supply of boltiot, now take OUT pin and connect it to pin 0 in bolt iot module and then connect the GND pin from PIR sensor to GND pin of bolt module.

Circuit Connections for an LED with Boltiot

1.)Take one leg of the resistor and wrap it around the longer leg of the LED i.e positive leg.
2.)Insert the negative leg of the LED into the ground pin of the Bolt.
3.)Insert the other leg of the resistor in digital pin 1 of the Bolt.
4.)Repeat the above step to connect the other LED to Bolt and insert the other leg of the resistor in digital pin 2 of the Bolt

Final look of the circuit.

This is how final circuit connection is to be.

Code

To install Bolt IoT in windows

Powershell
The following code is used to install the Bolt IoT package.
Ex:"c:\Users\samir\AppData\Local\Programs\Python\Python38-32\python.exe -m pip install boltiot"
where "c:\Users\samir\AppData\Local\Programs\Python\Python38-32\python.exe " is the location of python.exe.
c:\Users\samir\AppData\Local\Programs\Python\Python38-32\python.exe -m pip install boltiot

Final code smart street light in python.

Python
smart street light using python.
Instead of "api-key of boltiot" and "device name of boltiot" type in the api-key and device_name of your Bolt IoT module respectively.
import json 
from time import sleep
from boltiot import Bolt
api = "api-key of boltiot"
device = "device name of boltiot"
mybolt = Bolt(api,device)
while True:
	try:
		analog_response = mybolt.analogRead('A0')
		analog_data = json.loads(analog_response)
		print("LDR value >> " + analog_data['value'])
		if int(analog_data['value']) <=200:
			digital_response=mybolt.digitalRead('0')
			digital_data=json.loads(digital_response)
			print(digital_data)
			sen_value = int(digital_data['value'])
			if sen_value==1:
				print("Motion Detected")
				mybolt.digitalWrite('1','HIGH')
				mybolt.digitalWrite('2','HIGH')
				sleep(10)
			else:
				print("Sensor's ready")
				mybolt.digitalWrite('1','LOW')
				mybolt.digitalWrite('2','LOW')
		else:
			print("Sensor's ready")
			mybolt.digitalWrite('1','LOW')
			mybolt.digitalWrite('2','LOW')
	except KeyboardInterrupt:
		exit()

To install pyinstaller in python

Powershell
The following code is to install the pyinstaller.
Ex:"c:\Users\samir\AppData\Local\Programs\Python\Python38-32\python.exe -m pip install pyinstaller"
where "c:\Users\samir\AppData\Local\Programs\Python\Python38-32\python.exe" is the location of my python.exe file.
c:\Users\samir\AppData\Local\Programs\Python\Python38-32\python.exe -m pip install pyinstaller

Use of pyinstaller to create a windows executable file.

Powershell
The following command is used create a .exe file go to the location of your python directory and search for script folder, double click the script folder and copy the location and paste it in cmd.
Ex: "c:\Users\samir\AppData\Local\Programs\Python\Python38-32\Scripts\pyinstaller.exe file-name --onefile"
where "c:\Users\samir\AppData\Local\Programs\Python\Python38-32\Scripts\pyinstaller.exe" is the location of pyinstaller.
c:\Users\samir\AppData\Local\Programs\Python\Python38-32\Scripts\pyinstaller.exe file-name --onefile

Credits

Samir Khan

Samir Khan

1 project • 1 follower

Comments