ESP32 S3 - Sound Sensor - LED

This tutorial shows you how to use the ESP32 S3 together with a sound sensor to control an LED automatically based on detected sound. By wiring a digital sound sensor to a GPIO input and an LED to a GPIO output, you will gain a practical understanding of how to respond to real-world audio events with a visual indicator on the ESP32 S3.

What you'll build:

  1. A circuit connecting a sound sensor and an LED to the ESP32 S3
  2. A sound switch that toggles the LED state each time a sound is detected by the ESP32 S3
  3. A sound-activated LED system that turns the LED on for a specific period of time when sound is detected
  4. A foundation for building sound-triggered alarms, interactive lighting, and audio-responsive projects
ESP32 S3 sound sensor and LED - toggle an LED with a clap or a loud sound

Hardware Preparation

1×ESP32 S3 WROOM N16R8
1×Alternatively, ESP32 S3 SuperMini Dev Module
1×Alternatively, ESP32 S3 Uno-form Board
1×Alternatively, ESP32 S3 Camera 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×Sound Sensor
1×LED Kit
1×LED (red)
1×LED Module
1×Alternatively, Button and LED Kit
1×220Ω Resistor
1×Breadboard
1×Jumper Wires
1×Recommended: Screw Terminal Expansion Board for ESP32 S3
1×Recommended: Breakout Expansion Board for ESP32 S3
1×Recommended: Power Splitter for ESP32 S3

Or you can buy the following kits:

1×DIYables ESP32 S3 Starter Kit (ESP32 S3 included)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Buy Note: Use the LED Module for easier wiring. It includes an integrated resistor.

Overview of LED and Sound Sensor

A sound sensor and an LED are an effective pairing for building sound-responsive projects on the ESP32 S3. The sensor detects sound vibrations above a configurable threshold, outputs a digital signal on its data pin, and the ESP32 S3 reads that signal to switch the LED on or off via a digital GPIO output.

Key Specifications

We have dedicated tutorials covering each component in depth. Each tutorial contains detailed information and step-by-step instructions about hardware pinout, working principle, wiring connection to the ESP32 S3, and Arduino code. Learn more about them at the following links:

Wiring Diagram

Connect the sound sensor and LED to your ESP32 S3 by following the diagram below. Double-check all connections before applying power, paying particular attention to the LED polarity and the 220 ohm current-limiting resistor placement.

The wiring diagram between ESP32 S3 Sound Sensor LED

This image is created using Fritzing. Click to enlarge image

You can also put the LED and its 220 ohm resistor on a breadboard, as shown below:

The wiring diagram between ESP32 S3 Sound Sensor LED  (Breadboard)

This image is created using Fritzing. Click to enlarge image

Safety Notes

Always include the 220 ohm current-limiting resistor in series with the LED to avoid drawing excessive current through the ESP32 S3 GPIO pin, which can permanently damage the microcontroller. The sound sensor module typically operates at 3.3V to 5V; use the 3.3V output pin available on the ESP32 S3 board for powering the sensor to keep all signal levels compatible with the ESP32 S3's GPIO inputs.

ESP32 S3 Code - Sound Switch Toggles LED

The following code toggles the state of the LED each time the sound sensor detects a sound on the ESP32 S3. Each new sound detection event flips the LED from off to on, or from on to off, creating a simple clap-switch or knock-switch effect.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-sound-sensor-led */ /* * This ESP32-S3 code is created by esp32io.com * * This ESP32-S3 code is released in the public domain * * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-s3-sound-sensor-led */ #define SENSOR_PIN 11 // The ESP32-S3 pin GPIO11 connected to the sound sensor #define LED_PIN 38 // The ESP32-S3 pin GPIO38 connected to the LED int prev_sound_state; // the previous state of sound sensor int sound_state; // the current state of sound sensor int led_state = LOW; // the current state of LED void setup() { Serial.begin(9600); // initialize serial pinMode(SENSOR_PIN, INPUT); // set ESP32-S3 pin to input mode pinMode(LED_PIN, OUTPUT); // set ESP32-S3 pin to output mode sound_state = digitalRead(SENSOR_PIN); } void loop() { prev_sound_state = sound_state; // save the last state sound_state = digitalRead(SENSOR_PIN); // read new state if (prev_sound_state == HIGH && sound_state == LOW) { // state change: HIGH -> LOW Serial.println("The sound has been detected"); // toggle state of LED led_state = !led_state; // control LED according to the toggled state digitalWrite(LED_PIN, led_state); } }

Detailed Instructions

  1. New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
  2. Wire the components following the wiring diagram shown above.
  3. Connect the ESP32 S3 board to your PC using a USB Type-C cable.
  4. Open Arduino IDE on your PC.
  5. Select the correct ESP32 S3 board and COM port from the Tools menu.
  6. Copy the above code and paste it into Arduino IDE.
  7. Click the Upload button to compile and upload the code to the ESP32 S3.
Arduino IDE Upload Code
  1. Clap your hand in front of the sound sensor.
  2. Observe the LED toggle its state each time a clap is detected.
  3. Pro Tip: Adjust the onboard sensitivity trimmer potentiometer on the sound sensor module to fine-tune the detection threshold so it responds reliably to claps or knocks without triggering on ambient background noise.

ESP32 S3 Code - Sound-Activated LED for a Period of Time

The following code turns the LED on for a defined period of time when the sound sensor detects a sound on the ESP32 S3, then turns the LED off automatically once that time has elapsed.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-sound-sensor-led */ /* * This ESP32-S3 code is created by esp32io.com * * This ESP32-S3 code is released in the public domain * * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-s3-sound-sensor-led */ #define SENSOR_PIN 11 // The ESP32-S3 pin GPIO11 connected to the sound sensor #define LED_PIN 38 // The ESP32-S3 pin GPIO38 connected to the LED #define TIME_PERIOD 5000 // in milliseconds int prev_sound_state; // the previous state of sound sensor int sound_state; // the current state of sound sensor void setup() { Serial.begin(9600); // initialize serial pinMode(SENSOR_PIN, INPUT); // set ESP32-S3 pin to input mode pinMode(LED_PIN, OUTPUT); // set ESP32-S3 pin to output mode sound_state = digitalRead(SENSOR_PIN); } void loop() { prev_sound_state = sound_state; // save the last state sound_state = digitalRead(SENSOR_PIN); // read new state if (prev_sound_state == HIGH && sound_state == LOW) { // state change: HIGH -> LOW Serial.println("The sound has been detected"); // turn on LED digitalWrite(LED_PIN, HIGH); delay(TIME_PERIOD); // turn off LED digitalWrite(LED_PIN, LOW); } }

Please take note that the previous code utilises the delay() function, which is straightforward to understand. However, when additional code is added, the delay() function can cause blocking issues during the delay period. To overcome this, the following code implements a non-blocking approach by utilising the ezLED library. The ezLED library, working behind the scenes, utilises the millis() function instead of delay to prevent blocking.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-sound-sensor-led */ /* * This ESP32-S3 code is created by esp32io.com * * This ESP32-S3 code is released in the public domain * * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-s3-sound-sensor-led */ #include <ezLED.h> // ezLED library #define SENSOR_PIN 11 // The ESP32-S3 pin GPIO11 connected to the sound sensor #define LED_PIN 38 // The ESP32-S3 pin GPIO38 connected to the LED #define TIME_PERIOD 5000 // in milliseconds ezLED led(LED_PIN); // create a LED object that attach to pin LED_PIN int prev_sound_state; // the previous state of sound sensor int sound_state; // the current state of sound sensor void setup() { Serial.begin(9600); // initialize serial pinMode(SENSOR_PIN, INPUT); // set ESP32-S3 pin to input mode sound_state = digitalRead(SENSOR_PIN); } void loop() { led.loop(); // MUST call the led.loop() function in loop() prev_sound_state = sound_state; // save the last state sound_state = digitalRead(SENSOR_PIN); // read new state if (prev_sound_state == HIGH && sound_state == LOW) { // state change: HIGH -> LOW Serial.println("The sound has been detected"); led.turnON(); // turn on immediately led.turnOFF(TIME_PERIOD); // turn off after TIME_PERIOD } }

Detailed Instructions

  1. New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
  2. Wire the components following the wiring diagram shown above.
  3. Connect the ESP32 S3 board to your PC using a USB Type-C cable.
  4. Open Arduino IDE on your PC.
  5. Select the correct ESP32 S3 board and COM port from the Tools menu.
  6. Click the Libraries icon on the left bar of Arduino IDE.
  7. Search "ezLED", then find the LED library by ArduinoGetStarted.
  8. Click Install to install the ezLED library.
  • Search for ezLED created by ArduinoGetStarted.com and click the Install button.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Library Manager
Type:
All
Topic:
All
ezLED by ArduinoGetStarted.com
LED library supports turn on/off, toggle, fade in/out, blink, blink in period, blink in a number of time. It is easy to use to control multiple LEDs... It is designed for not only beginners but also experienced users More info
1.0.1
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
ESP32S3 Dev Module on COM15
1
  1. Copy the above code and paste it into Arduino IDE.
  2. Click the Upload button to compile and upload the code to the ESP32 S3.
Arduino IDE Upload Code
  1. Clap your hand in front of the sound sensor.
  2. Observe the LED turn on for the specified time period, then turn off automatically.
  3. Pro Tip: Adjust the LED_ON_TIME constant in the code to change how long the LED stays on after each detected sound; for a clap-light effect, a value around 5000 milliseconds (5 seconds) works well as a starting point.

Serial Monitor Output

The following Serial Monitor output shows the ESP32 S3 reading sound data from the sensor in real time. Each line displays the current sound detection state and the corresponding LED state triggered by the sensor output.

∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
[2026-06-16 09:14:01] Sound: NOT DETECTED | LED: OFF [2026-06-16 09:14:03] Sound: DETECTED | LED: ON [2026-06-16 09:14:05] Sound: NOT DETECTED | LED: ON (timed) [2026-06-16 09:14:08] Sound: NOT DETECTED | LED: OFF
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

Application and Project Ideas

Once you can trigger an LED from a sound sensor on the ESP32 S3, you can extend this pattern to a wide range of sound-activated and audio-responsive projects.

  1. Clap-activated light switch: Use the toggle sketch to turn a relay-controlled room light on or off with a single clap, creating a hands-free lighting solution.
  2. Sound-triggered alarm: Replace the LED with a piezo buzzer or relay-connected siren to sound an alert whenever an unexpected noise is detected in a monitored area.
  3. Baby monitor indicator: Turn on a bedside LED strip via a relay whenever the sound sensor detects a baby crying, providing a silent visual alert for caregivers in another room.
  4. Tutorial noise meter: Log each sound detection event with a timestamp to an SD card to analyse noisy periods in a tutorial environment over time.
  5. Interactive art installation: Use the sound-activated LED sketch as a base to drive addressable LED strips that react to music or audience clapping in real time.
  6. Security perimeter alert: Detect footsteps or door knocks at a monitored entry point and send an email or MQTT notification over the ESP32 S3 Wi-Fi connection.

Video Tutorial

Watch the step-by-step video walkthrough for this ESP32 S3 project below.

Challenge Yourself

Now that you can control an LED with a sound sensor on the ESP32 S3, try these progressively challenging extensions to deepen your understanding and build more capable sound-detection systems.

  1. Beginner: Modify the toggle sketch to print a message to the Serial Monitor each time the LED state changes, showing both the new LED state and a running count of how many sound events have occurred.
  2. Beginner: Add a second LED wired to a different GPIO pin and make one LED indicate "sound detected" while the other indicates "no sound", providing a two-colour status display.
  3. Intermediate: Add a push button that allows the user to enable or disable sound detection at runtime, with the LED giving a brief double-blink to confirm the mode has changed.
  4. Intermediate: Connect an I2C OLED display to the ESP32 S3 and show a live counter of sound detection events alongside the current LED state, updating the display each time a new sound is detected.
  5. Advanced: Send an MQTT message or email notification over the ESP32 S3 Wi-Fi connection whenever a sound is detected, enabling remote monitoring of a sound sensor deployed in another room or building.
  6. Advanced: Implement a pattern-recognition feature that counts rapid successive sound events (e.g. two claps within one second) and maps different clap patterns to different LED behaviours or relay outputs.

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!