Sound pollution is a serious problem for highly populated cities. It effects health and reduce quality of life. Before we deploy smart cities around the world, this issue needs to be addressed.
The problem
The noise pollution data needs to be available to everyone for few reasons :
- Identifying what causing noise pollution
- To monitor and reduce noise pollution
- Enforce environmental laws
- Have the choice to move to quieter neighborhood
- Improve quality of life
The Solution:why Sony Spresense development board ?
The noise pollution sensing system will be built around Sony Spresense development board. Since, this board has built in GPS and Audio features, it can report location and noise level data.
For a moving solution. It can be tied to low noise moving vehicles, which will collect noise level, location and time info, store to SD card and have cellular connectivity. For fixed location solutions it may be mounted on traffic lights/street lights and have wifi connectivity.
Multiple solutions will be installed through out the city to create a noise level map data. Over time complete map of noise level in dB can be generated.
In this project, a fixed solution will be built which is wifi connected. As for the IoT part, NodeMCU will get the data from the Sony Spresense development board. For data visualization, a custom app built on Blynk will show the information on Google Maps and tabulate historical data fetching from on board SD card.
App Development and Demonstration of Noise Level on Google Maps inside Blynk app with Super Chart- Custom Android App is developed with Blynk IoT.
- First, the base app is downloaded from Google Play Store
- Next, a Blynk Account is created and NodeMCU is added on a New Project
- An Auth Token was received from Blynk Server by email for using in code.
- Maps & Super Chart gadgets are added for visualizing location + noise level
- There is an optional Record button to trigger remote recording
See the following videos to understand the process:
Hardware Build
Sensing:Sound Pollution Sensor
This sensor module from spark fun provides audio output for recording and audio envelop (amplitude) output for audio level. If calibrated with standard dB scale, it can provide noise level data.
Processing:Spresense Board
The Sony spresense board uses on board GPS to locate the systems location. It is connected to the sound detector module to record audio and noise pollution level (envelop). Then, through serial it sends coordinate+noise data to NodeMCU
Connectivity:Node MCU
NodeMCU acts as the bridge for connectivity, since the Sony Spresense board does not have any IoT connectivity. It received noise level data and GPS location through serial from the Spresense board and send those data to Blynk Server. The Blynk server sends those data back to user's phone running Blynk App.
Code for Spersense board
This code is flashed on the Sony Spresense board. It performs GPS scanning, sends GPS data+noise data to Nodemcu through Serial.
//Library
#include <SDHCI.h>
#include <Audio.h>
#include <GNSS.h>
// Class
static SpGnss Gnss;
SDClass theSD;
AudioClass *theAudio;
File recFile;
//Variables
bool ErrEnd = false;
float lat = 0.0;
float lon = 0.0;
float noise = 0;
// Char
char msg_start = '<';
char msg_end = '>';
// String
String message_to_nodemcu;
String massage_from_nodemcu;
// Constant
static const int32_t recoding_frames = 400;
static const int32_t recoding_size = recoding_frames*288;
static void audio_attention_cb(const ErrorAttentionParam *atprm)
{
if (atprm->error_code >= AS_ATTENTION_CODE_WARNING)
{
ErrEnd = true;
}
}
void setup()
{
theAudio = AudioClass::getInstance();
theAudio->begin(audio_attention_cb);
theAudio->setRecorderMode(AS_SETRECDR_STS_INPUTDEVICE_MIC);
theAudio->initRecorder(AS_CODECTYPE_MP3, "/mnt/sd0/BIN", AS_SAMPLINGRATE_48000, AS_CHANNEL_STEREO);
GPS_begin();
Serial2.begin(115200);
}
void loop()
{
// Get NaviData
SpNavData NavData;
Gnss.getNavData(&NavData);
// get lat lon
lat = NavData.latitude;
lon = NavData.longitude;
// get 100 avg of noise sensor
for(int i=0; i<100; i++)
{
noise = noise+ analogRead(A0);
}
noise = noise/100; // avg of 100 samples
// merge data into a string containing lat,long,noise info like this -> <23.33,88.23,37>
message_to_nodemcu = String (msg_start + String(lat) + "," + String(lon) + "," + String(noise) + "msg_end");
// send the info over serial to node mcu
Serial2.print(message_to_nodemcu);
// add the remote recording part //
// if D2 is low by nodemcu start rec
while(!digitalRead(2))
{
recFile = theSD.open("Sound.mp3", FILE_WRITE);
theAudio->startRecorder();
if(digitalRead(2))
{
theAudio->stopRecorder();
}
}
}// end of loop
void GPS_begin()
{
int result;
result = Gnss.begin();
Gnss.select(QZ_L1CA); // Michibiki complement
result = Gnss.start(COLD_START);
}
Code for Nodemcu
The following code is flashed on the nodemcu. It runs Blynk for connectivity to Blynk App through Blynk Cloud. It also fetches GPS and Noise Data from the Sony Spresencse board through Serial.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "auth token";
char ssid[] = "WiFi name";
char pass[] = "Wifi Pass";
WidgetMap Gmap (V1);
BlynkTimer timer1;
BlynkTimer timer2;
BlynkTimer timer3;
BlynkTimer timer4;
//int index=0;
float noise =0.0;
const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars];
// temporary array for parsing
// variables for parsed data
char msgFromSpresense[numChars] = {0};
float NoiseFromSpresense = 0.0;
float LatFromSpresense = 0.0;
float LonFromSpresense = 0.0;
boolean updatedData = false;
int data =0;
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
timer1.setInterval(1000L, sensorDataSend); //timer will run every sec
timer2.setInterval(1000L, sensorDataSend2); //timer will run every sec
timer3.setInterval(100L, sensorSampler); //timer will run every sec
timer4.setInterval(2000L, readSerial);
}
void sensorDataSend()
{
int index = 0;
float lat = 0.0;
float lon =0.0;
lat = LatFromSpresense;
lon = LonFromSpresense;
noise = NoiseFromSpresense;
Gmap.location(index,lat,lon,noise);
}
void sensorDataSend2()
{
noise = data/100+20;
Blynk.virtualWrite(V2,noise);
data =0.0;
}
void sensorSampler()
{
data = analogRead(A0)+data;
}
void readSerial()
{
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (Serial.available() > 0 && updatedData == false) {
rc = Serial.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
updatedData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
if (updatedData == true) {
strcpy(tempChars, receivedChars);
// this temporary copy is necessary to protect the original data
// because strtok() used in parseData() replaces the commas with \0
char * strtokIndex; // this is used by strtok() as an index
strtokIndex = strtok(tempChars, ",");
LatFromSpresense = atof(strtokIndex);
strtokIndex = strtok(NULL, ",");
LonFromSpresense = atof(strtokIndex);
strtokIndex = strtok(NULL, ",");
NoiseFromSpresense = atof(strtokIndex);
updatedData = false;
}
}
void loop()
{
Blynk.run();
timer1.run();
timer2.run();
timer3.run();
timer4.run();
}
Advanced 3D Noise Level MeasurementSince, Sony Smersense board support up to 8 microphones, it's possible to separately measure directional sound in x, y, z axis.
- Log traffic noise pattern
- Log train/plane noise impact
- Log workshop/industrial noise pattern
- Record abnormal sounds for forensics
- Doppler speed analysis
That is for another day !
Remote Recording & Audio SurveillanceRemote recording is a feature to enable recording over the internet. Just by pushing the Record Button. Such feature can be used for audio surveillance.
Board to Board Serial Communication
ConclusionThe project is a quick demonstration. The noise sensor is not calibrated with standard equipment. For full fledged commercial solution to make a true noise pollution map, multiple sensor hubs are required to be install around the city. More work is needed in design and optimization of both hardware/software end for power, data and cost saving.
Comments