Raspberry Pi Pico Keypad LED Project – Blue LEDs for Numbers, Red LEDs for Letters | Beginner Tutorial



Components Required

  • Raspberry Pi Pico
  • 4x4 Matrix Keypad (16 keys)
  • 8 Blue LEDs (for numbers 0–9)
  • 8 Red LEDs (for alphabets A–D)
  • Resistors (one per LED for current limiting)
  • Jumper Wires
  • USB Cable

How It Works

The 4x4 keypad has 16 keys split into two groups. The number keys (1–9, 0) light up the corresponding blue LEDs, and the alphabet keys (A, B, C, D) light up the corresponding red LEDs. Pressing 0 resets all blue LEDs and pressing # resets all red LEDs.


Step-by-Step Instructions

Step 1: Connect the Keypad The 4x4 keypad has 8 pins (4 rows + 4 columns). Connect all 8 pins to the GPIO pins on the Raspberry Pi Pico using green jumper wires. Pull-down resistors are added on the row lines to avoid floating input signals.

CODE:

#include <Keypad.h>

const uint8_t LEDS = 12;
const uint8_t ROWS = 4;
const uint8_t COLS = 4;

char keys[ROWS][COLS] = {
  { '1', '2', '3', 'A' },
  { '4', '5', '6', 'B' },
  { '7', '8', '9', 'C' },
  { '*', '0', '#', 'D' }
};

// Pins connected to LED1, LED2, LED3, ...LED12
uint8_t ledPins[LEDS] = { 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 28, 27 };
uint8_t rowPins[ROWS] = { 26, 22, 21, 20 }; // Pins connected to R1, R2, R3, R4
uint8_t colPins[COLS] = { 19, 18, 17, 16 }; // Pins connected to C1, C2, C3, C4

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup() {
  for (uint8_t l = 0; l < LEDS; l++) {
    pinMode(ledPins[l], OUTPUT);
    digitalWrite(ledPins[l], LOW);
  }
}

void loop() {
  char key = keypad.getKey();

  if (key != NO_KEY) {
    switch (key) {
      case '1': digitalWrite(ledPins[0], HIGH);
        break;
      case '2': digitalWrite(ledPins[1], HIGH);
        break;
      case '3': digitalWrite(ledPins[2], HIGH);
        break;
      case '4': digitalWrite(ledPins[3], HIGH);
        break;
      case '5': digitalWrite(ledPins[4], HIGH);
        break;
      case '6': digitalWrite(ledPins[5], HIGH);
        break;
      case '7': digitalWrite(ledPins[6], HIGH);
        break;
      case '8': digitalWrite(ledPins[7], HIGH);
        break;
      case '9':
        for (uint8_t l = 0; l < 8; l++) {
          digitalWrite(ledPins[l], HIGH);
        }
        break;
      case '0':
        for (uint8_t l = 0; l < 8; l++) {
          digitalWrite(ledPins[l], LOW);
        }
        break;
      case 'A': digitalWrite(ledPins[8], HIGH);
        break;
      case 'B': digitalWrite(ledPins[9], HIGH);
        break;
      case 'C': digitalWrite(ledPins[10], HIGH);
        break;
      case 'D': digitalWrite(ledPins[11], HIGH);
        break;
      case '*':
        for (uint8_t l = 8; l < 12; l++) {
          digitalWrite(ledPins[l], HIGH);
        }
        break;
      case '#':
        for (uint8_t l = 8; l < 12; l++) {
          digitalWrite(ledPins[l], LOW);
        }
        break;
    }
  }

  delay(10);
}

Step 2: Connect the Blue LEDs (Numbers) Connect 8 blue LEDs in a row. Each LED has a resistor in series to limit current. Wire them to dedicated GPIO pins on the Pi Pico. These LEDs represent the number keys.

Diagram .json:

{
  "version": 1,
  "author": "Anderson Costa",
  "editor": "wokwi",
  "parts": [
    { "type": "wokwi-pi-pico", "id": "pico", "top": 118, "left": 348, "rotate": 90, "attrs": {} },
    {
      "type": "wokwi-resistor",
      "id": "rp1",
      "top": 349.55,
      "left": 19.2,
      "attrs": { "value": "1000" }
    },
    {
      "type": "wokwi-resistor",
      "id": "rp2",
      "top": 368.75,
      "left": 19.2,
      "attrs": { "value": "1000" }
    },
    {
      "type": "wokwi-resistor",
      "id": "rp3",
      "top": 426.35,
      "left": 19.2,
      "attrs": { "value": "1000" }
    },
    {
      "type": "wokwi-resistor",
      "id": "rp4",
      "top": 397.55,
      "left": 19.2,
      "attrs": { "value": "1000" }
    },
    { "type": "wokwi-membrane-keypad", "id": "keypad1", "top": -30.8, "left": -13.6, "attrs": {} },
    {
      "type": "wokwi-led",
      "id": "led1",
      "top": 20,
      "left": 420,
      "attrs": { "color": "blue", "label": "8" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r1",
      "top": 90,
      "left": 415,
      "rotate": 90,
      "attrs": { "value": "220" }
    },
    {
      "type": "wokwi-led",
      "id": "led2",
      "top": 20,
      "left": 400,
      "attrs": { "color": "blue", "label": "7" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r2",
      "top": 90,
      "left": 395,
      "rotate": 90,
      "attrs": { "value": "220" }
    },
    {
      "type": "wokwi-led",
      "id": "led3",
      "top": 20,
      "left": 380,
      "attrs": { "color": "blue", "label": "6" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r3",
      "top": 90,
      "left": 375,
      "rotate": 90,
      "attrs": { "value": "220" }
    },
    {
      "type": "wokwi-led",
      "id": "led4",
      "top": 20,
      "left": 360,
      "attrs": { "color": "blue", "label": "5" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r4",
      "top": 90,
      "left": 355,
      "rotate": 90,
      "attrs": { "value": "220" }
    },
    {
      "type": "wokwi-led",
      "id": "led5",
      "top": 20,
      "left": 340,
      "attrs": { "color": "blue", "label": "4" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r5",
      "top": 90,
      "left": 335,
      "rotate": 90,
      "attrs": { "value": "220" }
    },
    {
      "type": "wokwi-led",
      "id": "led6",
      "top": 20,
      "left": 320,
      "attrs": { "color": "blue", "label": "3" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r6",
      "top": 90,
      "left": 315,
      "rotate": 90,
      "attrs": { "value": "220" }
    },
    {
      "type": "wokwi-led",
      "id": "led7",
      "top": 20,
      "left": 300,
      "attrs": { "color": "blue", "label": "2" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r7",
      "top": 90,
      "left": 295,
      "rotate": 90,
      "attrs": { "value": "220" }
    },
    {
      "type": "wokwi-led",
      "id": "led8",
      "top": 20,
      "left": 280,
      "attrs": { "color": "blue", "label": "1" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r8",
      "top": 90,
      "left": 275,
      "rotate": 90,
      "attrs": { "value": "220" }
    },
    {
      "type": "wokwi-led",
      "id": "led9",
      "top": 20,
      "left": 440,
      "attrs": { "color": "red", "label": "A" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r9",
      "top": 90,
      "left": 435,
      "rotate": 90,
      "attrs": { "value": "220" }
    },
    {
      "type": "wokwi-led",
      "id": "led10",
      "top": 20,
      "left": 460,
      "attrs": { "color": "red", "label": "B" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r10",
      "top": 90,
      "left": 455,
      "rotate": 90,
      "attrs": { "value": "220" }
    },
    {
      "type": "wokwi-led",
      "id": "led11",
      "top": 20,
      "left": 480,
      "attrs": { "color": "red", "label": "C" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r11",
      "top": 90,
      "left": 475,
      "rotate": 90,
      "attrs": { "value": "220" }
    },
    {
      "type": "wokwi-led",
      "id": "led12",
      "top": 20,
      "left": 500,
      "attrs": { "color": "red", "label": "D" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r12",
      "top": 90,
      "left": 495,
      "rotate": 90,
      "attrs": { "value": "220" }
    }
  ],
  "connections": [
    [ "pico:GP0", "$serialMonitor:RX", "", [] ],
    [ "pico:GP1", "$serialMonitor:TX", "", [] ],
    [ "keypad1:C4", "pico:GP16", "green", [ "v15", "h132" ] ],
    [ "keypad1:C3", "pico:GP17", "green", [ "v25", "h182" ] ],
    [ "keypad1:C2", "pico:GP18", "green", [ "v35", "h204" ] ],
    [ "keypad1:C1", "pico:GP19", "green", [ "v45", "h222" ] ],
    [ "keypad1:R4", "pico:GP20", "green", [ "v55", "h240" ] ],
    [ "keypad1:R3", "pico:GP21", "green", [ "v65", "h260" ] ],
    [ "keypad1:R2", "pico:GP22", "green", [ "v75", "h286" ] ],
    [ "keypad1:R1", "pico:GP26", "green", [ "v85", "h299" ] ],
    [ "r1:1", "led1:A", "green", [ "h0" ] ],
    [ "r2:1", "led2:A", "green", [ "h0" ] ],
    [ "r3:1", "led3:A", "green", [ "h0" ] ],
    [ "r4:1", "led4:A", "green", [ "h0" ] ],
    [ "r5:1", "led5:A", "green", [ "h0" ] ],
    [ "r6:1", "led6:A", "green", [ "h0" ] ],
    [ "r7:1", "led7:A", "green", [ "h0" ] ],
    [ "r8:1", "led8:A", "green", [ "h0" ] ],
    [ "pico:GND.4", "led8:C", "black", [ "v-25", "h-22", "v-77", "h6" ] ],
    [ "pico:GND.4", "led7:C", "black", [ "v-25", "h-22", "v-77", "h6" ] ],
    [ "pico:GND.4", "led6:C", "black", [ "v-25", "h-22", "v-77", "h6" ] ],
    [ "pico:GND.4", "led5:C", "black", [ "v-25", "h-22", "v-77", "h6" ] ],
    [ "pico:GND.4", "led4:C", "black", [ "v-25", "h-22", "v-77", "h6" ] ],
    [ "pico:GND.4", "led3:C", "black", [ "v-25", "h-22", "v-77", "h6" ] ],
    [ "pico:GND.4", "led2:C", "black", [ "v-25", "h-22", "v-77", "h6" ] ],
    [ "pico:GND.4", "led1:C", "black", [ "v-25", "h-22", "v-77", "h6" ] ],
    [ "pico:GND.4", "led9:C", "black", [ "v-25", "h-22", "v-77", "h6" ] ],
    [ "pico:GND.4", "led10:C", "black", [ "v-25", "h-22", "v-77", "h6" ] ],
    [ "pico:GND.4", "led11:C", "black", [ "v-25", "h-22", "v-77", "h6" ] ],
    [ "pico:GND.4", "led12:C", "black", [ "v-25", "h-22", "v-77", "h6" ] ],
    [ "pico:GP4", "r1:2", "green", [ "v-28", "h10", "v-20" ] ],
    [ "pico:GP5", "r2:2", "green", [ "v-36", "h8" ] ],
    [ "pico:GP6", "r3:2", "green", [ "v-26", "h7" ] ],
    [ "pico:GP7", "r4:2", "green", [ "v-36", "h-3" ] ],
    [ "pico:GP8", "r5:2", "green", [ "v-33", "h-13" ] ],
    [ "pico:GP9", "r6:2", "green", [ "v-23", "h-14", "v-11", "h-10" ] ],
    [ "pico:GP10", "r7:2", "green", [ "v-22", "h-16", "v-9" ] ],
    [ "pico:GP11", "r8:2", "green", [ "v-12", "h-17", "v-24", "h-18" ] ],
    [ "r9:1", "led9:A", "green", [ "h0" ] ],
    [ "r10:1", "led10:A", "green", [ "h0" ] ],
    [ "r11:1", "led11:A", "green", [ "h0" ] ],
    [ "r12:1", "led12:A", "green", [ "h0" ] ],
    [ "pico:GP3", "r9:2", "green", [ "v-20", "h10", "v-20", "h20", "v-13" ] ],
    [ "pico:GP2", "r10:2", "green", [ "v-15", "h20", "v-15", "h20", "v-22" ] ],
    [ "pico:GP27", "r12:2", "green", [ "v165", "h152" ] ],
    [ "pico:GP28", "r11:2", "green", [ "v155", "h104" ] ],
    [ "rp1:2", "keypad1:R1", "green", [ "h8.4", "v-48" ] ],
    [ "rp2:2", "keypad1:R2", "green", [ "h18", "v-67.2" ] ],
    [ "rp4:2", "keypad1:R3", "green", [ "h27.6", "v-96" ] ],
    [ "rp3:2", "keypad1:R4", "green", [ "h37.2", "v-124.8" ] ],
    [ "rp1:1", "rp2:1", "red", [ "v0" ] ],
    [ "rp2:1", "rp4:1", "red", [ "v0" ] ],
    [ "rp4:1", "rp3:1", "red", [ "v0" ] ],
    [ "rp3:1", "pico:3V3", "red", [ "v19.2", "h417.15" ] ]
  ],
  "dependencies": {}
}

Step 3: Connect the Red LEDs (Alphabets) Connect 8 red LEDs in a row next to the blue LEDs. Each also has a series resistor. Wire them to separate GPIO pins. These LEDs represent the alphabet keys A, B, C, D.



Step 4: Connect Power and Ground Connect the VCC line from the keypad and LEDs to the 3.3V pin on the Pi Pico. Connect all ground lines back to a GND pin using the red wire.

Step 5: Write the Code Logic The code reads the keypad input every loop cycle. When a number key is pressed, the matching blue LED turns on. When an alphabet key is pressed, the matching red LED turns on.

Step 6: Program the Reset Keys

  • Pressing 0 → turns OFF all blue LEDs (resets numbers)
  • Pressing # → turns OFF all red LEDs (resets alphabets)

Step 7: Upload and Run Upload the MicroPython or CircuitPython code to the Pi Pico. Press keys on the keypad and watch the LEDs light up accordingly.


LED Mapping Summary

Key PressedLED ColorAction
1–9BlueLights up matching blue LED
A, B, C, DRedLights up matching red LED
0BlueResets (turns off) all blue LEDs
#RedResets (turns off) all red LEDs
*No action

Keywords Used: Raspberry Pi Pico, 4x4 keypad, LED project, blue LED, red LED, GPIO, MicroPython, beginner tutorial, Wokwi simulation


Comments