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:
- How to connect a sound sensor to an Arduino UNO R4
- How to write a program for Arduino UNO R4 to detect sound using a 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
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
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.
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.
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
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
- Uses the digitalRead() function to check the status of a pin on the Arduino UNO R4.
Arduino UNO R4 Code - Detecting the sound
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.
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.