Sound Sensor

Sound Sensor


This sensor is sensitive to sound intensity.

It can be used to detect noises.


It outputs an analog sine wave.

The louder the sound the larger the magnitude of the sine wave.

A higher peak amplitude means louder sound.

Voltage Range

3 - 5V

Interface Type

Analog Input

Example Usage

from microbit import *


SAMPLE_WT = 0.01 # each new value has a 1% significance

def calc_avg(avg, new_val):
    return  avg * (1 - SAMPLE_WT) + new_val * SAMPLE_WT

def read_sound():
    return pin0.read_analog()

# average starts at the first sensor value
avg_sound = read_sound()

while True:
    sound_val = read_sound()

    variation = sound_val - avg_sound

    if variation > LOUD_THRESHOLD or variation < -LOUD_THRESHOLD:
        # loud noise detected
        # something

    avg_sound = calc_avg(avg_sound, sound_val)