Hobbies And Interests
Home  >> Science & Nature >> Science

How to Control an 8x8 LED Matrix With Arduino

Arduino is a single circuit board used in conjunction with the Arduino software to make using electronics easier. It allows control of electronic circuits through programming on a small, simple scale. An 8x8 LED (light emitting diode) matrix is usually purchased as a complete unit, though some people may choose to buy 64 LEDs and wire them together. The biggest challenge in hooking up the LED matrix to the Arduino board is making sure the pins are wired to the appropriate inputs or outputs, as this is a little counterintuitive.

Instructions

    • 1

      Orient your LED matrix so that pins 1 through 8 are along the bottom, going left to right, and pins 9 through 16 are along the top, going right to left. Orient your Arduino board off to the side of the matrix, with the digital outputs (labeled) across the top and the analog inputs (labeled) across the bottom.

    • 2

      Wire together matrix pins 1 through 4 with board digital outputs 2 through 5, in that order. Wire together matrix pins 5 through 8 with board analog inputs 0 through 3, in that order. Wire together matrix pins 9 through 16 with board digital outputs 13 through 6, in that order.

    • 3

      Using the Arduino software, define your variables according to the arrangement of pins and inputs/outputs. The numbers in the variable pins correspond to the order of the wiring you did, with -1 added as a dummy to make array start at position 1. The LED matrix columns are defined by 8 pins in the order 13, 3, 4, 10, 6, 11, 15, 16, and the LED matrix rows are defined by 8 pins in the order 9, 14, 8, 12, 1, 7, 2, 5. Those give you the definitions of the variables rows and cols.

      Example code:

      #include <FrequencyTimer2.h>

      byte col = 0;

      byte leds[8][8];

      int pins[17]= {-1, 5, 4, 3, 2, 14, 15, 16, 17, 13, 12, 11, 10, 9, 8, 7, 6};

      int cols[8] = {pins[13], pins[3], pins[4], pins[10], pins[06], pins[11], pins[15], pins[16]};

      int rows[8] = {pins[9], pins[14], pins[8], pins[12], pins[1], pins[7], pins[2], pins[5]};

    • 4

      From here, you can make the LEDs flash in any pattern you desire by defining an 8x8 matrix in terms of 0s and 1s. For example, to define the letter "H", you could put in your code with 1s to turn on certain LEDs to make the shape of the letter H:

      #define H {

      {0, 1, 0, 0, 0, 0, 1, 0},

      {0, 1, 0, 0, 0, 0, 1, 0},

      {0, 1, 0, 0, 0, 0, 1, 0},

      {0, 1, 1, 1, 1, 1, 1, 0},

      {0, 1, 0, 0, 0, 0, 1, 0},

      {0, 1, 0, 0, 0, 0, 1, 0},

      {0, 1, 0, 0, 0, 0, 1, 0},

      {0, 1, 0, 0, 0, 0, 1, 0} }


https://www.htfbw.com © Hobbies And Interests