Detect noise levels using a sound sensor 🔊

In various applications, we need to detect sound intensity, maybe to enhance the functionality of the devices and their interaction with the surroundings or to make a security system. 


In this tutorial we will use the Arduino and a sound sensor to detect sound levels in your environment and print this data directly on your computer.


Overview


A sound sensor is a device that can detect and measure sound waves. It is a part of many of the devices we use, including phones, laptops, and music players. as well as security and monitoring systems.


By finishing this tutorial, you will learn how to use the sound sensor so that you may include it in more complex projects, such as creating a graph of sound level over time. You can also use it to turn on an LED or buzzer when the sound level exceeds a given threshold.


Getting the items


For this project you will need the following components you can buy them from our store.

Sale Off
Voltaat Arduino Uno R3 (Voltaat Version)
45 QAR
Sale Off
Voltaat Microphone Module
13 QAR
Sale Off
Voltaat Jumper Wires - Male to Female (40 Pack)
10 QAR

Wiring it up


To set up the sound sensor in the correct way, follow the instructions below. The image demonstrates how to connect the wires between the sound sensor and the Arduino. Once the sound sensor and the Arduino are connected to each other, connect the Arduino to your computer using the USB cable.


Connections from the Arduino to the sound sensor:

• Arduino A0 pin → sound sensor A0 pin

• Arduino GND pin → sound sensor GND pin (- pin)

• Arduino 5V pin → sound sensor VCC pin (+ pin)

• Arduino pin 2 → sound sensor D0 pin


Coding


This sketch's purpose is to keep track of the noise levels in the surrounding area. It uses the serial monitor to display the read values from the sound sensor as well as the sound status based on whether the digital read indicates that the noise level is high or low.


Simply follow the instructions and comments throughout the code to understand it well. You can develop and use it in more complex projects like a security alarm.


/*
Voltaat learn (https://www.voltaat.com/pages/voltaat-learn)
Link for full tutorial: https://bit.ly/3FrQDV5

Tutorial: Detect noise levels using a sound sensor

This sketch's purpose is to keep track of the noise levels in the surrounding area

Connections from the Arduino to the sound sensor:
• Arduino A0 pin → sound sensor A0 pin
• Arduino GND pin → sound sensor GND pin (- pin)
• Arduino 5V pin → sound sensor VCC pin (+ pin)
• Arduino pin 2 → sound sensor D0 pin

*/


//Define the variable soundSensorRead to Analog Input Pin A0
const int soundSensorRead = A0;

//Define the variable soundSensorPin to Digital Input Pin 2
const int soundSensorPin =2;

//Define variables
int sensorRead;
boolean sensorStatus;

//Commands inside void setup run once
voidsetup()
{
//Start the serial monitor at 9600 baud rate (9600 bits per second)
Serial.begin(9600);
//SoundSensorPin is defined as an input
pinMode(soundSensorPin,INPUT);

}


//Commands inside void loop run forever
void loop()
{
//Read the value of analog input from soundSensorRead and assign it in the variable sensorRead
sensorRead =analogRead(soundSensorRead);
//Read the value of digital input from soundSensorPin and assign it in the variable sensorStatus
sensorStatus =digitalRead(soundSensorPin);

//Check noise status
if(sensorStatus ==HIGH)
{
//Print to serial monitor
Serial.print("Alert, there is high noise in the surroundings ");
Serial.print("| Sound sensor value: ");
Serial.println(sensorRead);

}
else
{
//Print to serial monitor
Serial.print("Everything around you is peaceful ");
Serial.print("| Sound sensor value: ");
Serial.println(sensorRead);

}

//Delay for 3 seconds
delay(3000);
}

Testing it out




Now you must have correctly wired the sound sensor to the Arduino as we explained in the wiring section, as well as uploaded the code to your Arduino board.


You may now access the serial monitor on your Arduino IDE by clicking on the magnifying glass icon at the top right corner.



The serial monitor is a great tool that can facilitate communication between the computer and the Arduino. It allows us to send and receive different commands as well as view information directly from the Arduino.


Now, as we can see in the image below, the serial monitor prints the noise state and the read value from the sensor.


The value is updated and printed every three seconds. Because of the delay, we added to our code.

You should also check that you have selected the correct baud rate (9600) as specified in the code.


Resources 


Arduino Code

Fritzing Wiring file

Related Tutorials


RG LED is similar to a regular LED but it is made up of three smaller ones. It is called an RGB LED because it has three LEDs with three colors: red, green, and blue.

Most of us are familiar with the switches used in household devices. A relay is a type of switch that can be connected to an Arduino or any other microcontroller.


LCDs are used in a range of everyday applications, including the automobile radio and the house air conditioning remote. They display data and let you control it through menus.