There are a couple of different options to do sound detection. One provides a simple digital signal when the sound passes a threshold. The other provides a threshold digital signal as well as an analog amplitude signal.
Digital Sound Detection Option
You can pick these sensors up for about $1 apiece on Amazon.
The sound detection sensor detects whether sound has exceeded a threshold value. Sound is detected via microphone and fed into an LM393 op amp. The sound level set point is adjusted via an on board potentiometer. When the sound level exceeds the set point, an LED on the module is illuminated and the output is set low.
Specifications of sound detection sensor module:
- Working voltage: DC 3.3-5V
- Adjustable Sensitivity
- Dimensions: 32 x 17 mm
- Signal output indication LED
- Single channel output in the form of digital switching outputs (0 and 1 high and low)
- Outputs low level and the signal light when there is sound
Schematic Diagram
The circuit
The program
The Pico MicroPython program to access the signal via any GPIO port. In this case we will use GPIO 16.
from machine import Pin
import utime
di=Pin(16,Pin.IN)
def sound_handler(pin):
utime.sleep_ms(100)
if pin.value()==False:
print("ALARM! Sound detected!")
di.irq(trigger=machine.Pin.IRQ_RISING,handler=sound_handler)
This is a simple program that prints “Alarm! Sound detected” when the interrupt is triggered. You could do the sensing in a main loop as well. You will want to adjust the pot on the sound sensor board to get the desired level of sensitivity. I looked at using the one that also had analog output, but it output an analog audio signal that is more difficult to sense effectively and those boards cost slightly more as well.