Build it step by step
0 of 6 doneWire the display
CLK to D2, DIO to D3, power to 5V and GND.
Wire the buttons
Tap to D4 and start/stop to D5, the other legs to GND.
Wire the encoder
CLK to D6, DT to D7, power to 5V and GND.
Add click and light
Passive buzzer to D8 and GND. LED through 220 Ω to D9.
Upload
Install the TM1637 library and upload.
Test the timing
Set 60 BPM and count against a clock for 30 beats. It should hold within a beat or so.
How do you build a tap tempo metronome?
A metronome with a click, an LED flash, an accent on beat one, a BPM display and a tap button that sets the tempo from your taps. You need Arduino Nano, TM1637 4-digit display, Passive buzzer, LED 5 mm red, Resistor 220 Ω, Tactile push button 6 mm × 2, Rotary encoder module (KY-040), Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 6 steps and about 60 minutes.
- Level
- Beginner
- Time
- About 60 min
- Parts
- 9
Parts list
- Development BoardsBuyArduino Nano × 1
- DisplaysBuy
- Motors & ActuatorsBuyPassive buzzer × 1
- SemiconductorsBuyLED 5 mm red × 1
- PassivesBuyResistor 220 Ω × 1
- SwitchesBuy
- SensorsBuy
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| TM1637 CLK / DIO | Nano D2 / D3 | BPM display |
| TM1637 VCC / GND | Nano 5V / GND | Power |
| Tap button | Nano D4 and GND | Internal pull-up |
| Start / stop button | Nano D5 and GND | Internal pull-up |
| Encoder CLK / DT | Nano D6 / D7 | Tempo knob |
| Encoder + / GND | Nano 5V / GND | Power |
| Passive buzzer + / − | Nano D8 / GND | Click |
| LED anode through 220 Ω | Nano D9 | Beat flash, cathode to GND |
Code
Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones). Install the library "TM1637" by Avishay Orpaz. If the encoder turns the wrong way, swap the + or - in the setBpm line.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <TM1637Display.h>
TM1637Display disp(2, 3);
const byte TAP = 4, RUN = 5, ENC_A = 6, ENC_B = 7, BUZ = 8, LED = 9;
int bpm = 100;
bool running = true;
byte beat = 0;
unsigned long nextBeat = 0, ledOff = 0, taps[4], lastTap = 0;
byte tapCount = 0, lastA, lastBtn[2] = {HIGH, HIGH};
void setup() {
pinMode(TAP, INPUT_PULLUP); pinMode(RUN, INPUT_PULLUP);
pinMode(ENC_A, INPUT_PULLUP); pinMode(ENC_B, INPUT_PULLUP);
pinMode(LED, OUTPUT);
disp.setBrightness(5); disp.showNumberDec(bpm);
lastA = digitalRead(ENC_A);
}
void setBpm(int v) { bpm = constrain(v, 40, 240); disp.showNumberDec(bpm); }
void loop() {
unsigned long now = millis();
byte a = digitalRead(ENC_A); // encoder: one step per falling edge on CLK
if (a != lastA && a == LOW) setBpm(bpm + (digitalRead(ENC_B) == HIGH ? 1 : -1));
lastA = a;
byte t = digitalRead(TAP); // tap tempo
if (t == LOW && lastBtn[0] == HIGH && now - lastTap > 80) {
if (now - lastTap > 2000) tapCount = 0; // too long a gap: start again
taps[tapCount % 4] = now; tapCount++; lastTap = now;
if (tapCount >= 2) {
byte n = min(tapCount, (byte)4);
unsigned long first = taps[(tapCount - n) % 4], last = taps[(tapCount - 1) % 4];
setBpm(60000UL * (n - 1) / (last - first));
}
}
lastBtn[0] = t;
byte r = digitalRead(RUN); // start and stop
if (r == LOW && lastBtn[1] == HIGH) { running = !running; beat = 0; nextBeat = now; }
lastBtn[1] = r;
if (running && now >= nextBeat) {
tone(BUZ, beat == 0 ? 1200 : 800, 20); // higher click on beat one of four
digitalWrite(LED, HIGH); ledOff = now + 60;
beat = (beat + 1) % 4;
nextBeat += 60000UL / bpm;
}
if (now >= ledOff) digitalWrite(LED, LOW);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Turn the knob | BPM changes by one per click between 40 and 240 |
| Tap four times at a steady pace | Display shows the average tempo |
| Wait 2 seconds between taps | Tapping starts over |
| Start/stop button | Click and LED stop and start, with an accent on beat one |
If it does not work
Tempo drifts
Remove any delay() added to the sketch. The scheduler adds the beat length to nextBeat, so it should not drift.
The knob is jumpy
Add 10 nF between CLK and GND, or use a better encoder.
Tap tempo is not close
Tap at least four times and keep steady.
No click
Use a passive buzzer on D8. An active buzzer only plays one tone.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the tap tempo metronome?
Arduino Nano, TM1637 4-digit display, Passive buzzer, LED 5 mm red, Resistor 220 Ω, Tactile push button 6 mm × 2, Rotary encoder module (KY-040), Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the tap tempo metronome take to build?
About 60 minutes for a beginner maker, in 6 steps.
How do I know the tap tempo metronome works?
Turn the knob: BPM changes by one per click between 40 and 240. Tap four times at a steady pace: Display shows the average tempo. Wait 2 seconds between taps: Tapping starts over.
Tempo drifts: what should I check?
Remove any delay() added to the sketch. The scheduler adds the beat length to nextBeat, so it should not drift.
The knob is jumpy: what should I check?
Add 10 nF between CLK and GND, or use a better encoder.
Tap tempo is not close: what should I check?
Tap at least four times and keep steady.
No click: what should I check?
Use a passive buzzer on D8. An active buzzer only plays one tone.
