Siddharth Bhandarkar

Real-Time Noise Pollution Alert

A miniature representation of sending alert to the police about the real-time random sound intensity around the hospital via Telegram.

IntermediateProtip6 hours173
Real-Time Noise Pollution Alert

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
USB Cable Assembly, USB Type A Plug to Micro USB Type B Plug
USB Cable Assembly, USB Type A Plug to Micro USB Type B Plug
SparkFun Sound Detector (with Headers)
SparkFun Sound Detector (with Headers)
Jumper wires (generic)
Jumper wires (generic)

Software apps and online services


Hand tools and fabrication machines


Read more


Circuit connections of Bolt Iot Module and Sound Sensor

Here the Bolt IoT Wi-Fi Module is connected to the Sound sensor with the jumper wires via its attributes


Real time Noise Pollution Alert

There are two code files namely and that should be created separately
“”1. Configurations for Telegram alert message. File name ””
BOLT_API_KEY = XXXXXXXXX	# This is your Bolt cloud API Key.
DEVICE_ID = XXXXXXXXX	# This is the ID number of your Bolt device.
TELEGRAM_CHAT_ID = @XXXXXXXXX	# This is the channel ID of the channel created in the Telegram. Paste after @.
TELEGRAM_BOT_ID = botXXXXXXXXX	# This is the bot ID of the bot created in the Telegram. Paste after bot.
THRESHOLD = 80	# Threshold beyond which the alert should be sent.

""2. Main code file. File name""

import requests                 # for making HTTP requests
import json                     # library for handling JSON data
import time                     # module for sleep operation
from boltiot import Bolt        # importing Bolt from boltiot module
import configuration            # configuration file
mybolt = Bolt(configuration.BOLT_API_KEY, configuration.DEVICE_ID)
def get_sound_sensor_value_from_pin(pin):
  response = mybolt.analogRead(pin)
  data = json.loads(response)
      if data["success"] != 1:
            print("Request not successful")
            print("This is the response->", data)
            return -999
    	sound_sensor_value = int(data["value"])
    	return sound_sensor_value
except Exception as e:
print("Something went wrong when returning the sensor value")
     return -999
def send_telegram_message(message):
url = "" + configuration.TELEGRAM_BOT_ID + "/sendMessage"
data = {
        "chat_id": configuration.TELEGRAM_CHAT_ID,
        "text": message
        response = requests.request(
            params = data
        print("This is the Telegram response")
        telegram_data = json.loads(response.text)
        return telegram_data["OK"]
    except Exception as e:
print("An error occurred in sending the alert message via Telegram")
        return False
while True:
    #Step 1
    sound_sensor_value = get_sound_sensor_value_from_pin("A0")    
    print("The current sensor reading is:", sound_sensor_value)
    #Step 2
    if sound_sensor_value == -999:
	print("Request was unsuccessful. Skipping.")
     #Step 3
    if sound_sensor_value >= configuration.THRESHOLD:
      print("Sensor value has exceeded threshold")
      message = "Alert! Noise disturbance around the XYZ Hospital. Random and          unidentified sound intensity has crossed " + str(configuration.THRESHOLD) +       str(dB) + \
    The current sound sensor reading is  + str(sound_sensor_value) + str(dB)     + str(To, The Police Incharge, Immediate action required. Thankyou.)
telegram_status = send_telegram_message(message)
print("This is the Telegram status:", telegram_status)

# Step 4


Siddharth Bhandarkar

Siddharth Bhandarkar

1 project • 1 follower


Add projectSign up / LoginAbout BBC micro:bit