Community project

ESP32 Light Sound Effects

Photo of ESP32 Light Sound Effects
Generated with AI

Symel Pangantihon

Published December 4, 2026

This project combines LEDs and a piezo buzzer with an Arduino to create interactive light and sound effects triggered by push buttons. Three buttons control different modes: one plays a melodic sequence with synchronized light patterns, another activates an alarm with rapid flashing and tones, and the third stops all effects. The guide includes a complete wiring diagram showing how to connect the LEDs, resistors, buzzer, and buttons to the Arduino, plus a parts list and ready-to-upload firmware with no external libraries required.

Builders will learn how to debounce button inputs, synchronize visual and audio timing, and manage multiple modes with a state machine. The firmware is fully commented and easy to customize—adjust the light speed, tone duration, note frequencies, or add new button-controlled effects. Assembly takes about 30 minutes, and the result is a fun, responsive device perfect for learning Arduino basics or adding to a larger project.

Wiring diagram

Loading diagram…

Gather all the parts

QtyComponent
1

LED

red

Standard 3mm/5mm through-hole LED. A current-limiting series resistor is added automatically.

1

LED

yellow

Standard 3mm/5mm through-hole LED. A current-limiting series resistor is added automatically.

1

LED

green

Standard 3mm/5mm through-hole LED. A current-limiting series resistor is added automatically.

1

Resistor

220 Ω

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

220 Ω

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

220 Ω

Through-hole resistor (current-limiting in series with an LED)

1

Piezo Buzzer

Small passive piezo buzzer (TDK PS1240) for beeps, tones and alerts. It has no built-in oscillator, so drive one lead with a 3-30 V square wave from a microcontroller pin using tone() or PWM and connect the other lead to ground. It is loudest around 4 kHz and works from about 2 to 10 kHz; driving both leads in antiphase roughly doubles the volume.

1

Push Button

Momentary push button switch

1

Push Button

Momentary push button switch

1

Push Button

Momentary push button switch

Assemble it in 4 steps

1. Place the components

With USB unplugged, place three LEDs, three 220 ohm resistors, three plain momentary buttons and the passive piezo on a solderless breadboard. Place four-leg buttons across the centre gap.

2. Connect the common ground

Connect Uno GND to the breadboard ground rail. Connect each LED short leg, the piezo return and one switched side of each button to this rail. Bridge split rails if needed.

3. Connect the lights

Connect D8 through rRed to the red LED long leg. Connect D9 through rYellow to the yellow LED long leg. Connect D10 through rGreen to the green LED long leg.

  • Never connect an LED directly to a digital pin without its series resistor.

4. Connect the sound and controls

Connect the piezo signal lead to D6. Connect the other switched side of Melody to D2, Alarm to D4 and Stop to D7. Use terminals that connect only when pressed; same-side legs on many four-leg switches are already joined.

  • Internal pull-up resistors mean no external button resistors or 5V button wires are needed.
  • Use a passive piezo
  • not a powered active buzzer or a low-impedance speaker.

Review all connections

1. Connections between "rRed" and "Arduino"

FunctionrRedArduino
digitalP1GPIO 8
digitalP2 → LED ANODEEXT

2. Connections between "red" and "Arduino"

FunctionredArduino
groundGNDGND

3. Connections between "rYellow" and "Arduino"

FunctionrYellowArduino
digitalP1GPIO 9
digitalP2 → LED ANODEEXT

4. Connections between "yellow" and "Arduino"

FunctionyellowArduino
groundGNDGND

5. Connections between "rGreen" and "Arduino"

FunctionrGreenArduino
digitalP1GPIO 10
digitalP2 → LED ANODEEXT

6. Connections between "green" and "Arduino"

FunctiongreenArduino
groundGNDGND

7. Connections between "piezo" and "Arduino"

FunctionpiezoArduino
pwmSIGGPIO 6
groundGNDGND

8. Connections between "melody" and "Arduino"

FunctionmelodyArduino
digitalSIGNALGPIO 2
groundGNDGND

9. Connections between "alarm" and "Arduino"

FunctionalarmArduino
digitalSIGNALGPIO 4
groundGNDGND

10. Connections between "stop" and "Arduino"

FunctionstopArduino
digitalSIGNALGPIO 7
groundGNDGND

Deploy the firmware

#include <Arduino.h>

// Light & Sound Effects System. No extra libraries required.
const byte LED_PINS[] = {8, 9, 10}; // Red, yellow, green
const byte BUTTON_PINS[] = {2, 4, 7}; // Melody, alarm, stop
const byte BUZZER_PIN = 6;
const unsigned long STEP_MS = 240; // Change this to adjust light speed.
const unsigned long TONE_MS = 180; // Keep below STEP_MS for a gap.
const unsigned long DEBOUNCE_MS = 25;
// High notes suit a small passive piezo better than bass notes.
const unsigned int NOTES[] = {2093, 2349, 2637, 2794, 3136, 2794, 2637, 2349};
enum Mode {IDLE, MELODY, ALARM};
Mode mode = IDLE;
byte stepIndex = 0;
unsigned long nextStep = 0;
bool rawState[3] = {HIGH, HIGH, HIGH};
bool stableState[3] = {HIGH, HIGH, HIGH};
unsigned long changedAt[3] = {0, 0, 0};

void lightsOff() {
  for (byte i = 0; i < 3; ++i) digitalWrite(LED_PINS[i], LOW);
}
void selectMode(Mode selected) {
  noTone(BUZZER_PIN);
  lightsOff();
  mode = selected;
  stepIndex = 0;
  nextStep = millis(); // Start immediately, not after one interval.
}
// Return true once per press after the contacts have settled.
bool pressed(byte i, unsigned long now) {
  bool reading = digitalRead(BUTTON_PINS[i]);
  if (reading != rawState[i]) {
    rawState[i] = reading;
    changedAt[i] = now;
  }
  if (now - changedAt[i] >= DEBOUNCE_MS && reading != stableState[i]) {
    stableState[i] = reading;
    return reading == LOW; // INPUT_PULLUP makes a press read LOW.
  }
  return false;
}
void setup() {
  for (byte i = 0; i < 3; ++i) {
    pinMode(LED_PINS[i], OUTPUT);
    pinMode(BUTTON_PINS[i], INPUT_PULLUP);
  }
  pinMode(BUZZER_PIN, OUTPUT);
  lightsOff();
}
void loop() {
  unsigned long now = millis();
  bool melodyPressed = pressed(0, now);
  bool alarmPressed = pressed(1, now);
  bool stopPressed = pressed(2, now);
  // Stop has priority, including while held down.
  if (stopPressed || stableState[2] == LOW) selectMode(IDLE);
  else if (alarmPressed) selectMode(ALARM);
  else if (melodyPressed) selectMode(MELODY);

  // No delay(): buttons remain responsive during both effects.
  if (mode == IDLE || (long)(now - nextStep) < 0) return;
  nextStep = now + STEP_MS;
  lightsOff();
  if (mode == MELODY) {
    digitalWrite(LED_PINS[stepIndex % 3], HIGH);
    tone(BUZZER_PIN, NOTES[stepIndex], TONE_MS);
    if (++stepIndex >= 8) stepIndex = 0; // Repeat until stopped.
  } else {
    bool on = (stepIndex % 2 == 0);
    digitalWrite(LED_PINS[0], on ? HIGH : LOW);
    tone(BUZZER_PIN, on ? 2400 : 3200, TONE_MS);
    stepIndex ^= 1;
  }
}

Remix this project

Make it yours in one click

Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.

Open in Schematik