Lesson 6 Eight LED With 74HC595
Lesson 6 Eight LED With 74HC595
Introduction
In this lesson, you will learn how to use the IC 74HC595 to turn on the LEDs in
the order you specify.
Hardware Required
1 * RexQualis UNO R3
1 * Breadboard
8 * LED
8 * 220ohm Resistors
1 * 74HC595 IC
Principle
74HC595
The 74HC595 consists of an 8-bit shift register and a storage register with
three−state parallel outputs. It converts serial input into parallel output so that
you can save IO ports of an MCU. The 74HC595 is widely used to indicate
multipath LEDs and drive multi-bit segment displays. "Three-state" refers to
the fact that you can set the output pins as either high, low or "high
impedance." With data latching, the instant output will not be affected during
the shifting; with the data output, you can cascade 74HC595s more easily.
The chip contains eight pins that we can use for output, each of which is
associated with a bit in the register. In the case of the 74HC595 IC, we refer to
these as QA through to QH. In order to write to these outputs via the Arduino,
we have to send a binary value to the shift register, and from that number ,the
shift register can figure out which outputs to use. For example, if we sent the
binary value 10100010, the pins highlighted in green in the image below would
be active and the ones highlighted in red would be inactive.
Code interpretation
int currentLED = 0;
void setup()
//The 'setup' function just sets the three pins we are using
to be digital outputs.
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
leds = 0;
void loop()
//In the loop method, we clear the bits in the leds variable
at the start of every iteration so that all the bits are set to 0 as
we only want to light up one LED at a time. After this we
increment or reset the currentLED variable so that we are
lighting up the correct LED next.
leds = 0;
if (currentLED == 7)
currentLED = 0;
else
currentLED++;
bitSet(leds, currentLED);
digitalWrite(latchPin, LOW);
digitalWrite(latchPin, HIGH);
delay(250);
Experimental Procedures
To start with let’s connect pins 16 (VCC) and 10 (SRCLR) to the 5v pin on the
Arduino and connect pins 8 (GND) and 13 (OE) to the Gnd pin on the
Arduino. Pin 13 (OE) is used to enable the outputs, as this is an active low
pin we can just connect this directly to ground.
Next we need to connect the three pins that we will control the shift register
with:
Pin 11 (SRCLK) of the shift register to pin 5 on the Arduino – this will be
referred to as the “clock pin”
Pin 12 (RCLK) of the shift register to pin 4 on the Arduino – this will be referred
to as the “latch pin”
Pin 14 (SER) of the shift register to pin 2 on the Arduino – this will be referred
to as the “data pin”
When placing the LEDs be sure that they are connected in order, so that QA is
wired to the first LED, and QH is wired to the last LED, as otherwise our code
is not going to light up the LEDs in the correct order!
Schematic Diagram