Skip to content

11. Output devices

My Output Device

My output for this week is 16 LEDs in a 4x4 Matrix grid.

KiCAD

I made my board in KiCad. I started by looking up a picture of an LED matrix schematic online and I based my schematic off of the picture. I then added the footprints for the resistors, LEDs, and Xiao Esp32-C3. I also added through hole pin headers because my board would need to be double sided.

I then loaded up the PCB editor and routed my Traces

Soldering

Soldering was just like normal, I used copper rivets to connect both sides of my board and soldered them in place.

Then I soldered all of my 1206 SMD components like the resistors and LEDs before I soldered the female pin header to connect the board. Whilst soldering the resistors I realised that I didn’t need the have 220ohm resistors for both the rows and columns of my board. Instead I put the 220ohm resistors on the rows and I bridges the gap on the column side with a 0 ohm resistor.

Coding

I asked ChatGPT to make the code for me since it was a pretty simple code.

// Define pins for rows and columns
const int rows[4] = {D1, D2, D3, D4};     // Row pins (cathode)
const int cols[4] = {D7, D8, D9, D10};    // Column pins (anode)

void setup() {
  // Set all row and column pins as OUTPUT
  for (int i = 0; i < 4; i++) {
    pinMode(rows[i], OUTPUT);
    pinMode(cols[i], OUTPUT);

    digitalWrite(rows[i], HIGH);   // Rows HIGH = OFF (since cathode)
    digitalWrite(cols[i], LOW);    // Columns LOW = OFF (since anode)
  }
}

void loop() {
  // Loop through all 16 LEDs
  for (int r = 0; r < 4; r++) {
    for (int c = 0; c < 4; c++) {
      lightLED(r, c);
      delay(200);
      clearMatrix();
    }
  }
}

// Function to light a single LED at (row, col)
void lightLED(int row, int col) {
  digitalWrite(cols[col], HIGH);  // Anode side ON
  digitalWrite(rows[row], LOW);   // Cathode side ON
}

// Turn off all LEDs
void clearMatrix() {
  for (int i = 0; i < 4; i++) {
    digitalWrite(cols[i], LOW);   // Anode side OFF
    digitalWrite(rows[i], HIGH);  // Cathode side OFF
  }
}

Group Assignment

My Files


Last update: June 5, 2025