Cascading two 74hc165 not reading inputs correctly

Im trying to read inputs of the 2 74hc165 shift registers, however while some values are coming up as correct, sometimes some of bits dont properly respond to inputs. Im using an IR sensor to read inputs from it. its the TCRT5000. im using 2 on each registers to verify that its reading open and closed circuits as proper inputs. The values was will change to 1 if the IR sensor is connected, however when i move the input to another input pin, some of them are not properly updating or responding. some others do work properly. Is this a timing issue or a wiring issue? (Wiring information is on the line comments of the pin setup)

Thanks for any help!



int load = A0;             // PL pin 1 of both registers
int clockEnablePin = A1;   // CE pin 15 of both register
int dataIn = A3;           // Q7 pin 9 of the second 74HC165, Pin 9 of first register goes to pin 10 of 2nd
int clockIn = A2;          // CP pin 2 of both

byte inputData[2] = {B00000000, B00000000}; // Array to store the incoming data

void setup()
{
  // Setup Serial Monitor
  Serial.begin(9600);

  // Setup 74HC165 connections
  pinMode(load, OUTPUT);
  pinMode(clockEnablePin, OUTPUT);
  pinMode(clockIn, OUTPUT);
  pinMode(dataIn, INPUT);
}

void loop()
{
  // Load parallel data into the shift registers
  digitalWrite(load, LOW);
  delayMicroseconds(10);
  digitalWrite(load, HIGH);
  delayMicroseconds(10);

  // Enable the clock and read the data into the array
  digitalWrite(clockEnablePin, LOW);
  digitalWrite(clockIn, HIGH);
  inputData[0] = shiftIn(dataIn, clockIn, LSBFIRST); // Read 8 bits from the first shift register
  inputData[1] = shiftIn(dataIn, clockIn, LSBFIRST); // Read 8 bits from the second shift register
  digitalWrite(clockEnablePin, HIGH);

  // Print the data with all 8 bits
  Serial.println("Shift Register States:");
  Serial.print("Register 1: ");
  printBinary8(inputData[0]); // Print the first register's data as 8-bit binary
  Serial.print("Register 2: ");
  printBinary8(inputData[1]); // Print the second register's data as 8-bit binary

  delay(200); // Delay for readability
}

// Function to print a byte as 8-bit binary
void printBinary8(byte value)
{
  for (int i = 7; i >= 0; i--) {
    Serial.print((value >> i) & 1); // Print each bit
  }
  Serial.println(); // Newline for the next print
}

  • Always show us a good schematic of your proposed circuit.
    Show us good images of your ‘actual’ wiring.
    Give links to components.

  • Do the I.C.s have proper de-coupling ?

1 Like

I made this, the TCRT5000 VCC and gnd are all connected to the arduino 5V and Ground respectively, there is no decoupling capacitor in the breadoard
Link to TCRT5000: HiLetgo 10pcs TCRT5000 Infrared Reflective Sensor IR Photoelectric Switch Barrier Line Obstacle Avoidance Module Tracing Sensor Tracing Module for Arduino Smart Car Robot: Amazon.com: Industrial & Scientific

Realized I didnt show the connection of pin 9 to pin 10 of the 2nd register, updated to show it

  • Confirm you are using DO on the sensor.

  • Add a 100nF on each 165 power pin to GND, close to pin 16.
1 Like

Yes! im using pin D0
unfortunately i dont have a capacitor like that, I only have super capacitors on board (1F and 3F) and a 330uF capacitor

  • You need two 100nF (.1uF) capacitors.

  • Did you try adjusting the potentiometer for best switching ?

The IR sensors are working fine, the LED lights are lighting up when light is blocked, individually they also work fine. When I put the same IR sensor onto another input pin, it works fine. It seems the issue lies with the way the arduino is reading the input data from the 74hc165

  • Read this for comparison to what you are doing.

this code seems to use the SPI communcation, which im trying to avoid.
I downsized the code and am retesting with only one 74hc165, the binary values are proper, however When the IR sensor is released (no longer cut) some of the other values that are 0 also jump to one briefly. Im assuming this why you mentioned using a decoupling capatiors, this is likely the occurrence of noise?

Leaving inputs disconnected ("floating") otherwise?
With a 10k resistor to GND they'll be '0'.

yes, the other inputs are not connected so there floating. Maybe I can just fill all the inputs with IR sensors (i can only do 8 so ill just test with one register) Would this help with incorrect bits flipping?

They'd be in a definite state - 10k resistors fill the bill, less hassle.

using the same code I showed initally, they seem to be changing fine now, however, I realize that one of the bits connected to register 2, is showing up on register 1. So when the signal is cut, its changing on register 1 and not on register 2, the one it is connected into

to add to this, All floating inputs are now grounded with 10k. So only 8 of the pints actually have a a IR sensor (all register 1) register 2 is all pull down resistors. Ill have to wait for the nano capacitors to come in.

Try with pull-ups on the upper half and pull-downs on the lower and then vice versa.