Skip to content

Example 32: Sound Sensor ​

Experiment Overview ​

A sound sensor detects ambient sound intensity via an electret microphone, outputting an analog signal (sound level) and a digital signal (whether a threshold is exceeded). Suitable for voice-activated switches, noise monitoring, and similar applications.

Hardware Wiring ​

Board LabelGPIO PinConnected Device
AOGPIO34Sound sensor analog output
DOGPIO4Sound sensor digital output (optional)

JSON Configuration Example ​

json
{
  "peripherals": [
    {
      "id": "sound_01",
      "name": "Sound Sensor",
      "type": 15,
      "enabled": false,
      "pins": [34],
      "params": {}
    }
  ]
}

Peripheral Execution Linkage ​

Scenario: Voice-Controlled Light (Polling Trigger) ​

Feature: Toggle LED when sound is detected (ADC > 2500)

Web UI Configuration Steps ​

Step 1: Ensure LED Peripheral is Configured

  • Peripheral ID: led_d1
  • Type: GPIO Output

Step 2: Create Rule

  1. Click Peripheral Execution in the left menu
  2. Click New Rule button
  3. Fill in basic configuration:
    • Rule Name: Voice-Controlled Light
    • Report Data: ✅ Enabled
    • Enable: ✅ Enabled

Step 3: Configure Trigger (Polling Trigger)

  1. Click Add Trigger button

  2. Fill in trigger configuration:

    FieldValueDescription
    Trigger TypeSelect Polling TriggerPeriodic condition check
    Target PeripheralSelect sound_01Sound sensor
    Polling Interval100100ms (fast detection)
    Condition Expressionvalue > 2500Sound intensity threshold

Step 4: Configure Action

  1. Click Add Action button

  2. Fill in:

    • Action Type: Select Toggle Level
    • Target Peripheral: Select led_d1
  3. Click Save button

Sound Sensor Value Reference ​

StatusADC ValueDescription
Silence~2048Baseline value (midpoint)
Soft Sound2000-2500Slight sound
Normal Speech2500-3500Conversation volume
Loud Sound>3500Clapping, shouting

Notes ​

  1. Sensitivity: Module potentiometer adjusts sensitivity / digital output threshold
  2. Sampling Rate: Sound changes rapidly; 50-100ms sampling recommended
  3. Baseline Drift: Baseline values differ across environments with different ambient noise; calibration required
  4. Signal Amplitude: ADC reads ~2048 (midpoint) at silence; fluctuation range depends on volume

FastBee | fastbee.cn