Introduction
In this tutorial we will be looking at how to get started with the digital sound sensor. This is an extremely easy to use module that only requires three connections. Namely the VIN and GND, and a single digital output. A potentiometer is used to set the sensitivity, or the threshold that triggers a sound detection.
Required hardware
- 1 X Digital sound sensor
- 1 X Arduino Nano
- 1 X NTEA-MD, Assembled
- 3 X Dupont wires, female-to-male
Setting up the hardware
We chose to interface the digital sound sensor with the Nano microcontroller (because it is one of our favorite microcontrollers!). The Nano is easy to use, powerful and has a small footprint. To make this project more elegant, we will not be using a breadboard, as is common practice. Instead we will use the NTEA-MD (assembled), which is a breakout board designed specifically for the Nano. This particular breakout board is the medium size of the three types in this series. With this setup there shouldn’t be any soldering and assembly will only take a couple minutes.
As an aside, you could substitute the NTEA-MD and dupont wires with a standard breadboard and jumper wires.
Finally, the connection couldn’t be simpler. Pop in the Nano into the NTEA-MD and connect the following wires:
- VCC pin on the sensor to the 3.3V pin on the Nano.
- GND pin on the sensor to GND pin on the Nano.
- Digital pin (labelled “out”) on the sensor to analog pin A3 on the Nano.
Wait, what?! Why are we connecting the digital out of the sensor to an analog pin on the Nano? Simply for aesthetics, and because we can. If you look at the NTEA-MD (or the Nano), the pinouts on the side of the 3.3V and GND only has a single digital pin – D13. We don’t want to use this pin because we want to use the same hardware setup we have in this tutorial in another tutorial on making the famous “Clapper” using the sound sensor (COMING SOON). On the Nano the analog pins can be used as digital pins (see note below). So using the analog pin A3 is done simply for convivence as this pin exists on the same side as the 3.3V and GND, and hence we don’t have any crossing wires.
Note: You can check out the official guideline on how to use analog pin as a digital from the Arduino website. For our consideration, the pins A6 and A7 on the Nano cannot be used as digital pins. While all other analog pins can.
Don’t forget to plug in the Mini-B USB into the Nano and your computer!
You might be wondering why we are using the 3.3V pin to power the sensor. The sensor accepts both 3.3V as well as 5V, so why not use 5V? From our experimentation we found that the current draw vs. VCC voltage is as follows:
VCC [V] | Pot | Digital Out | Trig LED | Current draw [mA] |
3.3 | CW | 1 | OFF | 3.9 |
3.3 | CCW | 0 | ON | 5.1 |
5 | CW | 1 | OFF | 7.2 |
5 | CCW | 0 | ON | 10.1 |
For not only look at the VCC and Current draw columns (the other columns will be discussed below). We can see that the current draw is lower using the 3.3V pin. If applicable, one should always keep the power budget in mind. Now in this case it doesn’t really matter as using either voltage results in minor differences, both of which are far away from the current rating of the Nano. But we still consider this to keep up good habits
Operation principles
A few words on the practical side of operating the digital sound sensor. Table 1 above shows columns labelled “Pot” (for potentiometer), “Digital Out”, and “Trig LED”. When the module is not triggered, the digital out is high, namely 1. At this state the trigger LED is also OFF. Conversely, when the module is triggered, the digital out is low, namely 0. And the trigger LED is ON. To help identify where the trigger LED is on the board, see Fig. 1 below.
When first powering the module, one has to play around with the potentiometer to find the sensitivity they need for their project. On one extreme end, if you turn the pot all the way clockwise (CW), the resistance is at a max, and the sensitivity is low. So low that nothing will trigger it – always OFF. Alternatively, on the other extreme end, if you turn the pot all the way counter-clockwise (CCW), the résistance is at a min, and the sensitivity is high. So high that everything will trigger it – always ON. Of course these extreme ends are not practical to work with, so tune the pot to be somewhere in the middle.
Setting up the software
It is assumed that the user has already installed the IDE software and is familiar how to select the correct settings in order to upload scripts to the Nano. If the user is not familiar with these steps, see our tutorial on first time using the Nano microcontroller.
We are not going to go into the details of the script, what each lines means, etc. For this getting started tutorial we are interested simply in getting the sensor to output some data. After that, the user can expand on the script and make more complicated projects!
Simply copy the following script into the IDE software.
// Project title: "Tutorial: Getting started with the digital sound sensor"
// Date of last edit: Dec 6 2021, PTSolns
// For bugs or questions please send us an email at contact@PTSolns.com
// Overview: This is the script for the digital sound sensor. Set up the hardware as outlined in the tutorial:
void setup() {
Serial.begin(9600);
pinMode(A3, INPUT); // Recall, we are using the analog pin A3 as an digital input pin. No problem!
}
void loop() {
int statusSensor = digitalRead(A3);
Serial.print("Detection = ");
Serial.println(statusSensor);
}
Results and conclusion
Upon uploading the script and opening the serial monitor, the user should see something similar to the following.
To obtain the results above, we tuned the pot so that it is just on the boundary between outputting 1 (not triggered) when no sound is present, and outputting 0 (triggered) still when no sound is present. This setting is somewhere in the middle. When you find it, turn the pot clockwise just a tiny amount. In the results image above you can see mostly 1, which is as explained above the OFF state. There are a couple 0, which is when I rapidly clapped. Note that the script doesn’t have any delays, so the serial monitor goes by very fast. You can expand on this tutorial as required. This sensor can be used when a sound is to trigger some event. Maybe an alarm for when a door opens, or a light turning on when someone claps twice. The ladder is exactly the topic of the next tutorial on this digital sound sensor. Namely a tutorial on making “The Clapper” with the digital sound sensor. Enjoy!