Shift register (input)

The 74HC165 is an 8-bit parallel-load or serial-in shift register.

Figure 1: Pin-out 74HC165.

Wiring:

  • Pin 8 (GND): GND
  • Pin 16 (VCC): Voltage 5V
  • Pin 11-14 & 3-6 (A-H): Input 1-8
  • Pin 1 (SH/LD): shift/load pin
  • Pin 2 (CLK): Clock pin
  • Pin 9 (QH): Data output pin
  • Pin 15 (CLK INH): Clock-inhibit pin (or GND)

Clocking is accomplished by a low-to-high transition of the clock (CLK) input while SH/LD is held high and CLK INH is held low. CLK INH can be wired to GND to save a pin on the microcontroller. Unused inputs pins should be grounded as well.

Multiple 74HC165 ICs can be daisy chained by wiring the serial-out pin 9 (QH) to pin 10 (SER) of the succeeding IC allowing us to tie multiple 74165 ICs together that can be controlled using only 3 pins.


#define SO  2     // SER/DATA (Pin 9) of 74HC165 is connected to D2 of Arduino
#define SH_LD  3  // SH/LD (Pin 1) of 74HC165 is connected to D3 of Arduino
#define CLK  4    // CLK (Pin 2) of 74HC165 is connected to D4 of Arduino

// variables will change:
int i = 0;         // variable for reading 8-bit data
int PinState = 0;   //read the state of the SO pin
int Parallel_data = 0;//To store parallel data

void setup() {
  // initialize SH_LD & CLK pin as output:
  pinMode(SH_LD, OUTPUT);
  pinMode(CLK, OUTPUT);
  // initialize sER-Serial output pin as input:
  pinMode(SO, INPUT);
}

void loop() {
  digitalWrite(CLK, LOW);
  /*Parallel data that will be entered through D0 - D7 Pins of 74165  **/
  digitalWrite(SH_LD, LOW);
  delay(5);
  /*******************  INHIBIT SECTION START HERE  *****************/
  digitalWrite(SH_LD, HIGH);
  /*******************  INHIBIT SECTION ENDS HERE ******************/
  /************** SERIAL SHIFT SECTION START HERE **********/
  //Read 8-bit data from 74HC165
   Serial.print("Parallel Data:");
   for(i=0;i<8;i++)
    {
	PinState = digitalRead(SO);// read the state of the SO:
       digitalWrite(CLK, LOW);
	delay(1);
	digitalWrite(CLK, HIGH);
	delay(1);
	Serial.print(PinState); //Send out one by one parallel data to serial monitor
	Parallel_data = (Parallel_data<<1)|PinState; //Store the value in Parallel_data
    }
   Serial.println();
   delay(1000);
}