Introduction: Pushbutton LED Matrix
This project can be thought of as another introductory Arduino project that is slightly more advanced than your typical 'blinking an LED' project. This project incorporates an LED matrix, pushbuttons, shift registers (which can save pins on your Arduino board), and a key concept called multiplexing. I hope you find the tutorial enlightening and challenge yourself to improve upon it!
(1x) Arduino Uno
(5x) Tactile Pushbuttons
(2x) 0.1 uF Capacitors
(2x) 1 uF Capacitors
(8x) 1k Resistors
(5x) 10k Resistors
(2x) 74HC595 shift registers
Step 1: Step 1: Making an LED Matrix
The tutorial I used to make the 8x8 LED matrix in this project can be found here. There are common configurations for a LED matrix:
a) Common Row Anode
b) Common Row Cathode
Since I used the Common Row Cathode arrangement of the matrix, I will mainly discuss it here and you can extend the same logic to the Common Row Anode arrangement. In the Common Row Cathode arrangement, the LEDs' cathodes (or negative terminals which is the shorter leg on a LED) are connected together in rows while the anodes (or positive terminals which is the longer leg on a LED) are connected together in columns. To address a particular LED, pull the cathode row that the LED cathode is on low and pull the anode column that the LED anode is on high.
Note: When making the LED matrix shown in the link above, make sure to connect the anode columns with the 1k ohm resistors before applying any amount of voltage to the LEDs.
Step 2: Step 2: Wiring Up the Pushbuttons and Shift Registers
The wiring for the pushbuttons and shift registers is shown above. I would like to note that the shift registers in the circuit diagram do not show the ground (pin 8 of the IC) and Vcc or power supply (pin 16 of the IC) pins for the chips; the ground pin is connected to GND pin of the Arduino board and Vcc is connected to the 5V pin of the Arduino board. The Vcc pin of each shift register is also connected to a 0.1uF capacitor connected to ground.
Note: The outputs of each shift register are listed as QA to QH (ignore QH*). They are listed in terms of the least significant bit (LSB) (for QA) to most significant bit (MSB) (for QH) i.e. QA would control the 0th row or column, etc.
Step 3: Step 3: Uploading the Code
The code to control the LED matrix is attached to this tutorial. I tried to comment out as much of the code as I could so it would be very clear how the program works. The main basis of the program is there is a matrix that keeps track of which LEDs should be on or off. In order to have the various LEDs display correctly without accidentally turning on undesired diodes is to use a concept called multiplexing. Multiplexing is essentially lighting up individual LEDs in particular row while all other LEDs in other rows, then doing the same for the remaining rows. The trick is that if the LEDs cycle through the rows quickly enough, your eyes can tell that individual rows are being lit one at a time. If you would like to explore more ways you can trick your eyes with LEDs, you may want to look into the concept of persistence of vision (easily searchable on Google or Instructables).
The way the anode columns and cathode rows are updated is through a user-defined function called 'UpdateShiftRegisters'. This function first turns the latch pin, which controls if a new byte (8 bits) is sent to the output, low so no changes to the outputs are possible while new bits are being written to the chip. Then using a built-in Arduino function called 'ShiftOut', which specifically handles sending data to shift registers, the program writes whichever (cathode) row would be low and which (anode) columns should be high. Finally, the latch pin is pulled high so to update the output (the LEDs).
Step 4: Additional Information/Resources
Here are some links to websites or books that may give additional information regarding this project:
Getting Started with Arduino, 2nd Edition by Massimo Banzi