Example 32: Sound Sensor
About 1 min
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 Label | GPIO Pin | Connected Device |
|---|---|---|
| AO | GPIO34 | Sound sensor analog output |
| DO | GPIO4 | Sound sensor digital output (optional) |
JSON Configuration Example
{
"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
- Click Peripheral Config in the left menu → Switch to Peripheral Execution tab
- Click New Rule button
- Fill in basic configuration:
- Rule Name:
Voice-Controlled Light - Report Data: ✅ Enabled
- Enable: ✅ Enabled
- Rule Name:
Step 3: Configure Trigger (Polling Trigger)
Click Add Trigger button
Fill in trigger configuration:
Field Value Description Trigger Type Select Polling Trigger Periodic condition check Target Peripheral Select sound_01Sound sensor Polling Interval 100100ms (fast detection) Condition Expression value > 2500Sound intensity threshold
Step 4: Configure Action
Click Add Action button
Fill in:
- Action Type: Select Toggle Level
- Target Peripheral: Select
led_d1
Click Save button
Sound Sensor Value Reference
| Status | ADC Value | Description |
|---|---|---|
| Silence | ~2048 | Baseline value (midpoint) |
| Soft Sound | 2000-2500 | Slight sound |
| Normal Speech | 2500-3500 | Conversation volume |
| Loud Sound | >3500 | Clapping, shouting |
Notes
- Sensitivity: Module potentiometer adjusts sensitivity / digital output threshold
- Sampling Rate: Sound changes rapidly; 50-100ms sampling recommended
- Baseline Drift: Baseline values differ across environments with different ambient noise; calibration required
- Signal Amplitude: ADC reads ~2048 (midpoint) at silence; fluctuation range depends on volume
