ESP32 UNO - Sound Sensor
Need your ESP32 Uno to notice a clap or a loud bang? Connect a sound sensor to the ESP32 Uno form board and watch the Serial Monitor print a line each time a sound starts and stops. A sound detector module is cheap, and it needs only one signal wire.
By the end, you can:
- Wire a sound sensor to the ESP32 Uno at 3.3V
- Read the sensor output with digitalRead()
- Print a message when a sound starts and when it ends
- Tune the sensitivity with the on-board potentiometer

When this works, you can extend the sketch to switch on an LED, a lamp through a relay, or a servo motor each time the module hears a sound.
Components You Need
| 1 | × | ESP32 Uno-form Board | |
| 1 | × | USB Cable Type-A to Type-C (for USB-A PC) | |
| 1 | × | USB Cable Type-C to Type-C (for USB-C PC) | |
| 1 | × | Digital Sound Sensor | |
| 1 | × | Analog Sound Sensor | |
| 1 | × | Jumper Wires |
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of the Sound Sensor
By the end of this part, you know which module you hold and what each pin does.
| Module | Pins | Output |
|---|---|---|
| Digital sound sensor | VCC, GND, OUT | HIGH or LOW only |
| Analog sound sensor | +, G, DO, AO | HIGH or LOW on DO, changing voltage on AO |
Both modules carry a tiny trimmer that decides how loud a sound has to be to flip the digital pin.
Digital Sound Sensor Pinout
| Pin | Role |
|---|---|
| VCC | Power, 3.3V to 5V (use 3.3V with the ESP32 Uno) |
| GND | Ground (0V) |
| OUT | Signal. HIGH when quiet, LOW when a sound is heard |

The module also has two small LEDs. One shows power. The other lights up while the microphone hears a sound.
Analog Sound Sensor Pinout
| Pin | Role |
|---|---|
| + | Power. Feed it 3.3V from the ESP32 Uno |
| G | Ground (0V) |
| DO | Digital output. HIGH when quiet, LOW when a sound is heard |
| AO | Analog output. The voltage follows the sound level |

This module has the same potentiometer and the same two LEDs. The sketch on this page only uses the digital pin, so wire OUT (or DO) and ignore AO.
How It Works
The potentiometer sets a loudness threshold.
- Sound louder than the threshold: the output goes LOW.
- Sound quieter than the threshold: the output stays HIGH.
Good to know: The signal is flipped. A LOW reading in your sketch is a sound, and HIGH is silence.
ESP32 Uno Pinout
Match each Uno header label to its GPIO number in the picture before you place any wire. Your sketch uses the GPIO number, not the label.

How to Connect
Goal: the sensor gets power from 3.3V and sends its signal to D7.

This image is created using Fritzing. Click to enlarge image
| Module Pin | ESP32 Uno Pin |
|---|---|
| VCC | 3.3V |
| GND | GND |
| OUT | D7 (GPIO14) |
※ NOTE THAT:
The wiring diagram may not show the correct pin. On the ESP32 Uno, the sensor OUT goes to D7 (GPIO14), not D8 as the picture may show. We will update the diagram soon. Until then, follow the wiring table and the code on this page, not the picture.
Good to know: ESP32 Uno pins work at 3.3V and are not 5V tolerant. A sensor powered from 5V also outputs 5V on OUT, so keep it on 3.3V.
Programming the Sound Sensor
By the end of this part, you know the two functions the sketch needs.
Step 1 — Set the pin as an input
Use pinMode() once in setup(). Here the pin is GPIO14, the D7 header.
Step 2 — Read the pin
Call digitalRead() again and again in loop(). A LOW result means a sound.
Code
The sketch watches the sensor pin and prints a line only when its level changes, so one sound gives one "detected" line and one "disappeared" line.
| Code Part | What It Does |
|---|---|
| SENSOR_PIN 14 | Names the pin wired to OUT (D7, GPIO14) |
| prev_sound_state | Stores the level from the last pass |
| digitalRead(SENSOR_PIN) | Reads the new level, LOW means sound |
| HIGH to LOW change | Prints "The sound has been detected" |
| LOW to HIGH change | Prints "The sound has disappeared" |
Result: you get two clean messages per sound instead of a flood of lines.
Upload and Test
- First time with this board? Set it up with ESP32 Uno - Getting Started before you continue.
- Build the circuit by following the wiring table above.
- Plug in the USB Type-C cable between the ESP32 Uno and your computer.
- Select the board in Arduino IDE: pick ESP32 Dev Module and the COM port of the board (CH340).
- Copy the code above into a new sketch.
- Click the Upload button to send it to the board.
- Open the Serial Monitor, then pick 9600 baud in the drop-down.
- Clap once near the sensor and check the output.
- Pro tip: Hold the module in your hand and snap your fingers at about 5 cm. If the sound LED stays on in a quiet room, turn the potentiometer a little with a small screwdriver until it goes off.
Video Tutorial
See the ESP32 Uno build in action in the video below.
The demo counts your claps and starts a light show on a row of 8 LEDs: 1 clap = all blink, 2 claps = water wave, 3 claps = center to edges, 4 claps = random dance. These LEDs light up when their pin is pulled LOW (active-LOW wiring).
| Part | ESP32 Uno Pin |
|---|---|
| Sensor OUT | D10 (GPIO5) |
| LEDs 1-4 | D2 (GPIO26), D3 (GPIO25), D4 (GPIO17), D5 (GPIO16) |
| LEDs 5-8 | D6 (GPIO27), D7 (GPIO14), D8 (GPIO12), D9 (GPIO13) |
WARNING
This demo uses D10 (GPIO5) for the sensor OUT. The chip reads this pin at power-up. If the board does not boot or fails to upload, unplug the wire from D10, upload the code, then plug it back in. The LED on D8 goes to GND through a resistor, so it is safe.
ESP32 Uno vs UNO R4 for This Project
Moving this project from the UNO R4 to the ESP32 Uno changes the pin numbers and the voltage.
| Item | Arduino UNO R4 | ESP32 Uno |
|---|---|---|
| Logic voltage | 5V | 3.3V |
| Sensor OUT pin in code | 8 | 14 (D7) |
| Sensor power | 5V or 3.3V | 3.3V |
| Demo sensor pin | 10 | 5 (D10) |
| Arduino IDE board | Arduino UNO R4 WiFi | ESP32 Dev Module |
| Wireless | WiFi on the WiFi model | WiFi and Bluetooth built in |
The wiring stays on the same Uno header positions, so you can reuse the layout. Only the numbers in the code change, and the sensor must run from 3.3V.
Tips for Steadier Detection
A sound sensor is a small analog circuit, so its surroundings matter.
| Tip | Why It Helps |
|---|---|
| Turn the potentiometer in small steps | Tiny turns change the threshold a lot |
| Fix the module on a solid surface | Table bumps and wind are not counted as sounds |
| Test within about 10 inches (25 cm) | The microphone hears only nearby sounds |
| Use short wires and a stable supply | Power noise can trigger false alarms |
Go Wireless: Sound Alerts on Your Phone
Goal: see the sound events on your phone instead of a cable and a computer.
The ESP32 Uno has WiFi and Bluetooth, so the sensor can report to a browser or the DIYables Bluetooth app. Send "sound detected" lines to a wireless monitor, or plot the sound level over time.
Try These Next
- Turn on an LED while the sound LED is lit.
- Toggle a relay on every clap.
- Count claps and run a different action for each count.
Function References
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| No COM port in Arduino IDE | CH340 driver missing or charge-only cable | Install the CH340 driver and use a data USB cable |
| Upload fails with "Failed to connect" or "Waiting for download" | Board not in download mode | Hold the BOOT button while the upload starts |
| Serial Monitor shows garbage or stays empty | Baud rate does not match Serial.begin(9600) | Choose 9600 in the monitor |
| Nothing prints when you clap | Sensitivity too low or OUT on the wrong pin | Turn the potentiometer and check OUT goes to D7 (GPIO14) |
| Messages print in a silent room | Sensitivity too high or power noise | Turn the potentiometer back and use short wires |
| Power LED on the module is off | VCC or GND wire loose | Check the 3.3V and GND wires |
| Pin stops responding after a while | Sensor on 5V sends 5V into a 3.3V pin | Power the sensor from 3.3V |
| Random triggers when the motor or relay switches | Power noise on the supply | Power the sensor from a stable source and keep wires short |
FAQ
How does a digital sound sensor detect a clap?
A microphone on the module feeds a comparator. When the sound is louder than the level set by the potentiometer, the comparator pulls OUT LOW. The ESP32 Uno sees that change and prints a message.
Can I power the sound sensor from 5V with the ESP32 Uno?
The module runs at 5V, but then OUT also swings to 5V. ESP32 Uno pins are not 5V tolerant, so use the 3.3V pin or add a voltage divider on OUT.
Why does the code print "detected" when the pin goes LOW?
The module pulls its pin down when it hears something. In silence the pin rests at HIGH, so the sketch looks for the HIGH to LOW edge.
Can the sensor tell the difference between voices and claps?
No. It only reports that a sound passed the loudness threshold. Speech recognition needs a different module or library.
Can I use the AO pin of the analog sound sensor on the ESP32 Uno?
Yes. Connect AO to an analog header pin and read it with analogRead(). The ESP32 Uno ADC is 12-bit, so values run from 0 to 4095. Add analogSetAttenuation(ADC_11db); in setup() to read the full range up to about 3.3V.
Which pin can I use for the sensor besides D7?
Any normal digital pin works, for example D6 (GPIO27) or D9 (GPIO13). Avoid D0 and D1 because they carry the USB serial. Avoid boot strapping pins such as D8 (GPIO12) and D10 (GPIO5) when you can.
Can I use A2 to A5 for the sound sensor OUT pin?
Yes, as an input. A2 to A5 (GPIO35, 34, 36, 39) are input only and have no internal pull-up, which is fine for a sensor that drives the line itself.
Does analogRead() on A0 or A1 work when WiFi is on?
No. A0 (GPIO2) and A1 (GPIO4) are ADC2 pins, and ADC2 cannot be read while WiFi is on. For analog sound reading in a WiFi project, use A2 to A5 or GPIO32 and GPIO33.
Will the CH340 driver matter for this project?
Yes. The ESP32 Uno uses a CH340 USB chip. If no COM port appears, install the CH340 driver and try a data cable.
Can I show the sound events on a web page?
Yes. The ESP32 Uno has WiFi and Bluetooth. Use the web monitor or the Bluetooth app monitor from the Go Wireless section.
What if I run out of header pins for my project?
The ESP32 Uno has a few extra holes near the power header. GPIO32 and GPIO33 support I/O, PWM and analog on ADC1, so they also work while WiFi is on. GPIO15 supports I/O, PWM and analog on ADC2. Solder headers first, then use the GPIO number directly in your sketch. For a second sound sensor, use GPIO32 or GPIO33 first. Two warnings apply. First, GPIO15 and GPIO0 (the IO0 pin at the unused Uno NC position) are boot strapping pins, and a wrong connection can stop the board from booting or uploading code, so use GPIO32 and GPIO33 first. Second, never use the six holes under the digital header (SD0 to SD3, CMD, CLK = GPIO6 to GPIO11). They are wired to the flash chip, and using them crashes the board.