Project tutorial
Building Smart Cities with Less Sound Pollution

Building Smart Cities with Less Sound Pollution © Apache-2.0

You can close your eyes, but you cannot close your ears.

  • 2,377 views
  • 0 comments
  • 13 respects

Components and supplies

Apps and online services

About this project

Noise pollution also known as environmental noiseor sound pollution, is the propagation of noise with harmful impact on the activity of human or animal life.Poor urban planningmay give rise to noise pollution, side-by-side industrial and residential buildings can result in noise pollution in the residential areas. Some of the main sources of noise in residential areas include loud music, transportationnoise, lawn care maintenance, nearby construction, or young people yelling (sports games).The average noise level of 97.60 dB obtained exceeded the WHO value of 50 dB allowed for residential areas.Noise health effects. Noise health effects are the physical and psychological healthconsequences of regular exposure to consistent elevated sound levels. Elevated workplaceor environmental noisecan cause hearing impairment, tinnitus, hypertension, ischemic heart disease, annoyance, and sleep disturbance.Changes in the immune system and birth defectshave been also attributed to noise exposure. So as a small remedy for this solution, I have made a device which is capable of taking data of the sound level in the each sectors of the city. This data are compared with the accepted sound levels in various sectors. Consider the Hospitals and Park have the different accepted sound levels. This will be already fixed by the concerned authority, So when there is increase in the sound level when compared with the fixed sound levels. These sectors will be flagged by the concerned team. How is this is going to work is, the device which is consist of the sound sensor will frequently send data from the sectors to the IOTA Tangle. This data are accessed by the authority through any device(should have python platform)

Hardware

  • Arduino uno and Sound sensors- The analog value coming from the sound sensor is taken by the arduino and is converted in to the decibel values(dB).This is serially uploaded to the Raspberry pi.
  • Raspberry pi- The serial data coming from the arduino uno is received by the Raspberry and this data is uploaded to the IOTA's Tangle. The data is uploaded in every minutes to the tangle.

Note:Here you can use the ADC MCP3008(Analogto Digital converter) for collecting analog data from sound sensor with the raspberry pi by avoiding arduino uno

Software

  • Python - The complete project is running on the basis of the Python
  • PyOTA Library- This is the official Python library for the IOTA Core. If you have already pip in your computer. Enter the following command in the terminal to install the pyOTA.
pip install pyota
  • PrettyTable- This is python library used for sorting data and print in the form of tables. Enter the following command in the terminal to install the prettytable.
pip install PrettyTable
  • IOTA Address- You can generate the address using IOTA wallet.

For people who are new to IOTA, the address system might seem very confusing at first. To lift the confusion, the following link will cover all specialties about IOTA addresses you need to know.

  • Code- We have three pieces of code. First one is the arduino code.(read.ino)
int soundSensor=A0;
int dB;
void setup() {
pinMode(soundSensor,INPUT);
Serial.begin(9600);
}
void loop() {
 int Data=analogRead(soundSensor); 
 Serial.println(Data);
 dB = (Data+83.2073) / 11.003;//decibal value
 Serial.println(dB);
 Serial.write(dB);//Send data to the raspberry pi 3
 delay(100);
 }                                               

Second one is the code for the data coming from arduino to pi which is uploading to the tangle.(Upload.py)

from datetime import datetime
import schedule
import time
# Import GPIO library
import RPi.GPIO as GPIO
import serial
#Setup sensor as input
# Import the PyOTA library
import iota
# Import json
import json
# Define IOTA address where all transactions (cleaning records) are stored, replace with your own address.
# IOTA addresses can be created with the IOTA Wallet
CleaningLogAddr = b"XXXXXXXXXHKBWTCGKXTJGWHXEYJONN9MZZQUQLSZCLHFAWUWKHZCICTHISXBBAKGFQENMWMBOVWJTCMEWXKQDTJCV9"
# Create IOTA object, specify full node to be used when sending transactions.
# Notice that not all nodes in the field.deviota.com cluster has enabled attaching transactions to the tangle
# In this case you will get an error, you can try again later or change to a different full node.
api = iota.Iota("https://nodes.thetangle.org:443")
# Define static variable
city = "Smart District"
sector=0
def datapost():
   FB = api.send_transfer(depth=3, transfers=[pta], min_weight_magnitude=14)['bundle']
   print("success")
schedule.every(1).minutes.do(datapost)
# Main loop,
try:
   while True:
       ser = serial.Serial("/dev/ttyUSB0", 9600)#communication with pi,should also check the port
       status=ser.read()
       st=str(status)
       # Create json data to be uploaded to the tangle
       data1 = {'city': city, 'sector':sector,'Status': st}
       # Define new IOTA transaction
       pta = iota.ProposedTransaction(address = iota.Address(CleaningLogAddr),
                                     message = iota.TryteString.from_unicode(json.dumps(data1)),
                                     tag     = iota.Tag(b'SMARTDISTRICT'),
                                     value   = 0)
       schedule.run_pending() 
       time.sleep(1) 
except KeyboardInterrupt:
   GPIO.cleanup()

Third code is for retreiving data from the tangle to the authority.(Display.py)

 # Imports from the PyOTA library
from iota import Iota
from iota import Address
from iota import Transaction
from iota import TryteString
# Import json library
import json
# Import datetime libary
import datetime
# Import from PrettyTable
from prettytable import PrettyTable
# Define IOTA address where all transactions are stored, replace with your own address.
address = [Address(b'XXXXXXXXXXXXXXCGKXTJGWHXEYJONN9MZZQUQLSZCLHFAWUWKHZCICTHISXBBAKGFQENMWMBOVWJTCMEWXKQDTJCV9')]
# Define full node to be used when retrieving cleaning records
iotaNode = "https://nodes.thetangle.org:443"
# Create an IOTA object
api = Iota(iotaNode)
# Create PrettyTable object
x = PrettyTable()
# Specify column headers for the table
x.field_names = [ "city", "sector","Status"]
# Find all transacions for selected IOTA address
result = api.find_transactions(addresses=address)
# Create a list of transaction hashes
myhashes = result['hashes']
# Print wait message
print("Please wait while retrieving sound records from the tangle...")
# Loop trough all transaction hashes
for txn_hash in myhashes:
  # Convert to bytes
  txn_hash_as_bytes = bytes(txn_hash)
  # Get the raw transaction data (trytes) of transaction
  gt_result = api.get_trytes([txn_hash_as_bytes])
  # Convert to string
  trytes = str(gt_result['trytes'][0])
  # Get transaction object
  txn = Transaction.from_tryte_string(trytes)
  # Get transaction timestamp
  timestamp = txn.timestamp
  # Convert timestamp to datetime
  clean_time = datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
  # Get transaction message as string
  txn_data = str(txn.signature_message_fragment.decode())
  # Convert to json
  json_data = json.loads(txn_data)
  # Check if json data has the expected json tag's
  if all(key in json.dumps(json_data) for key in ["city","sector","Status"]):
      # Add table row with json values
      x.add_row([json_data['city'], json_data['sector'], json_data['Status'], clean_time])
# Sort table by cleaned datetime
x.sortby = "status"
# Print table to terminal
print(x)

This code will print the tables on the terminal of the pi. From there we can find the sectors which is violating their prescribed sound levels and can be flagged. In this way we can reduce the sound pollution in each sectors and will lead it to a smart city.

Code

Read.inoArduino
For reading sound sensor data
int soundSensor=A0;
int dB;
void setup() {
 pinMode(soundSensor,INPUT);
 Serial.begin(9600);
 
}

void loop() {

  int Data=analogRead(soundSensor); 
  Serial.println(Data);
  dB = (Data+83.2073) / 11.003;//decibal value
  Serial.println(dB);
  Serial.write(dB);//Send data to the raspberry pi 3
  delay(100);
  } 
Upload.pyPython
For storing data to the tangle
from datetime import datetime
import schedule
import time
# Import GPIO library
import RPi.GPIO as GPIO
import serial
#Setup sensor as input
# Import the PyOTA library
import iota
# Import json
import json
# Define IOTA address where all transactions (cleaning records) are stored, replace with your own address.
# IOTA addresses can be created with the IOTA Wallet
CleaningLogAddr = b"XXXXXXXXXHKBWTCGKXTJGWHXEYJONN9MZZQUQLSZCLHFAWUWKHZCICTHISXBBAKGFQENMWMBOVWJTCMEWXKQDTJCV9"
# Create IOTA object, specify full node to be used when sending transactions.
# Notice that not all nodes in the field.deviota.com cluster has enabled attaching transactions to the tangle
# In this case you will get an error, you can try again later or change to a different full node.
api = iota.Iota("https://nodes.thetangle.org:443")
# Define static variable
city = "Smart District"
sector=0
def datapost():
   FB = api.send_transfer(depth=3, transfers=[pta], min_weight_magnitude=14)['bundle']
   print("success")
schedule.every(1).minutes.do(datapost)
# Main loop,
try:
   while True:
       ser = serial.Serial("/dev/ttyUSB0", 9600)#communication with pi
       status=ser.read()
       st=str(status)
       # Create json data to be uploaded to the tangle
       data1 = {'city': city, 'sector':sector,'Status': st}
       # Define new IOTA transaction
       pta = iota.ProposedTransaction(address = iota.Address(CleaningLogAddr),
                                     message = iota.TryteString.from_unicode(json.dumps(data1)),
                                     tag     = iota.Tag(b'SMARTDISTRICT'),
                                     value   = 0)
       schedule.run_pending() 
       time.sleep(1) 
except KeyboardInterrupt:
   GPIO.cleanup()
Display.pyPython
For displaying data in the terminal
 # Imports from the PyOTA library
from iota import Iota
from iota import Address
from iota import Transaction
from iota import TryteString
# Import json library
import json
# Import datetime libary
import datetime
# Import from PrettyTable
from prettytable import PrettyTable
# Define IOTA address where all transactions are stored, replace with your own address.
address = [Address(b'XXXXXXXXXXXXXXCGKXTJGWHXEYJONN9MZZQUQLSZCLHFAWUWKHZCICTHISXBBAKGFQENMWMBOVWJTCMEWXKQDTJCV9')]
# Define full node to be used when retrieving cleaning records
iotaNode = "https://nodes.thetangle.org:443"
# Create an IOTA object
api = Iota(iotaNode)
# Create PrettyTable object
x = PrettyTable()
# Specify column headers for the table
x.field_names = [ "city", "sector","Status"]
# Find all transacions for selected IOTA address
result = api.find_transactions(addresses=address)
# Create a list of transaction hashes
myhashes = result['hashes']
# Print wait message
print("Please wait while retrieving sound records from the tangle...")
# Loop trough all transaction hashes
for txn_hash in myhashes:
  # Convert to bytes
  txn_hash_as_bytes = bytes(txn_hash)
  # Get the raw transaction data (trytes) of transaction
  gt_result = api.get_trytes([txn_hash_as_bytes])
  # Convert to string
  trytes = str(gt_result['trytes'][0])
  # Get transaction object
  txn = Transaction.from_tryte_string(trytes)
  # Get transaction timestamp
  timestamp = txn.timestamp
  # Convert timestamp to datetime
  clean_time = datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
  # Get transaction message as string
  txn_data = str(txn.signature_message_fragment.decode())
  # Convert to json
  json_data = json.loads(txn_data)
  # Check if json data has the expected json tag's
  if all(key in json.dumps(json_data) for key in ["city","sector","Status"]):
      # Add table row with json values
      x.add_row([json_data['city'], json_data['sector'], json_data['Status'], clean_time])
# Sort table by cleaned datetime
x.sortby = "status"
# Print table to terminal
print(x)

Schematics

Arduino with pi
Tony meck story image 1525107264264336 1fkemcexbm ey0getmrfj
Arduino with sensor
Arduino hookup sound detector oscmtl7uvx (1) y4znxpjbev

Comments

Similar projects you might like

Saving Aquatic Life & Fighting Water Pollution with IoT & AI

Project tutorial by Madhur Gupta

  • 3,516 views
  • 2 comments
  • 17 respects

The hydroMazing Smart Garden System

Project tutorial by Cory Potter

  • 27,639 views
  • 14 comments
  • 123 respects

Smart Home Automation

by Team Kamakshi's Smart Team

  • 5,627 views
  • 1 comment
  • 15 respects

The "SAM" SMART Automation & Monitoring Project

Project tutorial by Jade Perreault

  • 938 views
  • 0 comments
  • 8 respects

Home Smart Home

Project tutorial by Syed Sanoor

  • 75,063 views
  • 11 comments
  • 208 respects
Add projectSign up / Login