Arduino - Sound Sensor
The sound sensor is capable of detecting the presence of sound in the surrounding environment. It can be used to create sound-reactive projects, such as clap-activated lights or a sound-activated pet feeder.
In this tutorial, we are going to learn how to use Arduino and sound sensor to detect the sound. In detail, we will learn:
- How to connect the sound sensor to Arduino
- How to program Arduino to detect the sound using the sound sensor
Afterward, you can tweak the code to make it activate an LED or a light (via a relay) when it detects sound, or even make a servo motor rotate.
|Arduino UNO or Genuino UNO
|USB 2.0 cable type A/B
|(Optional) 9V Power Adapter for Arduino
|(Recommended) Screw Terminal Block Shield for Arduino Uno
|(Optional) Transparent Acrylic Enclosure For Arduino Uno
Or you can buy the following sensor kit:
|DIYables Sensor Kit 30 types, 69 units
About Sound Sensor
The sound sensor can be utilized to detect the presence of sound in the surrounding environment. You can adjust the detection threshold (sensitivity) using a built-in potentiometer.
The sound sensor includes three pins:
- VCC pin: needs to be connected to VCC (3.3V to 5V)
- GND pin: needs to be connected to GND (0V)
- OUT pin: is an output pin: HIGH if quiet and LOW if sound is detected. This pin needs to be connected to Arduino's input pin.
The sound sensor also has a built-in potentiometer, which can be used to addjust the sensitivity of the sensor. Further more, it has two LED indicators:
- One LED indicator for power
- One LED indicator for the sound state: on when sound is present, off when quiet
How It Works
The module has a built-in potentiometer for setting the sound sensitivity.
- When the sound is detected, the output pin of the sensor is LOW
- When the sound is NOT detected, the output pin of the sensor is HIGH
This image is created using Fritzing. Click to enlarge image
The real wiring:
How To Program For Sound Sensor
- Initializes the Arduino pin to the digital input mode by using pinMode() function. For example, pin 5
- Reads the state of the Arduino pin by using digitalRead() function.
Arduino Code - Detecting the sound
- Copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to Arduino
- Clap your hand in front of the sound sensor
- See the result on Serial Monitor.
Please keep in mind that if you notice the LED status remaining on constantly or off even when there is sound, you can adjust the potentiometer to fine-tune the sound sensitivity of the sensor.
Now we can customize the code to activate an LED or a light when sound is detected, or even make a servo motor rotate. You can find more information and step-by-step instructions in the tutorials provided at the end of this tutorial.
If the sound sensor is not working properly, try the following steps:
- Reduce vibrations: The sound sensor is also sensitive to mechanical vibrations and wind noise. Mounting the sound sensor on a solid surface can help minimize these vibrations.
- Consider the sensing range: Keep in mind that this sound sensor has a short sensing range, around 10 inches. To obtain accurate readings, you will need to make a noise closer to the sound sensor.
- Check the power supply: Ensure that the power supply is clean, as the sound sensor is sensitive to power supply noise due to being an analog circuit.
We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.