Project tutorial
IoT Based Public Notification System

IoT Based Public Notification System

A smart IoT and machine learning based public address system.

  • 252 views
  • 0 comments
  • 2 respects

Components and supplies

Apps and online services

About this project

Introduction

I live in Agra. In my locality, the people get their milk every evening when the milk van arrives. The van drops off barrels of milk for the entire locality and collects the empty barrels later in the evening. The volunteers responsible for milk distribution collect these barrels and inform the residents to collect the milk.

This information is given to the residents by ringing a gong/bell at the milk distribution point. But the problem is that the sound of the gong/ bell is audible upto a radius of 50 meters or so. Therefore, many people don't get the information which leads to delay in distribution. Many a times, people are not able to get their milk because they couldn't receive the information in time.

This system attempts to eliminate this problem by sending a notification to the residents via Telegram when the gong/ bell is rung.

Demonstration

Here, I am using a small plate to simulate the ringing of the gong.

Hardware Setup

An Adafruit MAX4466 Electret microphone has been used to pick up sound of the ringing of the bell. This mic has been interfaced with the BOLT Wifi Module using an Arduino Uno as shown in the following Fritzing diagram.

Setting up Telegram Channel

Download Telegram from the Play Store and sign up using your phone number. Now, follow the following steps to set up your telegram channel.

Setting up Chat Bot

Bots are third-party applications that run inside Telegram. Users can interact with bots by sending them messages, commands and requests. Telegram allows us to create a new bot with the help of a bot called as "BotFather". It is a single bot to create and manage other bots. Follow the following steps to setup the bot.

After the bot has been set up, add the bot the channel you created and make it an admin.

Set up Configuration File

Create a python file named 'conf.py' on your VPS and enter the following information:

bolt_api_key = "XXXX"                   # This is your Bolt Cloud API Key.
device_id = "XXXX" # This is the device ID and will be similar to BOLTXXXX.
telegram_chat_id = "@XXXX" # This is the channel ID of the Telegram channel.
telegram_bot_id = "botXXXX" # This is the bot ID of the Telegram Bot.
frame_size = 10 # Number of data points being considered
mul_factor = 3 # Multiplication constant for Z-Score Analysis

Arduino Code Explanation

This code reads noise values from the mic and sends it to the Bolt Wifi Module via serial communication.

int data;
void setup() {
// put your setup code here, to run once:
pinMode(A0,INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
data= analogRead(A0);
Serial.println(String(data));
delay(5000);

Main Code Explanation

The code can be basically divided into three major parts. They are,

  • Reading values from the Bolt device
  • Comparing the sensor value with the threshold. (The threshold value has been determined by using Z-Score Analysis)
  • Sending a message via Telegram if the threshold has been breached.

The above steps are put in a while loop so that it reads the sensor value every 10 seconds and sends the alert if required.

The entire code has been provided in the 'Code' section of this tutorial.

Conclusion

This system can be adopted for many use cases such as flood detection, temperature monitoring, irrigation systems, emergency notification etc. All you need to do is to swap out the sensor with a suitable one and write a suitable message to be conveyed to the public.

Code

Configuration file for the codePython
Enter your own api_key, device_id, telegram_chat_id, telegram_bot_id
api_key = "XXXXXXXXXXXXXXXXXXXXXXXXX"
device_id = "XXXXXXXXXX"
telegram_chat_id = "XXXXXXXXXXX"
telegram_bot_id = "XXXXXXXXXXXXXXXXXXXXX"
frame_size = 10
mul_factor = 3
Code for everything elsePython
import requests
import time
import statistics
import math
import json

import conf
from boltiot import Bolt

mybolt = Bolt(conf.api_key,conf.device_id)
mybolt.serialBegin('9600')

def getSensorValue():
#Returns Sensor Value. Returns -999 if fails
	try:
		response = mybolt.serialRead("10")
		data = json.loads(response)

		if data["success"] != 1:
			print("Request not successful")
			print(response)
			return -999

		sensor_value = data["value"]
		return sensor_value

	except Exception as e:
		print("Something went wrong. Response from BOLT:")
		print(e)
		return -999

def send_telegram_message(message):
#Send Telegram message and returns status
	url = "https://api.telegram.org/"+conf.telegram_bot_id+"/sendMessage"

	data =  {
		"chat_id" : conf.telegram_chat_id,
		"text" : message
		}

	try:
		response = requests.request("POST",url,params = data)

		print("Telegram url:")
		print(url)

		print("Response from Telegram:")
		print(response.text)

		telegram_data = json.loads(response.text)

		return telegram_data["ok"]

	except Exception as e:

		print("Something went wrong! Response:")
		print(e)
		return(False)

def compute_bounds(history_data,frame_size,factor):
#Computes lower and upper bounds for anomaly detection

	if len(history_data) < frame_size:
		return None

	if len(history_data) > frame_size:
		del history_data[0:len(history_data)-frame_size]

	Mn = statistics.mean(history_data)
	Variance = 0

	for data in history_data:
		Variance = Variance + math.pow((data-Mn),2)

	Zn = factor * math.sqrt(Variance/frame_size)

	high_bound = history_data[frame_size-1] + Zn
	low_bound = history_data[frame_size-1] - Zn

	return [high_bound,low_bound]

history_data = []
count = 0

while True:

	sensor_value = getSensorValue()
	l = len(sensor_value)

	if sensor_value == -999:
		print("Request was unsuccessful! Skipping")
		continue

	curNoise = int(sensor_value[0:l-1])

	print("Current Noise Value: ",curNoise)

	bound = compute_bounds(history_data,conf.frame_size,conf.mul_factor)

	if not bound:
		history_data.append(curNoise)
		print("Need ",conf.frame_size-len(history_data)," more values.")
		time.sleep(5)
		continue

	print(bound,curNoise)

	if curNoise<bound[1]:

		print("No noise at all!")

		message = "Very quiet surroundings."
		telegram_status = send_telegram_message(message)

		print("Status: ",telegram_status)

	elif curNoise>bound[0]:

		print("Bell ringing!")

		message = "Moo! Milk has arrived at the Milk Distribution Point."
		telegram_status = send_telegram_message(message)

		print("Status: ",telegram_status)

	history_data.append(curNoise)
	print("\n")

	time.sleep(5)

Schematics

Circuit Connection
Make the following connection:
1. Arduino 5V ---> Mic VCC
2. Arduino GND---> Mic GND
3. Arduino A0 ---> Mic OUT
4. Arduino Rx ---> Bolt Tx
5/ Arduino Tx ---> Bolt Rx
Bolt project bb jfhymv8qds

Comments

Similar projects you might like

Smart Personal Money Vault Monitoring System Based on IoT

Project tutorial by Salah Uddin

  • 2,481 views
  • 2 comments
  • 13 respects

Android App-Based Home Automation System Using IOT

Project tutorial by Team Autoshack

  • 50,883 views
  • 22 comments
  • 144 respects

Water Level Alerting System

Project tutorial by Pranav Kundaikar and Vinayak Shantaram Joshi

  • 9,118 views
  • 10 comments
  • 15 respects

Anomaly Detection & Temperature Monitoring Using Bolt IoT

Project tutorial by ashish anand

  • 4,036 views
  • 2 comments
  • 20 respects

RFID Based Smart Attendance System

Project showcase by team_chkr

  • 3,110 views
  • 1 comment
  • 13 respects
Add projectSign up / Login