Arduino Nano 33 IoT - Sound Sensor

The sound sensor can sense sounds nearby. It can be used to create cool projects that react to noise, like lights that turn on when you clap or a pet feeder that works when it hears a sound.

In this guide, we will learn how to use the Arduino Nano 33 IoT and a sound sensor to pick up sounds. We will look at the following topics:

After that, you can easily change the code so that it turns on an LED or a light (with a relay) when it hears a sound, or even makes a servo motor move.

Arduino Nano 33 IoT sound sensor

Hardware Preparation

1×Arduino Nano 33 IoT
1×Micro USB Cable
1×Digital Sound Sensor
1×Analog Sound Sensor
1×Breadboard
1×Jumper Wires
1×Optionally, 5V Power Adapter for ESP8266
1×Recommended: Screw Terminal Expansion Board for Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter for Arduino Nano

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

A sound sensor is used to pick up noises in the area around it. There are two kinds of sound sensor modules:

  • Digital sound sensor module – It gives you a simple signal that is either ON or OFF.
  • Analog sound sensor module – It gives you both a continuous signal (analog) and a simple ON/OFF signal (digital).

You can change the sensitivity of the digital output using a built-in potentiometer.

The Digital Sound Sensor Pinout

This sound sensor has three pins.

  • VCC pin: Connect this pin to a power supply between 3.3V and 5V.
  • GND pin: Connect this pin to ground (0V).
  • OUT pin: This pin sends a signal— it shows HIGH when it is quiet and LOW when sound is detected. Connect it to an input pin on the Arduino Nano 33 IoT.
Sound Sensor Pinout
image source: diyables.io

The sound sensor has a useful built-in knob that lets you easily change its sensitivity. It also includes two LED lights.

  • One LED light shows if the power is on.
  • Another LED light shows the sound status—it lights up when sound is detected and turns off when it is quiet.

The Analog Sound Sensor Pinout

This analog sound sensor has four pins.

  • + pin: Connect this to 5V power.
  • G pin: Connect this to ground (0V).
  • DO pin: This is a digital output. It shows HIGH when there is no sound and LOW when sound is detected. Connect it to a digital input on the Arduino Nano 33 IoT.
  • AO pin: This is an analog output. It sends an analog signal that shows the sound level. Connect it to an analog input on the Arduino Nano 33 IoT.
analog sound sensor Pinout
image source: diyables.io

How It Works

This module has an easy-to-use built-in knob that lets you change the sound sensitivity. Here is how the sensor's output pin works:

  • When sound is heard, the output pin is set to LOW.
  • When no sound is heard, the output pin is set to HIGH.

Wiring Diagram

The wiring diagram between Arduino Nano and 33 IoT Sound Sensor

This image is created using Fritzing. Click to enlarge image

※ NOTE THAT:

Please note that the Arduino Nano 33 IoT pins A4 and A5 have built-in pull-up resistors for I2C communication. Although these pins can be used as digital input pins, it is recommended to avoid using them for digital input. If you must use them, do not use internal or external pull-down resistors for these pins

How To Program For Sound Sensor

  • This sets the Arduino Nano 33 IoT pin to act as a digital input using the pinMode() function. For example, you can use pin D3.
pinMode(3, INPUT);
  • It checks if the Arduino Nano 33 IoT pin is on or off using the digitalRead() function, which you can learn more about at [digitalRead()].
int soundState = digitalRead(D3);

Arduino Nano 33 IoT Code - Detecting the sound

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-sound-sensor */ #define SENSOR_PIN 3 // The Arduino Nano 33 IoT pin D3 connected to the 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 the Serial to communicate with the Serial Monitor. Serial.begin(9600); // initialize the Arduino Nano 33 IoT's pin as an input pinMode(SENSOR_PIN, INPUT); } void loop() { // read the state of the the Arduino Nano 33 IoT's 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

If you are new to the Arduino Nano 33 IoT, be sure to check out our Getting Started with Arduino Nano 33 IoT tutorial. Then, follow these steps:

  • Connect the components to the Arduino Nano 33 IoT board as depicted in the diagram.
  • Use a USB cable to connect the Arduino Nano 33 IoT board to your computer.
  • Launch the Arduino IDE on your computer.
  • Select the Arduino Nano 33 IoT board and choose its corresponding COM port.
  • Copy the above code and open it in the Arduino IDE.
  • Click the Upload button in the Arduino IDE to send the code to the Arduino Nano 33 IoT.
  • Clap your hands near the sound sensor.
  • Check the result in 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 the LED staying on or off, even when there is sound, you might need to adjust the potentiometer to change how sensitive the sensor is to sound.

Now, we can change the code to make an LED or light turn on when sound is heard. We can even make a servo motor move depending on the sound. For more details and easy step-by-step instructions, check the tutorials at the end of this guide.

Troubleshooting

If you have any problem with the sound sensor, please try these steps to fix it:

  • Reduce vibrations: Mechanical shaking and wind can affect the sound sensor. To lessen these issues, mount the sensor on a solid, steady surface.
  • Consider the sensing range: This sound sensor only detects sounds within about 10 inches. For best results, keep the sound source close to the sensor.
  • Check the power supply: Make sure the power supply is clean and free from interference since the sensor is sensitive to any noise in the power signal.

Video Tutorial

Function References

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!