Shahariar
Published © CC BY

Urban Noise Level Mapping

A solution to measure noise level and sound pollution in urban areas.

IntermediateFull instructions provided20 hours2,714

Things used in this project

Hardware components

Spresense boards (main & extension)
Sony Spresense boards (main & extension)
×1
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
SparkFun Sound Detector (with Headers)
SparkFun Sound Detector (with Headers)
×1

Software apps and online services

Blynk
Blynk

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

Sch

Code

working blynk

C/C++
#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();
} 

Credits

Shahariar

Shahariar

74 projects • 264 followers
"What Kills a 'Great life' is a 'Good Life', which is Living a Life Inside While Loop"

Comments