Introduction: Shift Registers: How Do They Work?
Recently, I was going through the pile of old projects which I had made when I had just got into electronics. I found a 24 x 6 LED matrix which was my first 'complete' project. A lot of messy wiring, not perfect but it still works fine. At the time I made this project, I never thought about the components which were used, how did they work, etc. I just wanted to complete it as soon as possible and have some fun. And I'm sure there are many like me.
One such component used in the LED matrix was 74HC595 which is a Shift Register. Yet another popular device which is used when you run out of output pins. There are 24 columns which need to be controlled individually which means that you need 24 output pins on the Arduino (or any other microcontroller) which is a lot and makes the wiring messy. That is why shift registers are used. Now we can control 24 rows (or more) by using just 5 pins on the Arduino. Clever, isn't it?
In my previous Instructable, I made an LCD Trainer Kit which won a First Prize in Electronics Tips and Tricks Contest. It got some lovely comments from the people which suggests that the idea of getting back to basics is great.
In this Instructable, let us look at the working of a shift register and at the end build a small kit to see shift register in action.
Let's get back to basics!
Step 1: Things You Will Need
1x 74HC595 Shift Register
1x 16 pin IC socket
8x LEDs
8x 1k resistors
3x 10k resistors
3x Tactile push buttons
1x Perfboard
1x micro USB breakout board (optional)
Step 2: Know Your Shift Register
The shift register we will be using is 74HC595 which is an 8-bit Tri-state Shift Register i.e. with 8 outputs. Tri (3) states mean that the output can be set to either HIGH, LOW or High Impedance. Let us have a look at the pins of the IC and their function.
Note: Rising Edge - Transition from 0V to 5V (LOW to HIGH)
Falling Edge - Transition from 5V to 0V (HIGH to LOW)
Inputs (Control Pins)
Pin 14 - Serial Data In
Data is fed into the register from this pin. Serial means data is fed in bit by bit.
Pin 13 - Output Enable (OE)
This pin turns the output ON or OFF. It is an active low pin meaning that pulling the pin LOW enables the output. We will be connecting it directly to GND to make the output always ON.
Pin 12 - Storage Register Clock (RCLK)
When this pin is pulled HIGH, the data from the storage register is transferred to the output.
Pin 11 - Shift Register Clock (SRCLK)
A clock signal is provided to this pin. The data from Pin 14 (Serial Data In) is registered only at the rising edge of the clock. In simple words, when the clock signal rises from 0V to 5V, only then the data present at Pin 14 gets stored in the register.
Pin 10 - Shift Register Clear (SRCLR)
It is an active low pin. As the name suggests, when this pin is pulled LOW, it clears all the data from the storage register. We will be connecting it to 5V permanently so that the data is never cleared from the storage register.
Output
Pin 15, Pin 1 to 7 - QA to QH
These are the 8 outputs of the shift register.
Step 3: Putting the Kit Together
In the beginning, I had planned to use a project enclosure box. But since the components used are not panel friendly I decided to go with the perfboard. Plan the layout of components. Be creative in choosing the layout as long as it is sensible.
I used a micro USB breakout board as I will be powering the kit using USB.
The schematic for the build has been attached.
Step 4: Working
Let's get this thing running. We will try to light up LEDs at Q0 and Q1 i.e. 0000 0011
Note: Pushing the button makes that particular pin HIGH (or 1) and leaving the button makes it LOW (or 0).
Steps to be followed:
1. First, data is made 1 (HIGH). Hold down the Data push button. But the data has not been stored in the register yet.
2. The data is stored in the register when the clock signal rises from 0V to 5V i.e. on the Rising Edge. While holding the Data push button, push the Clock push button once as the IC looks for the rising edge only. Now the data is stored in the storage register as 0000 0001. You can now leave the Data push button.
3. To reflect the same in the output, push the Latch button once. You should see the LED of the first bit glowing. Great!
4. We are not done yet. Again hold down the Data push button and press the Clock push button once. Now the old 1 gets shifted to the left by one bit and the newly added 1 takes its place. Now the storage register will look like 0000 0011.
5. Press the latch button to reflect the same in the output.
That's it!
Now you might be able to understand why shift registers are used. In this case, 8 outputs can be controlled using only one line. Shift registers come in handy when you run out of output pins on the microcontroller.
I have made a stop motion video to make things more clear. Check out the video on YouTube.
Step 5: Have Fun!
Since you now know how a shift register works, you can use it along with Arduino and make an awesome project! Click here to know more interfacing 74HC595 with Arduino.
Thank you for sticking till the end. Hope you all love this project and learned something new today. Let me know if you make one for yourself. Subscribe to my YouTube channel for more upcoming projects.
17 Comments
4 years ago
That was a great write up and a very cool explanation. I liked the stop motion paper animation. I know you are trying to keep it minimal so that it is digestible but it might be worth discussing pin 9 & 13 more. Or indicating what someone can learn next. Pin 9's overflow bit allows you to chain multiple registers together. And looking at pin 13, why would you want to disable output? What was the the high-impedance state you mentioned in the intro? Pulling it high when not in use so that noise doesn't accidentally clock the data or output. (obviously you know this, i'm being rhetorical) But even cooler is that once you view the Output Enable pin as Chip Select suddenly your interface to the register looks a lot like SPI which can really change your view of what a shift register can do.
Reply 4 years ago
Hi. About the 74HC595 please go and check my Instr. at
www.instructables.com/id/UNIVERSAL-PCB-FOR-ATtiny-...
There I use the 74HC595 to different things. Mostly used in ”daisy-chain”.
1. To your que. About the ”High impedance-state”, it’s actually a bit missleading impression. What it is that the ”Output is neither + or minus”, it’s totally ”disconnected” from the grid.
Why is this needed? Well, there might be some other devices allso using these same lines, thus needed to ”disable” this unit.
Actually it goes the other way around: When you have several units sharing them same Address and/ or Data lines, you do ”Enable” one chip at a time and disable the rest of them. Just to avoid ”collisions/ shortage” with them units.
2. Pin9. You call it for ”owerflow” and that’s what it actually is. But it’s cleverly used to be a ”transporter of data”.
If you in Arduino or ATtiny use the powerful shiftOut command twice, then first will shiftOut the outermost 595 data, (data_led), it will ”pass through” the first one, and then shiftOut the second, (data_swb), (here I’m using my own data_1 and latch_1 because I’m using data_2 and latch_2 in another place, thus hawing two separate datachains):
shiftOut (data_1,clock_1,MSBFIRST,data_led);// LED BANK
shiftOut (data_1,clock_1,MSBFIRST,data_swb);// SWITCH BANK
And then ”Latch” them both at the same time
digitalWrite (latch_1,HIGH ); //
digitalWrite (latch_1,LOW); //
3. The 74HC595 actually IS a SPI, (Serial Periferial Interface), but using 3 lines for that. Many ”nodes”, howewer, have a ”built-in” 74HC595 to translate the data to the unit e.g.
a LCD display needs n’ lines to be driven, now, there are ”adapters” to transform the 3-line’s to the LCD-function. These adapters simply have a 74HC595 + some in there gut.
Check out my other Instr’s allso
Please answer me if You read this?
Reply 4 years ago
Yes, you are right. I should have mentioned the working of pin 9. I tried to keep it simple with only one register. I will update the Instructable. Thank you!
Question 4 years ago
Hi , you seem to know alot about micro circuits( well alot more than i do in any event...)
great instruct by the way.
i have been trying to figure a way to make the sweeping effect without using arduino or anything, i have found a couple diy's on the net, but they don't explain in laymens how to build the thing. can/will you be so kind as to help me with this project?
i have an old style Volkswagen Fox and i want to redo the lights to be similar to the new Audi design... here is a youtube link of what i would like to accomplish.
Please help me. ...
Ps: i have no formal training in electronics or the like. what i have learned is what i could piece together from "instructables.com" and similar sites.
Thanx in advance
Joe
Answer 4 years ago
Yes. I think I can do this.
Reply 4 years ago
Would you be so kind and make an instruct on it...please, please....that would help me so much...
Regards
Joe
4 years ago
Nice project! I made this animated .gif a while ago to help explain shift registers to students.
http://www.introbotics.com.au/projects/beginner/Sh...
Hope this can help anyone to better visualize how the 74HC595 works.
For more info go to: http://www.introbotics.com.au/projects/beginner/Sh...
Reply 4 years ago
Excellent work!
4 years ago on Step 5
Great presentation and operation info! I have a shift register game I call 'SHIFTY'. It has 16 bi-color LEDs placed in a 4 x 4 format and played to simulate SUDOKU with colors instead of numbers. Using two buttons, one to input Red and Yellow the other for Green and 'no light' Spaces. The player first predetermines and writes down a 16-LED color combination they want each LED to be for the final display to hopefully win. Using the two buttons for selected color inputs a combined total of only 32 inputs are allowed and then, whatever colors are displayed at that time, lock into place and no further inputs are allowed until a 'reset' is made for a new challenge. Each time either button is pressed all lights displayed, and their colors, 'shift' one place forward. Each possible color combination, 16.4 billion of them, can be accomplished with exactly 32 inputs. If you like I can give you the schematic and circuit board layout. John at jfmcircuits@twc.com
Reply 4 years ago
That looks interesting. I would like to make one. Also, you can make an Instructable for it and submit it to the Puzzle Contest which is going on right now.
4 years ago
Have you had no trouble with your (un-debounced) clock input?
4 years ago on Step 5
Great educational project. Very well presented. Excellent graphics.
4 years ago
There are so many old TTL and DTL DIPs out there to play with. And each has their own story and use. The mixture of old tech and new can even make new projects that were either hard to do back then, or nearly impossible. So your project brings new life to older tech and DIPs. I like that. And the great thing about those old Tech TTL and DTL DIPs, are they are very cheap to play with as well. Thumbs Up for sure.
Reply 4 years ago
There was a time when someone invented the TTL-technology.
Back in those days there was ”allso” tech’s known as DTL & RTL, (Diod/Transistor, Resistor/Transistor), logics.
The major problem with tfese 74xx chips was tho power to be within 4,75 ~5,25V.extreme limits.
That would be a way of a narrow window for the power-supply.
Then there came these ”FET-trans.”, and then them ”CMOS-trans.” and then them ”MOS-FET*s” logics.
Luckely for us they converted the LS74595 to 74HC595, that would be the ”next best” IC ewer, the best is the 555.(which isn't actually a "logical" IC, but anyway)
Reply 4 years ago
True! Old tech is the best way to learn electronics!
Question 4 years ago on Step 4
does this mean the shift register you used actually has 8 x 8 x 9 combinations?
Oh, I completely agree with the 'no 3D printer needed' comment. Not everyone has one or knows how to program one.
4 years ago on Step 5
GREAT IDEA!!... FINALLY, SOMETHING THAT DOESN'T REQUIRE A 3D PRINTER......