Arduino Metronome Project
Build a functional metronome with adjustable tempo using an Arduino, a button, a piezo buzzer, and an LED. Perfect for musicians and Arduino beginners.
- Arduino
- Beginner
- 30 to 45 minutes
- 6 steps
Shop this project
CartYou'll need
Arduino Uno Rev 3Board Only$32.24- Clear Breadboard400 Hole$6.99
1/2w (0.5Watt) ±1% Tolerance Metal Film Fixed Resistor (100pc)10$14.99
Vilros 10 Pcs Momentary Tactile Tact Push Button Switch-- 6 x 6mm x 5mmSold out · view product
Passive Piezo Buzzer$6.99
5mm LED Set-Includes 5x Red, 5x Yellow, 5x Green$6.99
Prices from vilros.com. Tax and shipping at checkout.
Before you start, you'll need
- An Arduino Uno (or compatible board) with USB cable
- A computer with Arduino IDE installed
- A breadboard and jumper wires
- A pushbutton, a piezo buzzer, and an LED
- Resistors: 10kΩ (button pull-down), 330Ω or 470Ω (LED current-limiting)
Set up your Arduino
About 5 minutes
Prepare the Arduino IDE and verify your board is working.
- Connect your Arduino Uno to your computer via USB.
- Open the Arduino IDE. Select the correct board (Tools → Board → Arduino Uno) and port (Tools → Port).
- Upload a simple blink sketch to confirm everything works (File → Examples → 01.Basics → Blink).
You should see
The built-in LED on your Arduino blinks on and off every second.
Wire the piezo buzzer and LED
About 5 minutes
Add audio and visual feedback for each beat.
- Connect the piezo buzzer's positive (red) wire to Arduino digital pin 8. Connect its negative (black) wire to GND.
- Place an LED on the breadboard. Connect the long leg (anode) to Arduino digital pin 13 through a 330Ω or 470Ω resistor.
- Connect the LED's short leg (cathode) to GND.
You should see
Piezo buzzer and LED are wired to pins 8 and 13 respectively, with proper polarity and resistor placement.
Upload the metronome sketch
About 10 minutes
Program the Arduino to produce beats at adjustable tempos.
- Open a new sketch in the Arduino IDE and paste the code below.
- Click the Upload button (right arrow icon) to upload the sketch to your Arduino.
// Arduino Metronome Project
// Adjustable tempo using button, piezo buzzer, and LED
const int buttonPin = 2;
const int ledPin = 13;
const int piezoPin = 8;
int tempo = 120; // Initial tempo (beats per minute)
int buttonState = 0;
int lastButtonState = 0;
unsigned long previousMillis = 0;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(piezoPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
unsigned long currentMillis = millis();
unsigned long interval = 60000 / tempo; // Calculate interval from tempo
// Check if it's time for a beat
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
beat();
}
// Read button to adjust tempo
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH && lastButtonState == LOW) {
tempo += 10;
if (tempo > 240) tempo = 60; // Wrap around after 240 BPM
Serial.print("Tempo: ");
Serial.println(tempo);
delay(200); // Debounce delay
}
lastButtonState = buttonState;
}
void beat() {
digitalWrite(ledPin, HIGH);
tone(piezoPin, 1000, 50); // 1000 Hz tone for 50ms
delay(50);
digitalWrite(ledPin, LOW);
}This sketch creates a metronome that starts at 120 BPM. Press the button to increase tempo by 10 BPM, wrapping back to 60 after 240.
You should see
The sketch uploads successfully, and the Serial Monitor shows 'Tempo: 120' (open it with Tools → Serial Monitor).
Test and adjust
About 5 minutes
Verify the metronome beats and button control work.
- Watch the LED and listen to the piezo buzzer. They should pulse in sync at regular intervals.
- Press the button. The tempo should increase by 10 BPM each time you press it.
- Open the Serial Monitor (Tools → Serial Monitor) to see the current tempo displayed.
You should see
The LED flashes and the buzzer beeps at regular intervals. Pressing the button increases the tempo, and the Serial Monitor updates.
It didn't work
No sound from the piezo buzzer.
Check that the piezo's positive wire is connected to pin 8 and the negative to GND. Some piezos are quieter than others; try holding it close to your ear.
LED doesn't light up.
Verify the LED's polarity (long leg to pin 13, short leg to GND) and that the resistor is in series. Try a different LED if it still doesn't work.
Button doesn't change tempo.
Check button wiring: one side should go to pin 2 and GND (through 10kΩ), the other side to 5V. Make sure the button straddles the breadboard's center divide.
Make it yours
About 10 minutes
Experiment with tempo range, tone pitch, or LED patterns.
- Change the initial tempo by editing the line `int tempo = 120;` to a different value (e.g., 80 or 160).
- Adjust the buzzer pitch by changing the `tone(piezoPin, 1000, 50);` line. Try 500 (lower pitch) or 2000 (higher pitch).
- Add a second LED or change the LED flash duration by adjusting the `delay(50);` in the `beat()` function.
You should see
Your customizations work as expected: different starting tempo, buzzer pitch, or LED behavior.
What to do next
- Learn Arduino basicsNew to Arduino? Start with the official beginner tutorials.
- Explore more Arduino projectsFind more beginner-friendly Arduino builds to try next.
- Upload sketches with Arduino IDE 2Get comfortable with the Arduino IDE workflow.
Stuck? Contact Vilros Support with your board model and what you see on screen.