Shift in Register

I have two 74HC165 chips with 12 push buttons. The buttons are pulled low by 10K resistors. All buttons are showing 5V on the board and when pushed, the 5V is transferring to the connected chip pin. However, the buttons are not registering on the serial monitor. Buttons 6, 7 and 8 all change the state of all the inputs, the rest of the buttons do nothing. I've lost count of the number of tutorials I've followed to try and get to the bottom of this - sure it is something really simple but I just can't find it!

Here's the circuit diagram

Here's the actual circuit as built (buttons numbered 1 - 12 left to right, top row then bottom row)

This is what the serial monitor is showing when button 6, 7 or 8 are pressed.

And the code being used

const int dataPin = 4;   // QH
const int clockPin = 2;  // CLK
const int latchPin = 3;  // SH/LD

const byte numBits = 12;  
  
void setup() {
  Serial.begin(9600);
  pinMode(dataPin, INPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
}
 
void loop() {
  digitalWrite(latchPin, LOW);
  digitalWrite(latchPin, HIGH);
 
  for (int i = 0; i < numBits; i++) {
    int bit = digitalRead(dataPin);
    Serial.print(bit ? "1" : "0");

    digitalWrite(clockPin, HIGH); 
    digitalWrite(clockPin, LOW);
  }
 
  Serial.println();
  delay(1000);
}

Any suggestions of where the error may lie or what might be causing this?

Many thanks.

See

You may have some electrical issues. Try your code in the simulator, and if it works

  • check your wiring
  • pull up your inputs, wire button to GND
  • add 0.1 uF caps 1 per IC between Vcc and GND

Then come back if it is still a software thing. Or still doesn't work.

HTH

a7

Solder all connections, or move the project to a solderless breadboard.

1 Like

Thank you. I'll have a look.

I have the same setup on both a fully soldered board and a solderless breadboard. Getting the same results from both. Will have a fiddle with the Wokwi

Doesn't look like the HC165 pins 8 are connected to GND

1 Like
  • Show us good images of the bottom of the board.

  • We don’t see any de-coupling capacitors on the board, they must be added.

  • Clock should go to Clock, Latch to Latch.

  • Your chip enables should be grounded.

  • Your switches are not wired properly.

I don't think your circuit diagram reflects your circuit. While the 165 power and ground pins are correct, you have pins 1 and 2 of the left chip connected to pins 2 and 3 of the right chip. Also pins 15 should be tied low. But I can't tell from the actual circuit picture how pins 1 and 2 are connected.

I haven't looked at your code.

Edited: pins 15 should be tied low.

Are you SURE all your buttons are mounted like this:

Not like this (input floats when button not pressed)?

  • An IR remote is one option of getting 44 switch inputs connected to an Arduino.

1 Like

Also, you have the four switches connected to the 165 on the right connected to pins 11-14, but they should be connected to pins 3-6. The most significant bit (H on pin 6) is shifted out first, so if you are only clocking 12 times, those four switches need to be connected to E, F, G and H.

@enthusiasticallyrubbish

1. Place the 74HC165 o the breadboard and connect it with UNO R3 as per circuit of Fig-1 to receive 10101010 from the parallel input pins of the shift register.


Figure-1:


Figure-2:

2. Uplaod the following untested sketch and check that the Serial Monitor shows 10101010 at 1-sec interval.

#include<SPI.h>

void setup()
{
    Serial.begin(9600);
    SPI.begin();
    pinMode(9, OUTPUT);
    //----------------------------    
    digitalWrite(9, HIGH);
    delayMicroseconds(10);
    digitalWrite(9, LOW);
    delayMicroseconds(10);
    digitalWrite(9, HIGH);
}

void loop()
{
      byte y = SPI.transfer(0x00);
      Serial.println(y, BIN);    //shows: 10101010
      delay(1000);
}

3. Change the parallel input signals among 0 and 1 and check that the reading of Serial Monitor chnages accrdingly.

4. Conect another shift register in series (Fig-2) with above shift register and check its functionality.

2 Likes
  • From Saint Nick Gammon

Using SPI

2 Likes

Thanks everyone, really appreciate the support. Will have a rebuild tomorrow!

  • Highly suggest you use the SPI technique as shown in Nick Gammon's example above.

  • Before you rebuild, suggest you review these links on soldering and wiring prototyping circuits:

Thanks @LarryD. This link helped me solve it. Now have the two chips chained and working correctly (also helped by a brand new breadboard as the old one was not really holding anything properly!).

Thanks again to everyone for their input. Amazing community!