Sound Level Detector using Maker UNO paired with ESP8266 Grove WiFi on Blynk

Having a noisy surrounding at home? Make yourself a sound level detector and notify the noise maker through Blynk App using Maker UNO paired with an ESP8266 Grove WiFi.

Hardware and Software Preparation

Hardware:

  1. Maker UNO (Arduino UNO compatible) x1
  2. Grove WiFi 8266 x1
  3. Base Shield V2 x1
  4. Grove Sound Sensor x1

Software:

  1. Arduino IDE
  2. Blynk

 

Before You Start

Hardware Setup

1. Connect the Base Shield to the Maker UNO board.

2. Connect the USB cable to your computer and Maker UNO board.

3. Connect the Grove 8266 WiFi to D2 port on your Base Shield.

4. Connect the Grove Sound Sensor to A0 port on your Base Shield.

5. Set the input voltage of your Base Shield which is connected to your Maker UNO to 5V.

Software Setup

On Arduino

1. Download and install Arduino IDE on your computer if you don’t have one.

2. Download CH341 here if you are using Maker UNO for the first time. Open the downloaded file and install CH341 Driver which is used for Maker UNO.

Note: You may check the Port number for your Maker UNO in your computer’s  “Device Manager”.

3. Select the correct port in Tools >> Port: >> COM X for your Maker UNO board.

4. Select Sketch >> Include Library >> Manage Libraries. Then search for “Blynk” and click the library named “Blynk” and install.

5. Go to this link containing an additional library for Blynk, select “Code” and “Download ZIP”.

6. Go to your Arduino IDE and select Sketch >> Include Library >> Add .ZIP library… and select the ZIP file that you have downloaded.

On Blynk

1. Install Blynk app on your smartphone and create a new Blynk account if you don’t have one.

Follow the guide here on how to install the Blynk app, create a new Blynk account and get the Auth Token of your project.

2. Create a new project, select “Arduino UNO” under “Choose Device”.

 

What Does the Code Do?

  1. Able to connect to WiFi.
  2. Able to connect to your Blynk project.
  3. Able to detect the sound level of surroundings.
  4. Able to notify and show the sound level in your Blynk project when the sound level exceeds the threshold value.

 

Let’s Start Coding

Step 1: Blynk Widget Setup

1. Open your Blynk app and select your Blynk project.

2. On the Blynk project, select (+) icon to add a widget. Select “Level H” and place it into the project space.

3. Select the Widget that you have placed in the project space, then change the pin type to “Virtual” and set it to “V1”. You may name it “Sound Level” and turn on the “show value” button.

4. Select (+) icon to add a widget again and select “LED” and place it into the project space.

5. Select the “LED” widget and change the pin type to “Virtual” and set it to “V2”. You may change the colour of the LED to red by selecting the green colour icon.

6. Lastly, add another widget by selecting the “LCD” from the Widget Box and place it into the project space.

7. Switch the input of the LCD to “Advanced” and change the pin type to “Virtual” and set it to “V3”.

Step 2:  Change the baudrate of Grove WiFi 8266

The baudrate of the Grove 8266 WiFi module is set at 115200 by default. But since we will be using the software serial library on the Maker UNO, it’s more reliable to communicate at a lower speed. Hence, you have to change the baudrate of Grove WiFi 8266 to 9600bps first before using it in this project.

1. Copy and paste the following code into your Arduino IDE.

#include <ESP8266_Lib.h>
// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

void setup()
{
  // Debug console
  Serial.begin(9600);
  delay(10);
  // First open a connection at 115200
  EspSerial.begin(115200);
  delay(10);
  // Send AT command to set Wifi module's baudrate to 9600
  EspSerial.println("AT+UART=9600,8,1,0,0");
  delay(10);
  // End the connection
  EspSerial.end();
  // Reopen the connection at 9600
  EspSerial.begin(9600);
  EspSerial.println("AT");
}

void loop()
{
}

2. Upload the code to your Maker UNO Board and wait for it to complete the uploading process.

Note: Make sure you have selected the correct port in Tools >> Port: >> COM X.

If you wish to change it back to 115200 baudrate, copy the following code to your Arduino IDE and upload it to your Maker UNO while the Grove 8266 WiFi module is connected to the D2 port.

#include <ESP8266_Lib.h>
// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

void setup()
{
  // Debug console
  Serial.begin(9600);
  delay(10);
  // First open a connection at 9600
  EspSerial.begin(9600);
  delay(10);
  // Send AT command to set Wifi module's baudrate to 115200
  EspSerial.println("AT+UART=115200,8,1,0,0");
  delay(10);
  // End the connection
  EspSerial.end();
  // Reopen the connection at 115200
  EspSerial.begin(115200);
  EspSerial.println("AT");
}

void loop()
{
}

Step 3: Upload the Code

1. Copy and paste the following code into your Arduino IDE.

#define BLYNK_PRINT Serial

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

//Insert your Blynk project Auth Token
char auth[] = "Your Blynk Project Auth Token";

// Insert your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Your WiFi SSID";
char pass[] = "Your WiFi Password";

//Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

const int pinSound = A0;// pin of Sound Sensor
const int pinLed   = 7;// pin of LED on your Maker UNO board
int thresholdValue = 500;// set the threshold value to turn on or off the LED and LCD

WidgetLED led1(V2); // Widget LED Virtual Pin number in your Blynk project
WidgetLCD lcd(V3); // Widget LCD Virtual Pin number in your Blynk project

void setup()
{
  pinMode(pinLed, OUTPUT); //set the LED as an OUTPUT
  
  // Debug console
  Serial.begin(9600);
  delay(10);
  // Open the connection at 9600
  EspSerial.begin(9600);
  EspSerial.println("AT");

  Blynk.begin(auth, wifi, ssid, pass);
}

void loop()
{
    Blynk.run();
    
    int sensorValue = analogRead(pinSound);
    if (sensorValue > thresholdValue) //If the sound level detected is higher than the threshold value...
    {
      //Serial monitor shows the alert message and the sensor value
      Serial.println("Sound Level Too High!"); 
      Serial.println(sensorValue); 
      //LED on Maker UNO will light up
      digitalWrite(pinLed, HIGH); 
      //Level H Widget in Blynk shows the sound level
      Blynk.virtualWrite(V1, sensorValue); 
      //Widget LED in Blynk will turn on
      led1.on(); 
      //LCD Widget shows alert messages on the coordinates of x=0, y=0
      lcd.print(0, 0, "Too Loud!"); 
      //LCD Widget shows alert messages on the coordinates of x=0, y=0
      lcd.print(0, 1, "Keep Quiet!"); 
      // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
      delay(5000);
      //Clear the LCD Widget in Blynk
      lcd.clear(); 
      //Turn off LED Widget in Blynk
      led1.off(); 
      //Reset the Level H Widget in Blynk to 0
      Blynk.virtualWrite(V1,0); 
      //Turn off LED on Maker UNO
      digitalWrite(pinLed, LOW); 
    }
   else
    {
      //Nothing is turned on
      digitalWrite(pinLed, LOW);
      led1.off();
      lcd.clear();
    }    
}

2. Change the WiFi SSID (Line 12), WiFi password (Line 13) and the Auth Token (Line 8) in the code.

Tips: Go File >> Preferences, tick “Display line numbers” to show the line number of your code.

3. Upload the code to your Maker UNO Board and wait for it to complete the uploading process.

Note: Make sure you have selected the correct port in Tools >> Port: >> COM X.

4. Open the Serial Monitor and wait for the WiFi connection, it may take a few seconds until it shows the WiFi connection is successful or not.

Note: Remember to change the Serial Monitor baudrate to 9600.

5. On your Blynk project, press the “play” icon.

6. If the connection is successful, try to make some noise and if the sound level exceeds the threshold value, you will see the serial monitor and your Blynk project notifying you with the alert message and the sound level value.

Hope you learned how to use Grove WiFi 8266 module with Arduino. Thank you.

You are encouraged to further improve the code for higher efficiency and more advanced applications.

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

Real-Time IoT Room Monitoring on Maker Pi Pico Using pyRTOS
Build an IoT Plant Monitoring System with MicroBit and Grove WiFi Module
Snap & Fit ABS Case and ICE Tower Cooling Fan Case Stress Test
Raspberry Pi Zero 2 W – Quad-core and 64-bit CPU
IoT Push Notification Using Rain Sensor with MicroBit
Tutorials of Cytron Technologies Scroll to Top