Free Shipping Over $119



Arduino UNO R3/MEGA 2560 R3 Project 16: 74HC595 driving LEDs

Posted by Fiona Su on

Introduction

To put it simply, 74HC595 is a combination of 8-digit shifting register, memorizer and equipped with tri-state output. Here, we use it to control 8 LEDs. You may wonder why use a 74HC595 to control LED? Well, think about how many I/O it takes for an Arduino to control 8 LEDs? Yes, 8. For an Arduino 168, it has only 20 I/O including analog ports. To save port resources, we use 74HC595 to reduce the number of ports it needs. Using 74HC595 enables us to use 3 digital I/O port to control 8 LEDs!

thumb
Hardware Required

  • 74HC595 chip*1
  • REV4 board *1
  • Red M5 LED*4
  • Green M5 LED*4
  • 220Ω resistor*8
  • Breadboard*1
  • USB cable *1
  • Breadboard jumper wires*several

Note: for pin 13 OE port of 74HC595, it should be connected to GND

Video Tutorial

Connection

Connection for REV4:

thumb

Connection for 2560 R3:

thumb

The circuit may seem complicated, but soon you will find it easy!

Sample Code:

int data = 2;// set pin 14 of 74HC595as data input pin SI 
int clock = 5;// set pin 11 of 74hc595 as clock pin SCK
int latch = 4;// set pin 12 of 74hc595 as output latch RCK 
int ledState = 0;
const int ON = HIGH;
const int OFF = LOW;
void setup()
{
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(latch, OUTPUT);
}
void loop()
{
for(int i = 0; i < 256; i++)
{
updateLEDs(i);
delay(500);
}
}
void updateLEDs(int value)
{
digitalWrite(latch, LOW);//
shiftOut(data, clock, MSBFIRST, ~value);// serial data “output”, high level first
digitalWrite(latch, HIGH);// latch
}

Result

After downloading the program, you can see 8 LEDs display 8-bit binary number.

thumb

All Tutorial

Buy 

0 comments

Leave a comment

Please note, comments must be approved before they are published