keyestudio
Share your creative ideas with us here
By Alisa | 20 March 2024 | 0 Comments

How to Use a 74HC595N Chip to Control LEDs?

1.Introduction
 

For a PLUS mainboard, it has only 22 I/O ports, how do we light up a large number of LEDs? In this project, we will use 74HC595N to control 7 LEDs to save port resources.
 

2.Components Required
 

Keyestudio Plus Mainboard*1

Red LED*7

74HC595N Chip*1

220Ω Resistor*7

Breadboard*1

Jumper Wires

USB Cable*1


3.Component Knowledge
 

74HC595N Chip: To put it simply, 74HC595N chip is a combination of 8-digit shifting register, memorizer and equipped with tri-state output.The shift register and the memorizer are synchronized to different clocks, and the data is input on the rising edge of the shift register clock SCK and goes into the memory register on the rising edge of the memory register clock RCK. If the two clocks are connected together, the shift register is always one pulse earlier than the storage register. The shift register has a serial shift input (SI) and a serial output (SQH) for cascading. The 8-bit shift register can be reset asynchronously (low-level reset), and the storage register has an 8-bit Three-state parallel bus output, when the output enable (OE) is enabled (active low), the storage register is output to the 74HC595N pin (bus).

image-20230417133531059

Pins

VCC and GND are used used for chip power supply, and the operating voltage is 5V.
 

4.Circuit Diagram and Wiring Diagram
 

Note: Pay attention to the direction in which the 74HC595N chip is inserted.


5.Code
 

/*
74HC595N_control_7_LEDS
http//www.keyestudio.com
*/
int data = 4;// sets PIN 4 of the 74HC595 to datainput PIN SI
int clock = 6;//  sets PIN 6 of the 74HC595 to clock PIN SCK
int latch = 5;// sets PIN 5 of the 74HC595 to 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);// shift out highbyte
digitalWrite(latch, HIGH);// lock
}


6.Result
 

Upload project code, wire up and power on, then you can see the changes of 7 LEDs cyclically.

Leave a Reply

Your email address will not be published.Required fields are marked. *
Name
E-mail
Content
Verification code