Basavesh MP
Published © GPL3+

Buzzing the buzzer using LDR | BOLT IoT

Do Photons make noise? - Yes, they do. But here we are going to produce noise using a buzzer according to the intensity of light (Photons).

BeginnerFull instructions provided1 hour685
Buzzing the buzzer using LDR | BOLT IoT

Things used in this project

Hardware components

Buzzer
Buzzer
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
PHPoC Bread Board
PHPoC Bread Board
×1
Jumper wires (generic)
Jumper wires (generic)
Female to male and male to male.
×1
Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Resistor 10k ohm
Resistor 10k ohm
×1

Software apps and online services

Snappy Ubuntu Core
Snappy Ubuntu Core
Or any Linux based distro.
Bolt Cloud
Bolt IoT Bolt Cloud

Story

Read more

Schematics

Circuit Overlook

Circuit connection of hardware components.

Code

Coding Part

Python
Simple program using Python3.
import json, time                 # importing libraries
from boltiot import Bolt

# api_key and device_id of the Bolt Wi-Fi module
bolt_api_key = '8d87411e-xxxx-xxxx-xxxx-xxxxxxxxxxxx'   
device_id = 'BOLTxxxxxxx'                 

nbolt = Bolt(bolt_api_key, device_id)

# defining the function to produce sound in buzzer
def noise_maker(pin, value):
	response = nbolt.analogWrite(pin, value)
	print (response)

# creating the infinte loop so that program can run until we press 'ctrl+c' 
while True:
	response = nbolt.analogRead('A0')
	data = json.loads(response)
	try:
		intensity = int(data['value'])
		intensity = int(intensity/4 - 1)  #converting the input(0 to 1023) to output(0 to 255)
		
		print ("Light intensity is ",intensity)
		noise_maker('0', intensity)   # calling function noise_maker
		
		time.sleep(3)         # buzz for 3 sec
		noise_maker('0', 0)  # switching off buzzer
	except Exception as e:
		print ("Error ", e)
	time.sleep(10)          # receiving the input from LDR after every 10 sec

Credits

Basavesh MP

Basavesh MP

2 projects • 3 followers
Thanks to Rahul Singh.

Comments