Arduino MKR WiFi 1010 - Sound Sensor

A sound sensor is a fascinating component that detects noise and vibrations in its surroundings! You can create amazing sound-activated projects with the Arduino MKR WiFi 1010 and a sound sensor, like lights that turn on when you clap, voice-controlled devices, or even a pet feeder that responds to specific sounds.

In this comprehensive guide, you'll learn how to use the Arduino MKR WiFi 1010 with a sound sensor to build interactive projects. We'll cover everything you need to know about connecting a sound sensor to the Arduino MKR WiFi 1010 and programming it to respond to audio input.

What You'll Learn:

Real-World Applications:

Once you've mastered the basics, you can easily extend your Arduino MKR WiFi 1010 sound sensor project to control LEDs, activate relays for high-power devices, or even trigger servo motors based on detected sounds!

Arduino MKR WiFi 1010 sound sensor

Hardware Preparation

1×Arduino MKR WiFi 1010
1×Micro USB Cable
1×Digital Sound Sensor
1×Analog Sound Sensor
1×Breadboard
1×Jumper Wires
1×Optionally, 5V Power Adapter for ESP8266

Or you can buy the following 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 a simple yet powerful component that detects audio vibrations in its environment. Think of it as an electronic "ear" for your Arduino MKR WiFi 1010 projects!

There are two types of sound sensor modules available:

  • Digital sound sensor module: Provides a simple binary signal (HIGH or LOW). Perfect for projects that just need to know "was there a sound?" without measuring how loud it was.
  • Analog sound sensor module: Offers both analog output (measures sound intensity) and digital output (ON/OFF detection). This gives you more flexibility - you can measure how loud the sound is or just detect if any sound occurred.

Both types feature a built-in potentiometer (a small adjustable knob) that lets you easily adjust the sensitivity threshold. This is incredibly useful for fine-tuning your Arduino MKR WiFi 1010 sound sensor project to respond only to sounds above a certain volume level.

The Digital Sound Sensor Pinout

The digital sound sensor module has three pins that you'll connect to your Arduino MKR WiFi 1010:

  • VCC pin: Connects to your power supply. Works with both 3.3V and 5V, making it compatible with the Arduino MKR WiFi 1010's voltage levels.
  • GND pin: Connects to ground (0V) - complete the circuit by connecting this to your Arduino MKR WiFi 1010's GND pin.
  • OUT pin: The digital output pin that sends the detection signal to your Arduino MKR WiFi 1010. This pin stays HIGH when it's quiet and goes LOW when sound is detected. Connect this to any digital input pin on your Arduino MKR WiFi 1010.
Sound Sensor Pinout
image source: diyables.io

Helpful Features:

  • Sensitivity knob: The built-in potentiometer (small screw on the module) allows you to adjust how sensitive the sensor is. Turn it clockwise to make it less sensitive, counterclockwise to make it more sensitive.
  • LED indicators: Two helpful LEDs on the board:
    • Power LED: Lights up when the module is powered, confirming proper connection
    • Status LED: Lights up when sound is detected, making it easy to test and calibrate your sensor

    The Analog Sound Sensor Pinout

    The analog sound sensor module offers more versatility with four pins:

    • + pin: Connects to 5V power supply.
    • G pin: Connects to ground (0V).
    • DO pin: Digital output pin. Works the same as the digital sound sensor - HIGH when quiet, LOW when sound is detected. Connect this to a digital input pin on your Arduino MKR WiFi 1010.
    • AO pin: Analog output pin. This is the special feature of this module! It provides an analog voltage that varies with the sound intensity, letting you measure not just if there's sound, but how loud it is. Connect this to an analog input pin (A0-A5) on your Arduino MKR WiFi 1010.
    analog sound sensor Pinout
    image source: diyables.io

    The analog sensor gives you the best of both worlds - simple sound detection (digital output) and detailed sound level measurement (analog output). This makes it perfect for advanced Arduino MKR WiFi 1010 projects where you want to respond differently to quiet sounds versus loud sounds!

    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 MKR WiFi 1010 Sound Sensor

This image is created using Fritzing. Click to enlarge image

How To Program For Sound Sensor

  • This sets the Arduino MKR WiFi 1010 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 MKR WiFi 1010 pin is on or off using the digitalRead() function, which you can learn more about at [digitalRead()].
int soundState = digitalRead(D3);

Arduino MKR WiFi 1010 Code - Detecting the sound

/* * This Arduino MKR WiFi 1010 code was developed by newbiely.com * * This Arduino MKR WiFi 1010 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-mkr/arduino-mkr-wifi-1010-sound-sensor */ // Arduino's pin connected to OUT pin of the sound sensor #define SENSOR_PIN 5 int lastState = HIGH; // the previous state from the input pin int currentState; // 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: currentState = digitalRead(SENSOR_PIN); if (lastState == HIGH && currentState == LOW) Serial.println("The sound has been detected"); else if (lastState == LOW && currentState == HIGH) Serial.println("The sound has disappeared"); // save the the last state lastState = currentState; }

Detailed Instructions

New to Arduino MKR WiFi 1010? Complete our Getting Started with Arduino MKR WiFi 1010 tutorial first to set up your development environment.

  • Connect the components to the Arduino MKR WiFi 1010 board as depicted in the diagram
  • Plug your Arduino MKR WiFi 1010 into your computer's USB port
  • Launch the Arduino IDE on your computer
  • Select the Arduino MKR WiFi 1010 board and its 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 MKR WiFi 1010.
  • 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!