74HC165 8 bit Parallel in/Serial out Shift Register

Previously, I’ve made a tutorial on how to use a 74HC595 Serial In/ Parallel Out Shift Register, which is useful in expanding output pins. In this tutorial, I am going to show another shift register which is capable of expanding input pins. The IC that I am using is 74HC165 Parallel In/ Serial Out Shift Register. One of the advantages that need to be stressed on is that by using only four pins, I can get eight input pins. Moreover, it can be cascaded, thus you can have any amount of input pins with only four pins with the help of this shift register.

74HC165 Parallel in, Serial Out Shift Register
74HC165 Parallel in, Serial Out Shift Register

Some of the features of 74HC165:

  • 8 bit Parallel Input
  • Serial output
  • Can be cascaded/ daisy chained

For more details on the chip, please refer to the datasheet here.

74HC165 Pin Diagram
74HC165 Pin Diagram
Pin Description
Pin Description

The input pins of the shift registers are pin 11 to 14 (D0 to D3) and pin 3 to pin 6 (D4 to D7). The input voltage acceptable range is between GND to Vcc, where maximum allowable voltage for Vcc is 7V according to the datasheet. However, it is recommended to operate the chip at 5V. 74HC165 has two output pins which are Q7 and /Q7, where /Q7 is the complement (inverted) of Q7.

After discussing about the input and output pins, let us move on with the control pins. To control the shift register, you would need three pins which are parallel load input (PL), clock input (CP) and clock enable input (CE).

Another pin that is useful especially when you want to cascade a few shift registers together, which is Serial Data Input (DS). Schematic on how to cascade the shift register will be shown later on.

Now, let us look into detail how to use the shift register. Initially, you need to make the parallel load input high. A low signal will triggers the input to be loaded into the shift register. This gives you a flexibility when to read the input to the shift registers. Besides, you want to stop reading the inputs while serially sending the output.

Next, you need to send the clock pulse to the shift register in order to obtain the serial output. However, you would need to set the clock enable before clocking out the data. After the clock is enabled, the parallel input data will be sent out in eight clock pulses.

A summary of the shift register operation is shown is the timing diagram below.

Timing Diagram for 74HC165
Timing Diagram for 74HC165

A simple schematic showing how to connect your 74HC165 Shift Register to Arduino. Notice that I am using a pull up resistor of 10k ohm on all the inputs. You can can also change it into pull down resistor network connection.

Schematic for 74HC165
Schematic for 74HC165

To cascade between two 74HC165 shift register, all you need to do is to connect the Serial Output (Pin 9) of first stage into Serial Input (Pin 10) of the second stage. You can cascade a lot of shift register to get tons of inputs. An example application of cascading the shift registers to get more input is the Arduino Piano that I have made previously.

Cascading 74HC165 Shift Register
Cascading 74HC165 Shift Register

Some of the images of setup on a breadboard.

Circuit setup on breadboard
Circuit setup on breadboard
Connection from 74HC165 to DIP switches
Connection from 74HC165 to DIP switches
LCD Display the Shift Register Input
LCD Display the Shift Register Input
All Input goes low
All Input goes low

In order to ease the process of reading data from shift register, I am using an Arduino built in function which is ShiftIn(). More details regarding the function, please refer Arduino Reference.

ShiftIn(data,clock,order)

– The data is the input pin on Arduino to read the output from shift register whereas the clock is the pin connected to shift register clock. For the order, you can choose either MSBFIRST or LSBFIRST.

Note that you need to control the parallel load pin by yourself since it can’t be controlled by the shiftIn function. It can be controlled simply by digitalWrite to either HIGH or LOW.

Below is the code I used to test out 74HC165 Shift Register:

//shift register experiment
//coded by zxlee
//iamzxlee.wordpress.com

#include <LiquidCrystal.h>

LiquidCrystal lcd(6,7,8,9,10,11);

#define enable 2
#define load 3
#define clock 4
#define data 5

void setup()
{
lcd.begin(16,2);
pinMode(enable,OUTPUT);
pinMode(load,OUTPUT);
pinMode(clock,OUTPUT);
pinMode(data,INPUT);
digitalWrite(load,HIGH);
digitalWrite(enable,HIGH);
lcd.print("Input = ");
Serial.begin(9600);
}

void loop()
{
digitalWrite(load,LOW);
delayMicroseconds(5);
digitalWrite(load,HIGH);
delayMicroseconds(5);

digitalWrite(clock,HIGH);
digitalWrite(enable,LOW);
byte incoming=shiftIn(data,clock,MSBFIRST);
digitalWrite(enable,HIGH);

for(int i=7;i>=0;i--)
{
if(bitRead(incoming,i)==1)
{
lcd.setCursor((15-i),0);
lcd.print("1");
}
else
{
lcd.setCursor((15-i),0);
lcd.print("0");
}
}

}

Last but not least, a video demo showing the operation of 74HC165 Shift Register

 

18 thoughts on “74HC165 8 bit Parallel in/Serial out Shift Register

    1. Hi J Dacampo, Thanks. If you would like to cascade 74HC165, the only modification you need to make is add the number of shiftIn() depending on how many you are using.

      Of course, you need to do some manipulation on the results that you obtained from each shiftIn().

      1. Hey zxlee, great article, It helped me a lot. I am also trying to cascade two shift registers, and I’m having trouble with the serial data from the second shift reg.
        What do you mean by “the onlu modification you need to make is add the number of shiftIn()”?

  1. Why have you left out the decoupling capacitors? You need a 0.1uF ceramic capacitor between the power pin and the ground pin of EVERY shift register chip. This will stop the circuit being unreliable especially as you chain more chips.

    1. Hi Grumpy_Mike, I didn’t knew that previously. Now I know that it is better if we can include a 0.1uF ceramic capacitor for all digital circuit for each IC.

  2. I have made this project but I am not able to send the “10000101” bits to print into the character on hd44780 character LCD, How to print this incoming input data on lcd into character ?

    As I have given lcd.print (); but the same “10000101” is showing on the LCD, so, how to print it into character on LCD ?

  3. Thanks for your kind reply…
    See I have followed you and understood your line 39 to 51 is printable characters. In my case I have attached 74HC165 TO GET PARALLEL DISPLAY DATA FROM AN INSTRUMENT TO CONVERT IT INTO SERIAL AND THEREAFTER SERIAL DATA INPUT TO ARDUINO FOR DISPLAYING THE OBJECT OF THE INSTRUMENT INTO THE DISPLAY OF ARDUINO. AND THERE IS MY PROBLEM IN SPTE OF GETTING THE “INSTRUMENTAL DISPLAY OBJECT” i AM GETTING THE “011000” VALUE ACCORDING TO YOURS. WOULD YOU PLEASE BE ABLE TO GUIDE ME TO CONVERT THIS “011000” DATA TO ACTUAL DISPLAYING OBJECT ? THANKS

    FOR YOUR INFORMATION : THE ACTUAL DISPLAY OF THIS INSTRUMENT HAS BEEN DISCONTINUED AND THEREFORE i WANT TO TAKE THE DISPLAY DATA OF THE INSTRUMENT INTO ARDUINO THROUGH ON ITS LCD. THANKS…..

  4. Dear
    Object means the instrument which is a digital keyboard for music playing and its display lcd is not available and its very much important to me, (its my first keyboard) therefore I want to get the display data (or display screen) of the instrument on arduino lcd.

    for your information : the object purely means the display screen of the instrument, did it make you clear to understand ? Thanks

    1. Again to make you clear the parallel pin for the display ic of the instrument has been attached with 74HC165 AND ITS SERIAL OUT HAS BEEN GIVEN TO ARDUINO TO READ THE DISPLAY DATA FROM THE INSTRUMENT AND DISPLAY OUT ON THE ARDUINO SCREEN IN SPITE OF THE THE “01” VALUE.

    2. From my understanding, you have the buttons well connected to the shift register and the output of shift register is also connected to the Arduino. If you are using the same display (16×2 HD44780 LCD), then the code above should have worked for you. If you are using other display, you may need to change to code for the display.

      Another thing that you can try is, first make sure you read what is exactly send from the shift register. Change the code to display it using your serial monitor. From there, if you able to read the correct input from your buttons, then its just the display code you need to work on.

      Hope this helps.

  5. Hello friend!
    I am not going to leave you –
    Can you help me regarding forwarding the “High / Low” value to DDram of HD44780 LCD ?
    For example : I want to add the code DDRAM = 0b0001, PORTB = 0b0010 in order to make the Arduino capable to fetch the Reading Data from 74HC165 to LCD Port to control it manually.

    Thanks & Regards

    1. Hi Sammy, I am not clear what DDRAM you meant. If you need to read the inputs to shift register and display it on your HD44780 using Arduino, the code provided above would work for you.

      Regarding the pin connections, check out the top section of code “#define” is where all the pins are declared. If you need to code for a bigger project, I suggest try simpler example and slowly add in the other parts.

      Good luck!

Leave a Reply to James Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s