Skylar Jones
Published

Heartbeat Light Effect on 8x8 LED Matrix with Arduino UNO

Visualize your heartbeat with an 8x8 LED Matrix using Arduino UNO—an engaging project blending tech and creativity.

BeginnerFull instructions provided135

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Adafruit 8x8 LED
×1
Resistor 100 ohm
Resistor 100 ohm
×1

Software apps and online services

Online Simulation
PCBX Online Simulation

Story

Read more

Schematics

111_trbid7rqso.png

Code

Untitled file

Arduino
// Define the pins for the 8x8 LED matrix
int led_row[8] = {2, 3, 4, 5, 6, 7, 8, 9};
int led_col[8] = {10, 11, 12, 13, A0, A1, A2, A3};

// Coordinates of the LED that need to be lit
const int coords_1[18] = {
    2, 4,
    1, 2,
    0, 1,
    1, 0,
    2, 0,
    3, 0,
    4, 1,
    5, 2,
    6, 3
};
const int coords_2[21] = {
    0, 1, 1,
    1, 0, 2,
    2, 0, 3,
    3, 0, 3,
    4, 1, 6,
    5, 2, 5,
    6, 3, 4
};

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

void loop() {
    for (int i = 0; i < 9; i++) {
        display(coords_1[i*2], coords_1[i*2+1]);     
    }
    for (int i = 9; i > 0; i--) {
        display(coords_1[i*2], coords_1[i*2+1]); 
    }
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 7; j++) {
            display_all(coords_2[j*3], coords_2[j*3+1], coords_2[j*3+2]); 
        }
    }
}

// Turn off the entire LED matrix
void reset_all() {
    for (int row = 0; row < 8; row++) {
        digitalWrite(led_row[row], LOW);
        for (int col = 0; col < 8; col++) {
            digitalWrite(led_col[col], HIGH);
        }
    }
}

// Light up the LED at the corresponding coordinates in the matrix
void display(int y, int x) {
    reset_all();
    for (int row = 0; row < 8; row++) {
        if (row == y) {
            digitalWrite(led_row[row], HIGH);
            for (int col = 0; col < 8; col++) {
                if (col == x) {
                    digitalWrite(led_col[col], LOW);
                    digitalWrite(led_col[7-col], LOW);
                }
            }
        }
    }
    delay(80); // Adjust the speed
}

// Light up all the LEDs within the area enclosed by the aforementioned coordinates
void display_all(int y, int x1, int x2) {
    reset_all();
    for (int row = 0; row < 8; row++) {
        if (row == y) {
            digitalWrite(led_row[row], HIGH);
            for (int col = 0; col < 8; col++) {
                if (col >= x1 && col <= x2) {
                    digitalWrite(led_col[col], LOW);
                    digitalWrite(led_col[7-col], LOW);
                }
            }
            delay(50); // Adjust the speed
        }
    }
}

Credits

Skylar Jones

Skylar Jones

11 projects • 0 followers
Customer Success: Your one-stop solution for PCB and PCBA services, plus component sourcing. Enjoy FREE online simulation and EDA.

Comments