Double-clap light switch
Clap twice and the lights come on. Clap twice again to switch them off.
Shop by category
Shop all componentsTurn ambient noise into a moving row of LEDs, so the room's volume becomes something you can see. A microphone signal swings above and below a resting midpoint, so a single analogRead() tells you almost nothing, catch it mid-swing and a loud sound reads as silence. Instead the sketch samples repeatedly for 50 ms and keeps the largest and smallest values seen, then uses the difference between them. That peak-to-peak amplitude is a genuine measure of loudness, and it is the foundation of every sound experiment in this level.
The ESP32 is a 3.3V board: never connect a 5V signal straight to a GPIO pin.
Every part for this build comes in the Geekobot Titan Kit box, a Geekobot exclusive, together with the parts for all 120 projects, from a first blinking LED to a smart fan and a reaction game. The wiring below is the kit's own wiring.
Tick anything you already have and the total updates.
ESP32 DevKit V1 (38-pin): the brain of every Titan Kit project, with Wi-Fi and Bluetooth
Male-to-female and female-to-female leads for the modules
LEDs from the kit's red, green, yellow and blue packs
220 ohm resistors: one in series with every LED
Sound sensor module: AO gives the loudness, DO switches at the knob setting
ESP32 expansion board from the kit: every GPIO has its own S, V, G header
Follow the colours: red is power, dark grey is ground, blue is a signal.
titan_kit_051_sound_level_bar_graph.inoVerify & upload in Electrolarkint micPin = 34;
int ledPins[10] = {12, 14, 27, 26, 25, 33, 32, 5, 23, 19};
int sampleWindow = 50; // ms of sampling per reading
int quietLevel = 20; // Peak-to-peak in a silent room
int loudLevel = 400; // Peak-to-peak when shouting
int readAmplitude()
{
unsigned long start = millis();
int highest = 0;
int lowest = 1023;
while (millis() - start < sampleWindow)
{
int sample = analogRead(micPin);
if (sample > highest) highest = sample;
if (sample < lowest) lowest = sample;
}
return highest - lowest;
}
void setup()
{
analogReadResolution(10); // ESP32 is 12-bit; use 0-1023 like the examples
for (int i = 0; i < 10; i++)
{
pinMode(ledPins[i], OUTPUT);
}
Serial.begin(9600);
}
void loop()
{
int amplitude = readAmplitude();
int level = map(amplitude, quietLevel, loudLevel, 0, 10);
level = constrain(level, 0, 10);
for (int i = 0; i < 10; i++)
{
digitalWrite(ledPins[i], i < level);
}
Serial.print("Amplitude: ");
Serial.print(amplitude);
Serial.print(" Bars: ");
Serial.println(level);
}
Use a micro-USB data cable (some cables only charge), install the CP210x or CH340 driver if no port appears, pick Tools > Board > ESP32 Dev Module and hold the BOOT button on the board until the upload starts.
Turn it round: the long leg (anode) goes to the GPIO side through the 220 ohm resistor, the short leg to GND.
Use the sensor's AO pin on GPIO34 and turn the blue trim pot: the module's LED should flicker when you clap.
A microphone signal swings above and below a resting midpoint, so a single analogRead() tells you almost nothing, catch it mid-swing and a loud sound reads as silence. Instead the sketch samples repeatedly for 50 ms and keeps the largest and smallest values seen, then uses the difference between them. That peak-to-peak amplitude is a genuine measure of loudness, and it is the foundation of every sound experiment in this level.
A quiet room lights no LEDs or one. Normal talking lights three to five. A clap briefly lights all ten.
Yes. It is project 51 of 120 in the Geekobot Titan Kit, in level 10 (Sound analysis). Every part on the list comes in the kit box, and you can also buy the parts one by one from the list above.
No. Every Titan Kit project is wired on the ESP32 expansion board and the breadboard with jumper wires.
8 parts: ESP32-WROOM-32 38-Pin Development Board, USB Cable, Solderless Breadboard, Dupont Jumper Wires (40 pcs), 10 × Through-Hole LED Pack (Pack of 10), Carbon Film Resistor 1/4W 5% (Pack of 10), Generic LM393 Sound Detection Sensor Module – Digital Output and ESP32 38-Pin Expansion Board. On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 45 minutes. The build on this page has 5 steps.
No. This page has the complete, tested code (titan_kit_051_sound_level_bar_graph.ino).
About ₹894 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Analog mapping to array outputs; Peak-to-peak sampling over a time window; Why a single microphone reading is meaningless; Calibrating quiet and loud limits for your room.
The ESP32 is a 3.3V board: never connect a 5V signal straight to a GPIO pin.
Clap twice and the lights come on. Clap twice again to switch them off.
Plays a friendly ding-dong whenever someone walks into the shop or room.
Beeps and flashes any message in Morse, or key your own by hand.
Turn a membrane keypad into a two-octave piano.
Lessons are free to read. Maker (₹499/month) and Pro add quizzes, worked problems and certificates, paid with your Geekobot account. See plans
Learning project. Check every circuit and the datasheet of each part before you power it up.