Shift registers can be used in a wide variety of applications. You can, for example, use them to convert multiple parallel data lines to a single serial line and vice-versa. This technique can be used to extend the number of available in- and outputs of a microcontroller and this article will show you how you can achieve this.
Parallel to serial conversion
I’ll use this method to make it seem like an Arduino has seven additional input pins by utilizing a parallel to serial shift register to convert multiple individual lines of a bus (eight in this case) to a single serial data line that can be read by the microcontroller.
This will allow you to reduce the number of necessary inputs by seven. However, this method will require you to use two additional outputs for controlling the shift register:
In this configuration, all eight data lines of the bus are connected to the eight parallel inputs of the shift register. The state of each line can be controlled with the DIP switch. The Arduino first tells the shift register to latch the data word by using the mode select line. It then generates the clock signal and the shifter pushes the next bit to its serial output which is then read by the Arduino prior to generating the next clock pulse. This is repeated eight times.
I wrote a full tutorial at maker.pro together with a short intro to shift registers and I only want to mention the following:
The big downside to this method is the additional overhead that the microcontroller has to deal with. It has to create a clock signal and read the eight bits one at a time.
Serial to parallel conversion
This is one method that make it seem like a micro controller has more output pins than it physically does and it will allow you to convert a single serial output to a parallel bus by using one serial to parallel shift register:
The bits get clocked into the register and once all of them got loaded, the output of the register is enabled. The previously saved bits then get output by the register’s parallel outputs. Anyway, this configuration will also require two additional outputs for controlling the shift register.
You can find the full tutorial, together with two alternative methods, here!
The test application in the tutorial does not only support the serial to parallel conversion of a full data word. It also supports shifting any number of bits and can, therefore, be used to visualize the logical shift operation.
Decoders can also be used as an alternative to shift register. I did this in the Nixie Tube Thermometer project. I also discuss the pros and cons and differences between these methods in this maker.pro article.