Have you ever wondered how people made their projects controlling tons of LEDs with just a single Arduino? Controlling all the LEDs individually requires a lot of pins. So, now I am going to introduce you to shift register. In this tutorial the shift register that we are going to use is 74HC595, 8 bit shift register. By using shift register, you expanded a lot of output pins from your Arduino, that is the best part!

Okay, you might wondering, what is the shift register that I have mentioned. Now, I am going to briefly cover some basic information on shift register before proceed to 74HC595 IC. Shift register consists of arrangement of flip flops and used in applications involved storage and transfer of data in digital system. Shift register can have either serial or parallel inputs and outputs. Four basic configurations of shift register are Serial-In, Serial-Out,  Serial-In, Parallel-Out, Parallel-In, Serial-Out, and Parallel-In, Parallel-Out.

sr5The difference between serial and parallel data transfer is that serial transfer data bit by bit whereas parallel transfer data simultaneously. The data transfer rate for parallel is faster than serial, eg, 8 bits of data in serial requires eight time intervals to fully transfer data, but for parallel with 8 data lines only requires one time interval. However, the down side of using parallel data transfer is that it cost more than serial because of the number of data lines required.

A clock is used to provide an uniform and synchronous timing for the shift register to work. Next, I am going to introduce another new term which is latch. A latch actually works as a storage used to store data in digital electronic system.

sr4
74HC595 IC

What I really like about 74HC595 shift register is that it expands eight more pins with only three pins from Arduino. It can be used to control outputs such as LED, relays, 7 segment or even make yourself a serial LCD. You can try to search around for serial LCD with 74HC595. It further reduce the pins used to control LCD in 4 bit mode, from 7 pins to 3 pins!!  Besides that, you can chain shift register to control even more outputs with only three control pins.

Datasheet for 74HC595, available here

Some features of 74HC595:

– 8 Bit Serial Input

– 8 Bit Serial and Parallel Output

– Storage Register with 3 State Output

Pin Diagram and Description for 74HC595:

sr2
Pin Diagram
sr1
Pin Description (Click to enlarge)

For Q0 to Q7, this is the eight output pin of your shift register. SHCP is the clock input to your shift register, while STCP is the latch for the register. DS is the serial data input. MR, master reset is used to reset the shift register, in this case, we are going to connect it to 5V since we don’t need to reset it. Besides that, to enable the output, you need to connect OE to GND.

sr6
Timing diagram for 74HC595

To control the shift register in your program, send a low signal to your shift register. Next, shift 8 bits of data in 8 period of clock. Then, send a high signal to latch out the 8 bits of data. The reason to send a LOW signal before transfers all the data and a HIGH signal after complete transfers all the data is because the latch is positive edge triggered. On the positive edge of latch signal, all the serial data will be latch out. here is a function in Arduino which ease the job of shifting data, which is shiftOut(). We will discuss it on the code part.

Another analogy of mine on shift register is that data is like people who are queueing, the clock control the people enter one at a time, and the latch is eight gates to allow the people pass through the gate.

Let us start working with shift register and Arduino.

sr3
How to connect your shift register
sr5
Potentiometer to control speed of data update
sr4
Overall set up of circuit on a breadboard
sr3
8 LEDs to display output

sr2

Sample code to try with 74HC595 Shift Register

#define clock 9
#define latch 10
#define data 11
#define pot A0

byte value=0;

void setup()
{
 pinMode(latch,OUTPUT);
 pinMode(clock,OUTPUT);
 pinMode(data,OUTPUT);
 pinMode(pot,INPUT);
}

void loop()
{
 for(int i=0;i<=255;i++)
 {
 digitalWrite(latch,LOW);
 shiftOut(data,clock,MSBFIRST,i);
 digitalWrite(latch,HIGH);
 delay(analogRead(pot));
 }
}

In the setup() function, you need to set the pinMode for clock, latch and serial data as output. A potentiometer is connected to control the speed of data update.

As mentioned previously, first we need to reset the latch pin. Then shift in the data to shift register with shiftOut function, only then you set the latch pin to output the serial data.

shiftOut(datapin,clockpin,order,value)

– Datapin is the pin to output each bit, clockpin is used to toggle for clock signal. Order allows you to select order of output, either Most Significant Bit (MSB) or Least Significant Bit (LSB) first. The last parameter is the value to shift out.

Video demo:

Start working with shift register and Arduino now and share the project of yours using shift register.

Advertisements