Raspberry Pi Pico Simon Says Memory Game with LEDs, Buzzer, OLED & High Score (MicroPython)

Build a Raspberry Pi Pico Simon Says memory game in MicroPython: four coloured LEDs and buttons, a musical buzzer, an OLED that shows the level, and a high score that stays saved in flash even after power-off.

  • DifficultyIntermediate
  • Build time2–3 hours
  • Board / MCURaspberry Pi Pico (RP2040)
  • Parts9 items
  • CodeMicroPython

Need it ready-made? Buy Ready Project

Simon Says is the classic memory game: the game flashes a pattern of coloured lights and notes, and you must repeat it in the same order. Every round adds one more step, and the pattern also plays a little faster, so it gets harder until you make a mistake. This Raspberry Pi Pico Simon Says game recreates it on a breadboard with four LEDs, four push buttons, a passive buzzer and a small OLED screen.

It is a fun weekend build for students and a great way to learn MicroPython inputs and outputs: digital outputs for the LEDs, button reading with debounce, PWM tones on a buzzer, I2C for the OLED display and saving a file to the Pico’s flash memory, so your best score is remembered even after you unplug it.

Raspberry Pi Pico Simon Says memory game on a breadboard with red, green, blue and yellow LEDs and buttons, a buzzer and an OLED showing level and best score

How It Works

  • Attract mode: after power-up the LEDs chase in a circle and the OLED shows the best score. Press any button to start. The exact moment you press is used as the random seed, so every game has a new pattern.
  • Computer’s turn: each round one random colour (0–3) is added to the sequence. The Pico plays the whole sequence, lighting each LED with its own note (C, E, G and high C). The step time starts at 480 ms and drops by 20 ms per level, down to 180 ms.
  • Your turn: you press the buttons in the same order. Each press lights the matching LED and plays its note while you hold it, just like the original game. Buttons are debounced in software (20 ms) and wait for release, so one press counts only once.
  • Time limit: you have 3 seconds for every press. If you are too slow or press the wrong colour, a falling game-over tune plays and the correct LED stays lit so you can see what you missed.
  • High score: your score is the number of rounds you completed. If it beats the record, the Pico writes it to hiscore.txt in flash and shows NEW RECORD on the OLED.

Components Required

  • Raspberry Pi Pico (or Pico W / Pico 2) – 1
  • 5 mm LEDs: red, green, blue and yellow – 1 each
  • 220 Ω resistors (for the LEDs) – 4
  • 12 mm tactile push buttons (coloured caps if available) – 4
  • Passive buzzer (not the self-oscillating active type) – 1
  • 100 Ω resistor (in series with the buzzer) – 1
  • 0.96 inch SSD1306 I2C OLED display, 128×64 – 1
  • Breadboard (full size) and jumper wires – 1 set
  • Micro-USB cable or 3×AA battery pack for power – 1

Wiring Table

Part / pinPico pinNotes
OLED VCC3V3(OUT) – pin 363.3 V supply for the display
OLED GNDGND – pin 38Common ground
OLED SDAGP0 – pin 1I2C0 data
OLED SCLGP1 – pin 2I2C0 clock
Red LED (via 220 Ω)GP2 – pin 4LED cathode to GND
Green LED (via 220 Ω)GP3 – pin 5LED cathode to GND
Blue LED (via 220 Ω)GP4 – pin 6LED cathode to GND
Yellow LED (via 220 Ω)GP5 – pin 7LED cathode to GND
Red buttonGP6 – pin 9Other leg to GND, internal pull-up
Green buttonGP7 – pin 10Other leg to GND
Blue buttonGP8 – pin 11Other leg to GND
Yellow buttonGP9 – pin 12Other leg to GND
Passive buzzer + (via 100 Ω)GP15 – pin 20Buzzer – to GND; PWM tone output

Connection Diagram

The illustration above shows a typical breadboard layout and is a layout guide only. Follow the pin-accurate drawing below, which matches the wiring table and the code.

Raspberry Pi Pico Simon Says Game – Pin-Accurate Wiring Raspberry Pi Pico GP0 (pin 1) OLED SDA GP1 (pin 2) OLED SCL GP2 (pin 4) 220 Ω → RED LED anode, cathode → GND GP3 (pin 5) 220 Ω → GREEN LED anode, cathode → GND GP4 (pin 6) 220 Ω → BLUE LED anode, cathode → GND GP5 (pin 7) 220 Ω → YELLOW LED anode, cathode → GND GP6 (pin 9) RED button → GND (internal pull-up) GP7 (pin 10) GREEN button → GND GP8 (pin 11) BLUE button → GND GP9 (pin 12) YELLOW button → GND GP15 (pin 20) 100 Ω → passive buzzer (+), buzzer (–) → GND 3V3 / GND OLED VCC to 3V3 (pin 36), all GNDs to common rail LED long leg (anode) goes to the resistor. Buttons need no external resistors: the code enables the internal pull-ups. Use a PASSIVE buzzer so the four notes sound different. Power from micro-USB or 3×AA (4.5 V) into VSYS (pin 39).
Pin-accurate connection diagram for the Raspberry Pi Pico Simon Says game.

Code

Flash the latest MicroPython UF2 for your board (hold BOOTSEL while plugging in the Pico and drop the file on the RPI-RP2 drive). In Thonny, open Tools → Manage packages, search for ssd1306 and install it (or copy the ssd1306.py driver from the micropython-lib repository to the Pico). Then save the code below to the Pico as main.py so the game starts automatically on power-up.

# Raspberry Pi Pico Simon Says Memory Game
# 4 LEDs + 4 buttons + passive buzzer + SSD1306 OLED, high score kept in flash
# Arduino Project Hub - ardiunoprojecthub.online
# Needs ssd1306.py on the Pico (Thonny: Tools > Manage packages > "ssd1306")

from machine import Pin, PWM, I2C
import time, urandom
import ssd1306

# ---------- pin map (matches the wiring table) ----------
LED_PINS = (2, 3, 4, 5)        # red, green, blue, yellow LEDs (220 ohm to GND)
BTN_PINS = (6, 7, 8, 9)        # matching buttons, other leg to GND
BUZZER_PIN = 15                # passive buzzer (+) through 100 ohm
TONES = (262, 330, 392, 523)   # C4, E4, G4, C5 - one note per colour
NAMES = ("RED", "GREEN", "BLUE", "YELLOW")

leds = [Pin(p, Pin.OUT, value=0) for p in LED_PINS]
btns = [Pin(p, Pin.IN, Pin.PULL_UP) for p in BTN_PINS]   # pressed = 0
buzzer = PWM(Pin(BUZZER_PIN))
buzzer.duty_u16(0)

i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
oled = ssd1306.SSD1306_I2C(128, 64, i2c)

SCORE_FILE = "hiscore.txt"
INPUT_TIMEOUT_MS = 3000        # time allowed for each button press


def load_best():
    try:
        with open(SCORE_FILE) as f:
            return int(f.read().strip() or 0)
    except (OSError, ValueError):
        return 0              # first run: file does not exist yet


def save_best(score):
    with open(SCORE_FILE, "w") as f:
        f.write(str(score))


def show(line1, line2="", line3=""):
    oled.fill(0)
    oled.text("SIMON SAYS", 24, 0)
    oled.hline(0, 10, 128, 1)
    oled.text(line1, 0, 20)
    oled.text(line2, 0, 34)
    oled.text(line3, 0, 48)
    oled.show()


def tone(freq, ms):
    if freq:
        buzzer.freq(freq)
        buzzer.duty_u16(20000)    # about 30 % duty = clear but not harsh
    time.sleep_ms(ms)
    buzzer.duty_u16(0)


def flash(i, ms):
    leds[i].value(1)
    tone(TONES[i], ms)
    leds[i].value(0)


def step_time(level):
    # sequence gets faster as the level goes up (min 180 ms per step)
    return max(180, 500 - level * 20)


def wait_press(timeout_ms):
    """Return button index 0-3, or -1 on timeout. Includes debounce."""
    start = time.ticks_ms()
    while time.ticks_diff(time.ticks_ms(), start) < timeout_ms:
        for i, b in enumerate(btns):
            if b.value() == 0:
                time.sleep_ms(20)              # debounce
                if b.value() == 0:
                    leds[i].value(1)
                    buzzer.freq(TONES[i])
                    buzzer.duty_u16(20000)
                    while b.value() == 0:      # wait for release
                        time.sleep_ms(5)
                    buzzer.duty_u16(0)
                    leds[i].value(0)
                    time.sleep_ms(30)
                    return i
        time.sleep_ms(2)
    return -1


def any_button():
    return any(b.value() == 0 for b in btns)


def game_over_sound():
    for f in (392, 330, 262, 196):
        tone(f, 180)
        time.sleep_ms(30)


def win_round_sound():
    tone(784, 60)
    time.sleep_ms(30)
    tone(1047, 90)


def attract_mode(best):
    """Chase the LEDs until any button is pressed."""
    show("Press any key", "to start", "Best: %d" % best)
    i = 0
    while not any_button():
        leds[i].value(1)
        time.sleep_ms(150)
        leds[i].value(0)
        i = (i + 1) % 4
    while any_button():           # wait for release so it is not counted
        time.sleep_ms(10)
    urandom.seed(time.ticks_us())  # human timing gives a random seed
    time.sleep_ms(400)


def play_game(best):
    sequence = []
    while True:
        sequence.append(urandom.getrandbits(2))   # add one random colour 0-3
        level = len(sequence)
        show("Level: %d" % level, "Watch...", "Best: %d" % best)
        time.sleep_ms(500)
        t = step_time(level)
        for c in sequence:                        # computer plays the pattern
            flash(c, t)
            time.sleep_ms(t // 2)

        show("Level: %d" % level, "Your turn!", "Best: %d" % best)
        for expected in sequence:                 # player repeats it
            pressed = wait_press(INPUT_TIMEOUT_MS)
            if pressed != expected:
                return level - 1, expected, pressed
        win_round_sound()
        time.sleep_ms(400)


best = load_best()
show("Ready!", "", "Best: %d" % best)
for i in range(4):
    flash(i, 120)

while True:
    attract_mode(best)
    score, expected, pressed = play_game(best)
    game_over_sound()
    leds[expected].value(1)      # show which colour was correct
    msg = "Too slow!" if pressed < 0 else "Wrong colour"
    if score > best:
        best = score
        save_best(best)
        show("NEW RECORD: %d" % score, msg, "Was " + NAMES[expected])
    else:
        show("Score: %d" % score, msg, "Was " + NAMES[expected])
    time.sleep_ms(2500)
    leds[expected].value(0)

How to Play

  • Press any button to start. Watch the LEDs and listen to the notes.
  • When the OLED says Your turn!, press the buttons in the same order.
  • Each correct round plays a short happy chirp and adds one more step.
  • To reset the high score, delete hiscore.txt from the Pico in Thonny’s file panel.

Troubleshooting

ProblemFix
ImportError: no module named ‘ssd1306’The OLED driver is not on the Pico. Install the ssd1306 package in Thonny or copy ssd1306.py to the Pico’s root folder.
OSError: [Errno 5] EIO at startThe OLED is not answering on I2C. Check SDA on GP0 and SCL on GP1, VCC on 3V3 and GND. Run print(i2c.scan()): you should see [60] (0x3C).
All four notes sound the same, or only a clickYou have an active buzzer. Replace it with a passive buzzer so the PWM frequency sets the pitch.
A button seems to press itselfThe button is wired to the wrong breadboard rows. Tactile buttons connect in pairs across the gap; use pins on opposite corners.
An LED never lightsThe LED is reversed. The long leg (anode) must go to the resistor and GPIO pin, the short leg to GND.
Game says Too slow! immediatelyA button is held or shorted to GND at start. Check that no button pin is touching the GND rail.
High score resets after unpluggingThe code must run from the Pico’s flash as main.py. Running it only from Thonny’s editor still saves, but check that hiscore.txt appears on the Pico.

Ideas to Extend

  • Add a two-player mode where players take turns adding one colour each.
  • Replace the LEDs with a WS2812B ring for brighter, bigger colours.
  • Add a difficulty switch that changes the start speed and time limit.

Leave a Comment