Double-clap light switch
Clap twice and the lights come on. Clap twice again to switch them off.
Shop by category
Shop all componentsA practice metronome for any instrument. The potentiometer sets the tempo, the piezo clicks and the LED flashes in time, and every fourth beat is higher and longer so you always know where the bar starts. The current tempo prints in the Serial Monitor.
Tick anything you already have and the total updates.
A 10 kΩ knob that works as a voltage divider, giving an analog value you can map to anything.
Follow the colours: red is power, dark grey is ground, blue is a signal.
stage_metronome.inoVerify & upload in Electrolark// Metronome with an accent beat
// Geekobot project library · board: Arduino Nano
// Wiring diagram, parts list and build steps: Geekobot project page "stage-metronome"
// ---- pins ----
const uint8_t POT_PIN = A0;
const uint8_t PIEZO_PIN = 2;
const uint8_t LED_RED = 3;
const int ADC_MAX = 1023; // 10-bit analog input
const float VREF = 5.0f;
// ---- latest readings ----
int potPct = 0;
int bpm = 100, beat = 0;
unsigned long lastBeat = 0;
void setRedLed(bool on) { digitalWrite(LED_RED, on ? HIGH : LOW); }
void setup() {
Serial.begin(115200);
pinMode(LED_RED, OUTPUT);
}
void loop() {
bpm = map(analogRead(POT_PIN), 0, ADC_MAX, 40, 208);
if (millis() - lastBeat >= 60000UL / bpm) {
lastBeat = millis();
bool accent = (beat % 4) == 0; // first beat of the bar is higher and louder
tone(PIEZO_PIN, accent ? 1500 : 1000, accent ? 60 : 35);
setRedLed(true); delay(accent ? 60 : 30); setRedLed(false);
beat++;
Serial.print(bpm); Serial.println(F(" bpm"));
}
}
The sketch above runs here on a simulated Arduino Nano. Move the sliders for the sensors and buttons it reads, and watch the Serial monitor, display and outputs change.
The wiper is on an outer pin. Move the signal wire to the middle leg.
Normal for a bare piezo; mount it on a small box to resonate.
LED is reversed; flip it. Check the 220 Ω resistor is in series.
Open the Serial Monitor at 115200 baud and check for messages. Make sure you chose the right board and port in the Arduino IDE.
Close other programs using the serial port, try another USB cable (some are charge-only) and press reset just before uploading.
Yes. Most of the code works unchanged on an ESP32 with the ESP32 board package. Watch for 5 V modules: ESP32 pins are 3.3 V, so 5 V output signals need a resistor divider. Analog readings run 0–4095 instead of 0–1023, which the ADC_MAX constant handles.
Use a 5 V USB phone charger or a power bank into the board's USB port.
7 parts: Nano CH340 Development Board (Soldered), 16mm Rotary Potentiometer 10kΩ (Linear), Piezo Buzzer (passive), Through-Hole LED Pack (Pack of 10), Resistor Assortment Kit (30 Values), Solderless Breadboard (830 points) and Dupont Jumper Wires (40 pcs). Tools: Digital Multimeter and Wire Stripper and Cutter. On this page you can tick the parts you already have and add only the rest to your cart.
It is a beginner project and takes about 45 minutes. The build on this page has 8 steps.
No. This page has the complete, tested code (stage_metronome.ino).
Yes. The Run it panel under the code runs this exact sketch on a simulated board. Move the sliders or press the buttons for the sensors it reads, and the Serial monitor, display and outputs react as they will on the real build. It is a simulation, so real readings depend on your parts and wiring.
About ₹328 for the parts at the prices on this page, plus tools if you do not have them. Quantity price breaks lower the cost when you build several.
Current-limiting resistors for LEDs; Generating musical notes with tone(); Voltage dividers and analogRead().
Ideas that reuse this build: Big display of the tempo and Hand theremin. They are listed under Take it further on this page.
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.
Learning project. Check every circuit and the datasheet of each part before you power it up.
124 bpm 124 bpm 124 bpm 124 bpm 124 bpm
A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.