How to get the value of eight A3144 hall sensors connected with a parallel to serial shift register 74HC165 when a magnet is detected or brought near?

The below code only gives 11111111 on serial monitor. But I want to get the value from each of the hall sensors when a magnet is detected or taken away from the sensor.

int load = 7;
int clockEnablePin = 4;
int dataIn = 5;
int clockIn = 6;

void setup() {
Serial.begin(9600);
pinMode(load, OUTPUT);
pinMode(clockEnablePin, OUTPUT);
pinMode(clockIn, OUTPUT);
pinMode(dataIn, INPUT);
}

void loop() {

//Write pulse to load pin
digitalWrite(load, LOW);
delayMicroseconds(5);
digitalWrite(load, HIGH);
delayMicroseconds(5);

//Get data from 74HC165
digitalWrite(clockIn, HIGH);
digitalWrite(clockEnablePin, LOW);
byte incoming = shiftIn(dataIn, clockIn, LSBFIRST);
digitalWrite(clockEnablePin, HIGH);

// Print to serial monitor
Serial.print("Pin States: \r\n");
Serial.println(incoming, BIN);
delay(200);
}

Please post a schematic of your project showing how the sensors are connected to the shift register

@UKHeliBob

That is a hall switch, working voltage minimum 4.5V, so 5V is okay.
Are those 1k or 10k resistors ? Both is okay.

The Wokwi simulation has two examples for the 74HC165 : https://docs.wokwi.com/parts/wokwi-74hc165.
The examples are slightly different for the signal usage. You can start the simulation and see that both work.

I'm not sure that the shiftIn() will work in this situation. I read its documentation and the moment the data is captured might not be correct for the 74HC165.
Can you write the clock toggle with digitalWrite() as in the Wokwi examples ?

The 74HC165 is a little weird. The data-bit has to be read first, then followed by a clock pulse. I think that the pulseIn() is for signals that generate the clock pulse first and read the data-bit after that.

const int dataPin = 5;   /* Q7 */
const int clockPin = 6;  /* CP */
const int latchPin = 7;  /* PL */

const int numBits = 8;   /* Set to 8 * number of shift registers */

void setup() {
  Serial.begin(9600);
  pinMode(dataPin, INPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
}

void loop() {
  // Step 1: Sample
  digitalWrite(latchPin, LOW);
  digitalWrite(latchPin, HIGH);

  // Step 2: Shift
  Serial.print("Bits: ");
  for (int i = 0; i < numBits; i++) {
    int bit = digitalRead(dataPin);
    if (bit == HIGH) {
      Serial.print("1");
    } else {
      Serial.print("0");
    }
    digitalWrite(clockPin, HIGH); // Shift out the next bit
    digitalWrite(clockPin, LOW);
  }

  Serial.println();
  delay(1000);
}

I also tried the above code from the website wokwi but I still get 11111111 as output and there is no change visible when a magnet is brought near or taken away. Is it then something wrong with the connection? I have already shared the schematic diagram of it. What could possibly be wrong and how can I identify and correct it?

Have you connecting the Clock Enable to GND ?

Make a few test-sketches.
Connect a hall sensor to a digital input to check if that works.
Then connect GND and 5V to some inputs of the shift register instead of the hall sensors, try to read that.

Breadboards have often bad contacts and jumper wires can be broken.
Do you have a multimeter to check all the voltages and all the signals ?
Can you upload a photo of your project ?

Keep in mind that it is possible that your 74HC165 is broken.

The Wokwi examples have the Clock and Latch just like you, but they use the normal output, and you the inverted output of the 74HC165. That should be no problem.

I checked the connection through multi-meter as per best of my limited knowledge on the subject but all the components seemed to be working. I also replaced shift register with a new one. Also, one thing I found is that even if I remove all the hall sensors, the serial monitor shows 11111111 in loop again and again which means it is not even showing this with the help of hall switches. What should I do then?

Isolate the problem.
Forget about the hall sensors, and test the shift register.
Connect a few inputs to GND and a few to 5V. Use resistors for that if you are not sure if your chip is 180 degrees rotated.
Make a test-sketch for the shift register. You could change the latch and clock and then wait a few seconds and print a message to the Serial Monitor. Then you can measure that with a multimeter and try to keep up.

  digitalWrite(latchPin, LOW);
  Serial.println("Latch LOW");
  delay( 2000);

  digitalWrite(latchPin, HIGH);
  Serial.println("Latch HIGH");
  delay( 2000);

Thank You @Koepel I have checked my connections and when I bring a magnet close to the hall sensors the voltage on them which is apprx. 4.5V becomes 0V and when I remove the magnet the sensor turns back to 4.5V. This means that all the hall sensors are responding to the magnets which makes my connections alright. So, the problem left is with code. What is wrong in this code? I want to get 0 when magnet is brought closer to the sensor and 1 when taken away.