Projects / Tap tempo metronome

Tap tempo metronome

Beginner1 hGuided buildReviewed

Build it step by step

0 of 6 done
  1. NANO

    Wire the display

    CLK to D2, DIO to D3, power to 5V and GND.

  2. NANO

    Wire the buttons

    Tap to D4 and start/stop to D5, the other legs to GND.

  3. NANO

    Wire the encoder

    CLK to D6, DT to D7, power to 5V and GND.

  4. NANO12.3 mA

    Add click and light

    Passive buzzer to D8 and GND. LED through 220 Ω to D9.

  5. NANO12:45

    Upload

    Install the TM1637 library and upload.

  6. NANO

    Test the timing

    Set 60 BPM and count against a clock for 30 beats. It should hold within a beat or so.

In short

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

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
TM1637 CLK / DIONano D2 / D3BPM display
TM1637 VCC / GNDNano 5V / GNDPower
Tap buttonNano D4 and GNDInternal pull-up
Start / stop buttonNano D5 and GNDInternal pull-up
Encoder CLK / DTNano D6 / D7Tempo knob
Encoder + / GNDNano 5V / GNDPower
Passive buzzer + / −Nano D8 / GNDClick
LED anode through 220 ΩNano D9Beat 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.

CheckExpected
Turn the knobBPM changes by one per click between 40 and 240
Tap four times at a steady paceDisplay shows the average tempo
Wait 2 seconds between tapsTapping starts over
Start/stop buttonClick 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 →

Ask Lark AI

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.