Three-lane rhythm tapper
Lights run down three lanes and you tap the matching button as each one reaches the end, scoring for timing and getting faster as you go. A quick rhythm game that shows how reaction time and timing windows work.
Build it step by step
0 of 7 doneWire the three buttons
D2, D3 and D4, each other leg to GND.
Wire the three LEDs
D5 to D7, each through a 220 ohm resistor, short legs to GND.
Wire the buzzer and OLED
Buzzer to D8 and GND, OLED to A4, A5, 5V and GND.
Upload the sketch
Three boxes appear on the screen.
Wait for a note
It falls down one lane.
Press the matching button
While its LED is lit, for a point and a high beep.
Play on
Until your five lives run out.
How do you build a three-lane rhythm tapper?
Lights run down three lanes and you tap the matching button as each one reaches the end, scoring for timing and getting faster as you go. A quick rhythm game that shows how reaction time and timing windows work. You need Arduino Nano, Tactile push button 6 mm × 3, LED 5 mm red × 3, Resistor 220 Ω × 3, Passive buzzer, SSD1306 OLED Display, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 100 minutes.
- Level
- Intermediate
- Time
- About 100 min
- Parts
- 8
Parts list
- Development BoardsBuyArduino Nano × 1
- SwitchesBuy
- SemiconductorsBuyLED 5 mm red × 3
- PassivesBuyResistor 220 Ω × 3
- Motors & ActuatorsBuyPassive buzzer × 1
- DisplaysBuy
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Lane buttons 1 to 3 | Nano D2, D3 and D4 and GND | Left, middle and right lane |
| Lane LEDs 1 to 3 long legs | Nano D5, D6 and D7, each through a 220 ohm resistor | Light when a note is in the hit zone |
| LED short legs | Nano GND | Return |
| Passive buzzer + and - | Nano D8 and GND | Hit and miss sounds |
| OLED SDA and SCL | Nano A4 and A5 | Shows the falling notes |
| OLED VCC and GND | Nano 5V and GND | Power for a 0.96 inch module |
Code
One note at a time drops down one of three lanes on the screen. The lane's LED lights while the note is inside the hit zone, a box near the bottom, and you score by pressing that lane's button during that time. A press in the wrong lane or too early counts as a miss, and so does letting the note fall past. You have five lives, the notes speed up after every ten, and any button restarts after the game is over. The timing window is the height of the zone divided by the speed: at a speed of 2 pixels per frame and about 33 frames a second, the window is long enough to be easy, and by speed 6 it is only a few frames, which is why the game gets hard. The sketch uses a 30 millisecond frame timer instead of delay, so button presses are never missed. Install "Adafruit SSD1306" and "Adafruit GFX" from the Library Manager. Try changing ZONE_TOP to make the window shorter, or keep a longest streak score.
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).
// Libraries: Adafruit SSD1306 and Adafruit GFX.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
const uint8_t BTN[3] = {2, 3, 4};
const uint8_t LED[3] = {5, 6, 7};
const uint8_t BUZZ = 8;
const int ZONE_TOP = 46; // a note is hittable between these two rows
const int ZONE_BOTTOM = 62;
const int NOTE_H = 6;
const uint8_t MAX_LIVES = 5;
bool prevDown[3];
bool active = false;
bool resolved = false;
int lane = 0;
int y = -NOTE_H;
int speedPx = 2;
uint8_t beats = 0;
uint8_t lives = MAX_LIVES;
unsigned int score = 0;
bool gameOver = false;
unsigned long lastFrame = 0;
unsigned long nextAt = 0;
bool inZone() {
return (y + NOTE_H >= ZONE_TOP) && (y <= ZONE_BOTTOM);
}
void restart() {
active = false;
resolved = false;
y = -NOTE_H;
speedPx = 2;
beats = 0;
lives = MAX_LIVES;
score = 0;
gameOver = false;
nextAt = millis() + 800;
}
void miss() {
resolved = true;
tone(BUZZ, 200, 150);
if (lives > 0) lives--;
if (lives == 0) gameOver = true;
}
void draw() {
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(SSD1306_WHITE);
oled.setCursor(0, 0);
if (gameOver) {
oled.print(F("GAME OVER Score "));
oled.print(score);
oled.setCursor(0, 12);
oled.print(F("Press any button"));
} else {
oled.print(F("Score "));
oled.print(score);
oled.print(F(" Lives "));
oled.print(lives);
}
for (uint8_t i = 0; i < 3; i++) {
int x = 8 + i * 42;
oled.drawRect(x, ZONE_TOP, 26, ZONE_BOTTOM - ZONE_TOP + 1, SSD1306_WHITE); // hit zone
if (active && !resolved && !gameOver && i == lane) oled.fillRect(x + 4, y, 18, NOTE_H, SSD1306_WHITE);
}
oled.display();
}
void setup() {
for (uint8_t i = 0; i < 3; i++) {
pinMode(BTN[i], INPUT_PULLUP);
pinMode(LED[i], OUTPUT);
}
pinMode(BUZZ, OUTPUT);
Serial.begin(9600);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
randomSeed(analogRead(A0));
restart();
}
void loop() {
unsigned long now = millis();
for (uint8_t i = 0; i < 3; i++) {
bool down = (digitalRead(BTN[i]) == LOW);
bool pressed = down && !prevDown[i];
prevDown[i] = down;
if (!pressed) continue;
if (gameOver) { restart(); continue; }
if (active && !resolved) {
if (i == lane && inZone()) {
resolved = true;
score++;
tone(BUZZ, 1800, 80);
} else {
miss(); // wrong lane or too early
}
}
}
if (!active && !gameOver && now >= nextAt) { // start a new note
lane = random(3);
y = -NOTE_H;
active = true;
resolved = false;
beats++;
if (beats % 10 == 0 && speedPx < 6) speedPx++;
}
if (now - lastFrame >= 30) {
lastFrame = now;
if (active) {
y += speedPx;
if (y > 63 || (resolved && !inZone())) {
if (!resolved) miss(); // note fell past the zone
active = false;
nextAt = now + 350;
}
}
for (uint8_t i = 0; i < 3; i++)
digitalWrite(LED[i], (active && !resolved && !gameOver && i == lane && inZone()) ? HIGH : LOW);
draw();
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Note in the zone | That lane's LED lights |
| Correct button in time | Score goes up with a high beep |
| Wrong lane or early press | Low beep and a lost life |
| Every ten notes | The notes fall faster |
| Five misses | Game over screen, any button restarts |
If it does not work
Blank screen
Check the OLED wires and try address 0x3D.
Notes never appear
Check the sketch uploaded and the OLED shows the boxes.
A lane never scores
Check the button goes to its pin and to GND.
LED stays dark
Check its direction and the 220 ohm resistor.
Too hard or too easy
Change the starting speedPx or the zone height.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the three-lane rhythm tapper?
Arduino Nano, Tactile push button 6 mm × 3, LED 5 mm red × 3, Resistor 220 Ω × 3, Passive buzzer, SSD1306 OLED Display, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the three-lane rhythm tapper take to build?
About 100 minutes for a intermediate maker, in 7 steps.
How do I know the three-lane rhythm tapper works?
Note in the zone: That lane's LED lights. Correct button in time: Score goes up with a high beep. Wrong lane or early press: Low beep and a lost life.
Blank screen: what should I check?
Check the OLED wires and try address 0x3D.
Notes never appear: what should I check?
Check the sketch uploaded and the OLED shows the boxes.
A lane never scores: what should I check?
Check the button goes to its pin and to GND.
LED stays dark: what should I check?
Check its direction and the 220 ohm resistor.
