Hi. This is a new forum, and for now you can post without registration.
Feel free to ask any questions. We are all here to help each other.

Smart Home Automation project competition

Starting with 2018 we will hold quarterly Smart Home Automation project competitions! There will also be prizes for the winners!
Read more in the official Competition topic.

Sound detection

All kind of sensors you can use to interact with the enviroment
User avatar
Posts: 47
Joined: Fri Nov 10, 2017 11:56 am
x 3

Sound detection

Post by oTp » Mon Nov 20, 2017 12:41 pm

For detecting sounds in the enviroment, you ca use a simple module like this: https://www.aliexpress.com/item/Sound-D ... 63195.html

It has a digital and analog output, onboard amplifier, and analog output level setting.

For a simple "clap" or "word" detection, you can use the digital output pin, and set the threshold to a suitable value with the potentiometer on the sensor.
Use a simple code like this, to detect the activation:

Code: Select all

const byte interruptPin = 13;
volatile byte interruptCounter = 0;
void setup() {
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, FALLING);
void handleInterrupt() {
void loop() {
      interruptCounter = 0;
      Serial.print("Sound detected!");
Keep in mind a simple code like this will trigger multiple times on a single sound event, so you will have to do some further filtering and timeouts for a more practical implementation.

If you would like to do some kind of noise measurements, than use the analog output.
You can use an AD converter, and average the readings, or add an external resistor and capacitor, to smooth out the level and then read the voltage with AD converter.