In this project we will make IoT Based Sound Level & Intensity Monitoring Device using Nodemcu ESP8266 & Sound Module/Sensor & monitor online on Thingspeak Server.
Overview
A sound level meter is used for acoustic (sound that travels through the air) measurements. The best type of microphone for sound level meters is the condenser microphone, which combines precision with stability and reliability. The diaphragm of the microphone responds to changes in air pressure caused by sound waves. That is why the instrument is sometimes referred to as a Sound Pressure Level (SPL) Meter.
Sound level meters are commonly used in noise pollution studies for the quantification of different kinds of noise, especially for industrial, environmental, mining and aircraft noise. The reading from a sound level meter does not correlate well to human-perceived loudness, which is better measured by a loudness meter. Specific loudness is a compressive nonlinearity and varies at certain levels and at certain frequencies. These metrics can also be calculated in a number of different ways.
In this IoT project, we will make Sound Level & Intensity Meter. This DIY project is very simple and can be made at home for monitoring sound pollution. We will use Nodemcu ESP8266, Sound Module & OLED Display. The Sound Sensor will detect the sound and convert it into an analog voltage which is read by Nodemcu ESP8266. The Nodemcu connects to wifi and uploads the data to Thingspeak Server.
Before starting, you can check the previous post to get started with Sound Sensor:
1. Decibel Meter using Sound Module & Arduino with LCD Display
2. IoT Decibelmeter with Sound Sensor & ESP8266
Components Required
Following are the components required for making this project. All the components can be eaily purchased from Amazon. The componets purchase link is given below.
| S.N. | Components Name | Quantity | Purchase Links |
|---|---|---|---|
| 1 | NodeMCU ESP8266 | 1 | Amazon | AliExpress |
| 2 | Sound Sensor | 1 | Amazon | AliExpress |
| 3 | OLED Display | 1 | Amazon | AliExpress |
| 4 | Connecting Wires | 10 | Amazon | AliExpress |
| 5 | Breadboard | 1 | Amazon | AliExpress |
Microphone Sound Sensor
The microphone sound sensor, as the name says, detects sound. It gives a measurement of how loud a sound is. The sound sensor is a small board that combines a microphone (50Hz-10kHz) and some processing circuitry to convert sound waves into electrical signals. This electrical signal is fed to on-board LM393 High Precision Comparator to digitize it and is made available at OUT pin.
The module has a built-in potentiometer for sensitivity adjustment of the OUT signal. We can set a threshold by using a potentiometer. So that when the amplitude of the sound exceeds the threshold value, the module will output LOW otherwise HIGH.
Apart from this, the module has two LEDs. The Power LED will light up when the module is powered. The Status LED will light up when the digital output goes LOW.
The sound sensor only has three pins: VCC, GND & OUT. VCC pin supplies power for the sensor & works on 3.3V to 5V. OUT pin outputs HIGH when conditions are quiet and goes LOW when sound is detected.
0.96″ I2C OLED Display
This is a 0.96 inch blue OLED display module. The display module can be interfaced with any microcontroller using SPI/IIC protocols. It is having a resolution of 128×64. The package includes display board, display,4 pin male header pre-soldered to board.
OLED (Organic Light-Emitting Diode) is a self light-emitting technology composed of a thin, multi-layered organic film placed between an anode and cathode. In contrast to LCD technology, OLED does not require a backlight. OLED possesses high application potential for virtually all types of displays and is regarded as the ultimate technology for the next generation of flat-panel displays.
Circuit: Sound Level Monitor with ESP8266 & Sound Module
The circuit diagram for Interfacing Sound Sensor with NodeMCU ESP8266 & OLED Display is given below. The connection is fairly simple.
The sound sensor and OLED display both needs 3.3V power supply. So connect their VCC & GND terminal to 3.3V & GND of NodeMCU respectively. Connect the output pin of sound sensor to Nodemcu A0 pin. Connect the I2C pin, i.e SDA & SCL pin of OLED Display to Nodemcu D2 & D1 pin respectively.
Setting Up Thingspeak
In order to Monitor the Sensor Data on Thingspeak Server, you first need to Setup the Thingspeak. To set up the Thingspeak Server, visit https://thingspeak.com/. Create an account or simply sign in if you created the account earlier. Then create a new channel with following details.
After filling these details, save the channel. The go-to the API Key and copy the API key. This API key will be used in the program.
Source Code/Program
The source code/program for Sound Module with ESP8266 is given below. Copy the code and upload it to the Nodemcu board.
Make sure to do the changes in Wifi SSID, Password and Thingspeak API.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
#include <ESP8266WiFi.h> #include <SPI.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); int num_Measure = 128 ; // Set the number of measurements int pinSignal = A0; // pin connected to pin O module sound sensor long Sound_signal; // Store the value read Sound Sensor long sum = 0 ; // Store the total value of n measurements long level = 0 ; // Store the average value int soundlow = 40; int soundmedium = 500; int error = 33; String apiKey = "14K8UL2QEK8BTHN6"; // Enter your Write API key from ThingSpeak const char *ssid = "Alexahome"; // replace with your wifi ssid and wpa2 key const char *pass = "12345678"; const char* server = "api.thingspeak.com"; WiFiClient client; void setup () { pinMode (pinSignal, INPUT); // Set the signal pin as input Serial.begin (115200); display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128x64) display.clearDisplay(); delay(10); Serial.println("Connecting to "); Serial.println(ssid); display.clearDisplay(); display.setCursor(0,0); display.setTextSize(1); display.setTextColor(WHITE); display.println("Connecting to "); display.setTextSize(2); display.print(ssid); display.display(); WiFi.begin(ssid, pass); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); display.clearDisplay(); display.setCursor(0,0); display.setTextSize(1); display.setTextColor(WHITE); display.print("WiFi connected"); display.display(); delay(4000); } void loop () { // Performs 128 signal readings for ( int i = 0 ; i <num_Measure; i ++) { Sound_signal = analogRead (pinSignal); sum =sum + Sound_signal; } level = sum / num_Measure; // Calculate the average value Serial.print("Sound Level: "); Serial.println (level-error); display.clearDisplay(); display.setCursor(0,0); //oled display display.setTextSize(1); display.setTextColor(WHITE); display.println("--- Decibelmeter ---"); if( (level-error) < soundlow) { Serial.print("Intensity= Low"); display.setCursor(0,20); //oled display display.setTextSize(1); display.setTextColor(WHITE); display.print("Sound Level: "); display.println(level-error); display.setCursor(0,40); display.print("Intensity: LOW"); display.display(); // { // if( (level-error) < 0) // Serial.print("Intensity= Low"); // display.setCursor(0,20); //oled display // display.setTextSize(1); // display.setTextColor(WHITE); // display.print("Sound Level: 0"); // // display.setCursor(0,40); // display.print("Intensity: LOW"); // // display.display(); // } } if( ( (level-error) > soundlow ) && ( (level-error) < soundmedium ) ) { Serial.print("Intensity=Medium"); display.setCursor(0,20); //oled display display.setTextSize(1); display.setTextColor(WHITE); display.print("Sound Level: "); display.println(level-error); display.setCursor(0,40); display.print("Intensity: MEDIUM"); display.display(); } if( (level-error) > soundmedium ) { Serial.print("Intensity= High"); display.setCursor(0,20); //oled display display.setTextSize(1); display.setTextColor(WHITE); display.print("Sound Level: "); display.println(level-error); display.setCursor(0,40); display.print("Intensity: HIGH"); display.display(); } sum = 0 ; // Reset the sum of the measurement values delay(200); if (client.connect(server, 80)) // "184.106.153.149" or api.thingspeak.com { String postStr = apiKey; postStr += "&field1="; postStr += String(level-error); postStr += "r\n"; client.print("POST /update HTTP/1.1\n"); client.print("Host: api.thingspeak.com\n"); client.print("Connection: close\n"); client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n"); client.print("Content-Type: application/x-www-form-urlencoded\n"); client.print("Content-Length: "); client.print(postStr.length()); client.print("\n\n"); client.print(postStr); } client.stop(); //delay(15000); // thingspeak needs minimum 15 sec delay between updates. } |
To calibrate the device the following line needs to be corrected practically.
|
1 2 3 |
int soundlow = 40; int soundmedium = 500; int error = 33; |
The sound module detects the sound in 3 different levels assigned as Low Intensity, Medium Intensity and High Intensity. You can set the soundlow & soundmedium according to your wish. The hearing intensity depends varies from person to person.
Similarly, error integer is defined to remove the negative value for sound level. This can only be known after uploading the code and doing the observation. Check the negative value when there is pin-drop silent and assign in the code.
Monitor Sound Level with ESP8266 & Sound Module on OLED Display
After the code is uploaded the Nodemcu will try connecting to wifi. All the process can be observed in OLED display as shown below.
Once the wifi is connected, the OLED display will start displaying the sound level and intensity on OLED Screen.
Now you can play music and observe the value on OLED Display. The sound level will rise when high sound is detected and will slow down when a low sound is detected.
Monitor Sound Level with ESP8266 & Sound Module on Thingspeak
You can visit Thingspeak now to monitor the sound level data online. Just go to the private view of Thingspeak and you will see the following data logs & graphs.














1 Comment
I’m a bit confused as to how thingsspeak can plot the data like that, although it’s been converted to a string beforehand