Arduino UNO R4 - Sound Sensor

In this guide, we will learn how to use the Arduino UNO R4 and a sound sensor to detect sounds. We will cover the following details:

Arduino UNO R4 sound sensor

Later, you can adjust the code so that it turns on an LED or a light (using a relay) when it hears a sound, or even makes a servo motor turn.

Hardware Preparation

1×Arduino UNO R4 WiFi
1×Arduino UNO R4 Minima (Alternatively)
1×USB Cable Type-C
1×Digital Sound Sensor
1×Analog Sound Sensor
1×Jumper Wires
1×(Recommended) Screw Terminal Block Shield for Arduino UNO R4
1×(Recommended) Breadboard Shield For Arduino UNO R4
1×(Recommended) Enclosure For Arduino UNO R4
1×(Recommended) Power Splitter For Arduino UNO R4

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables.

Overview of Sound Sensor

You can use the sound sensor to find sound around you. There are two kinds of sound sensor modules:

  • Digital sound sensor module: gives a simple ON or OFF signal.
  • Analog sound used module: outputs both continuous range values and ON/OFF signals.

You can adjust the sensitivity of the digital output with the built-in potentiometer.

The Digital Sound Sensor Pinout

The digital sound sensor has three pins:

  • VCC pin: Connect to VCC (3.3V to 5V).
  • GND pin: Connect to GND (0V).
  • OUT pin: This is an output pin. It shows HIGH when it is quiet and LOW when it detects sound. Connect this pin to the input pin of Arduino UNO R4.
Sound Sensor Pinout
image source: diyables.io

The sound sensor includes a potentiometer to adjust its sensitivity. It also has two LED indicators.

  • One LED indicator for power
  • One LED indicator for sound: on when there is sound, off when it is quiet

The Analog Sound Sensor Pinout

The analog sound sensor has four pins:

  • + pin: should be connected to 5V.
  • G pin: should be connected to GND (0V).
  • DO pin: is a digital output pin. It is HIGH when it is quiet and LOW when sound is detected. Connect this pin to the Arduino UNO R4's digital input pin.
  • AO pin: is an analog output pin. It sends out the sound level as an analog value. Connect this pin to the Arduino UNO R4's analog input pin.
analog sound sensor Pinout
image source: diyables.io

The analog sound sensor includes a useful built-in potentiometer. This allows you to easily change its sensitivity for the digital output. It also has two LED indicators.

  • One LED light shows if the power is on.
  • Another LED light shows if there is sound. It lights up when sound is there and goes off when it is quiet.

How It Works

The module includes an adjustable potentiometer to control how sensitive it is to sound.

  • When the sensor hears a sound, its output pin is LOW.
  • When the sensor does not hear a sound, its output pin is HIGH.

Wiring Diagram

The wiring diagram between Arduino UNO R4 Sound Sensor

This image is created using Fritzing. Click to enlarge image

How To Program For Sound Sensor

  • Sets up the Arduino UNO R4 pin as a digital input using the pinMode() function. For instance, pin 8
pinMode(8, INPUT);
  • Uses the digitalRead() function to check the status of a pin on the Arduino UNO R4.
int soundState = digitalRead(8);

Arduino UNO R4 Code - Detecting the sound

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-sound-sensor */ #define SENSOR_PIN 8 // The Arduino UNO R4 pin connected to OUT pin of the sound sensor int prev_sound_state = HIGH; // the previous state from the input pin int sound_state; // the current reading from the input pin void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); // initialize the Arduino's pin as an input pinMode(SENSOR_PIN, INPUT); } void loop() { // read the state of the the input pin: sound_state = digitalRead(SENSOR_PIN); if (prev_sound_state == HIGH && sound_state == LOW) Serial.println("The sound has been detected"); else if (prev_sound_state == LOW && sound_state == HIGH) Serial.println("The sound has disappeared"); // save the the last state prev_sound_state = sound_state; }

Detailed Instructions

Follow these instructions step by step:

  • If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
  • Connect the sound sensor to the Arduino Uno R4 according to the provided diagram.
  • Connect the Arduino Uno R4 board to your computer using a USB cable.
  • Launch the Arduino IDE on your computer.
  • Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
  • Copy the code and open it in Arduino IDE.
  • Click the Upload button in Arduino IDE to send the code to the Arduino UNO R4.
  • Clap your hand near the sound sensor.
  • Check the results on the Serial Monitor.
COM6
Send
The sound has been detected The sound has disappeared The sound has been detected The sound has disappeared
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

If you see that the LED light stays on all the time or stays off even when there is sound, you can change the settings of the potentiometer to better adjust the sensor's reaction to sound.

Troubleshooting

If the sound sensor isn't working right, try these steps:

  • Adjust the sensitivity: you can tune the sensor's sensitivity by adjusting the potentiometer.
  • Reduce vibrations: The sound sensor can pick up vibrations and wind noise. It helps to attach it to a sturdy surface to lessen these vibrations.
  • Consider the sensing range: Remember that this sound sensor can detect sounds only up to 10 inches away. To get correct readings, make sounds near the sensor.
  • Check the power supply: Make sure the power supply is stable because the sound sensor, which is an analog circuit, is affected by power noise.

Video Tutorial

Learn More

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!