lois li
Published © CERN-OHL2

Key-controlled 3x3 LED Matrix

Use Arduino UNO to control a 3x3 LED matrix where each keypad button press lights the corresponding LED.

BeginnerProtip2 hours26

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
5 mm LED: Yellow
5 mm LED: Yellow
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Gravity:Digital Push Button (Yellow)
DFRobot Gravity:Digital Push Button (Yellow)
×1

Software apps and online services

Online Simulation
PCBX Online Simulation

Hand tools and fabrication machines

Materia 101
Arduino Materia 101

Story

Read more

Schematics

Key-controlled 3x3 LED Matrix

This project involves creating an interactive keypad-controlled LED matrix using an Arduino UNO development board. The goal is to design a system where pressing any button in a 3x3 matrix keypad will light up the corresponding LED in a 3x3 LED matrix.

Code

Key-controlled 3x3 LED Matrix

Arduino
This project involves creating an interactive keypad-controlled LED matrix using an Arduino UNO development board. The goal is to design a system where pressing any button in a 3x3 matrix keypad will light up the corresponding LED in a 3x3 LED matrix.
// Define the pins for the 3x3 LED matrix
int led_row[3] = {A5, A4, A3}; // Connect to the rows of the LED matrix
int led_col[3] = {A2, A1, A0}; // Connect to the columns of the LED matrix

// Define the pins for the 3x3 matrix keypad
int btn_row[3] = {8, 9, 10}; // Connect to the rows of the keypad
int btn_col[3] = {11, 12, 13}; // Connect to the columns of the keypad

void setup() {
    for (int i = 0; i < 3; i++) {
        pinMode(btn_row[i], OUTPUT);
        pinMode(btn_col[i], INPUT);
    }
    
    for (int i = 0; i < 3; i++) {
        pinMode(led_row[i], OUTPUT);
        pinMode(led_col[i], OUTPUT);
    }
}

void loop() {
for (int row = 0; row < 3; row++) { // Row scanning
    digitalWrite(btn_row[row], HIGH); // Set the buttons of the current row to high level
    digitalWrite(led_row[row], HIGH); // Set the cathode of the LEDs in the current row to 1
    for (int col = 0; col < 3; col++) { // Column scanning     
        if (digitalRead(btn_col[col]) == HIGH) { // A button in the current column of the current row is pressed
            digitalWrite(led_row[row], LOW); // Set the cathode of the LEDs in the current row to 0
            digitalWrite(led_col[col], HIGH); // Set the anode of the corresponding column's LED to 1, lighting up the LED at the corresponding coordinate
            delay(500); // Keep the LED lit for 500 milliseconds
            digitalWrite(led_col[col], LOW); // Set the anode of the corresponding column's LED to 0, turning off the LED
            digitalWrite(led_row[row], HIGH); // Reset the cathode of the LEDs in the current row to 1
        }
    }
    digitalWrite(btn_row[row], LOW); // Reset the buttons in the current row to high level
    }
}

Credits

lois li
8 projects • 0 followers

Comments