Problems with the HC165 Shift Register

Hello! I was hoping to build a 32 key keyboard using 4 165s, but it seems I can't even get one to work!
I have Vcc connected to 5v, GND, CLK INH, SER, and Q! grounded, Latch to pin 4, Clock to pin 5, Q to in 3, and A - H as inputs from the switches

Sadly it seems that none of the inputs work except for H, which outputs all the inputs as HIGH (output in the serial monitor as 8 1s), even when connected directly to 5v. Even with that though, sometimes it just does whatever it wants

I was just wondering if anybody could help me find a solution. I've tried swapping out the chip, all the wires, and the code is copy/pasted from here, so I have no idea what the deal is.

Thanks! <3

you need to read the sticky post at the start of the forum on how to use the forum - it explains how to post you code using code tags -

you also need a wiring diagram - it can be hand sketched and a picture or scan of it

then someone can look at your code and wiring and help you - you want to make it easy for people to help - i.e. don't make them guess or need to go search for things

welcome to the forum - those chips are used by the truck load and a small single wire can stop everything - so should be someone that can glance at the code and wiring and get you going in the right direction

and Q! grounded,

No, leave that unconnected otherwise what salidude said.

The inputs don't have pullup resistors. Add a resistor to every switch.

DrDiettrich:
The inputs don't have pullup resistors. Add a resistor to every switch.

I had that from the beginning, apologies for the lack of clarity

Grumpy_Mike:
No, leave that unconnected otherwise what salidude said.

Will do, thank you

saildude:
you need to read the sticky post at the start of the forum on how to use the forum - it explains how to post you code using code tags -

you also need a wiring diagram - it can be hand sketched and a picture or scan of it

then someone can look at your code and wiring and help you - you want to make it easy for people to help - i.e. don't make them guess or need to go search for things

welcome to the forum - those chips are used by the truck load and a small single wire can stop everything - so should be someone that can glance at the code and wiring and get you going in the right direction

Apologies for the lack of these, attached is a diagram of 8 switches and 1 register

and here is the code

//Code for using a Arduino Micro as a keyboard using
//Geteron switches and the HC165 Shift Registers

int latchPin = 4;
int clockPin = 5;
int dataPin = 3;

byte switchVar1 = 72;  //01001000

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB
  }
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
}

void loop() {

  
  //Pulse the latch pin:
  //set it to 1 to collect parallel data
  digitalWrite(latchPin,1);
  //set it to 1 to collect parallel data, wait
  delayMicroseconds(20);
  //set it to 0 to transmit data serially  
  digitalWrite(latchPin,0);

  //while the shift register is in serial mode
  //collect each shift register into a byte
  //the register attached to the chip comes in first 
  switchVar1 = shiftIn(dataPin, clockPin, LSBFIRST);

  //Print out the results.
  //leading 0's at the top of the byte 
  //(7, 6, 5, etc) will be dropped before 
  //the first pin that has a high input
  //reading  
  Serial.println(switchVar1, BIN);

//white space
Serial.println("-------------------");
//delay so all these print satements can keep up. 
delay(500);

}

hope this can help you help me!

That schematic has lots of wiring missing, it is like trying to debug code when you only post a bit. As drawn that simply will not work.
It might be that the serial out of the shift register is not actually connected to the Arduino. Also the pull up resistors go nowhere.

Hi,
This might help.

https://www.gammon.com.au/forum/?id=11979

Tom... :slight_smile:

TomGeorge:
Hi,
This might help.

Gammon Forum : Electronics : Microprocessors : Using a 74HC165 input shift register

Tom... :slight_smile:

As a matter of fact it works perfectly now!
Thank you so much c:

dataPin MUST be INPUT!!!!