I would like to capture the state of some push buttons with a shift register (CD4014B). I am trying to troubleshoot and identify if the problem I'm having is hardware or software.

Printing the byte to the serial monitor I can see 11111111 when no buttons are pressed.. The expected result.

The problem I'm having is no matter which button I press all bits remain 1... Except button 'D'. When 'D' is pressed all bits are 0.

Here is my schematic:

shift register schematic

(Side note: I don't currently have actual push buttons installed. I'm simulating a button press by connecting the pin header to ground)

int dataPin = 8;
int clockPin = 9;
int latchPin = 10;

void setup() {
    pinMode(latchPin, OUTPUT);   
    pinMode(clockPin, OUTPUT);
    pinMode(dataPin, INPUT);

    digitalWrite(latchPin, LOW);    
    digitalWrite(clockPin, LOW);


byte shift() {

  byte data, i;

    /* first clock pulse gets parallel load */
    digitalWrite(latchPin, HIGH);

        /* clock low-high-low */
        digitalWrite(clockPin, HIGH);
        digitalWrite(clockPin, LOW);

        /* if this is the first bit, then we're done with the parallel load */
        if (i==0) digitalWrite(latchPin, LOW);

        /* shift the new bit in */
        int temp = digitalRead(dataPin);
        if(temp) {
            data = data | (1 << i);



void loop() {
    byte buttons = shift();
    Serial.println(buttons, BIN);


Is my schematic wiring correctly, and is my code error free? And in either case, why am I not getting the desired results?


1 Answer 1


Your code is full of errors. Your pin index's are wrong and clock, latch and data pins are all inputs. With inputs defined as outputs you get no useful results.

According to the datasheet, you should just set pin 9 'high' so it always parallel loads, then use clock to shift data out. Not sure why you have an inner loop for the latch/load pin.

NOTE: I would use an 8 section DIP switch to input whatever pattern you want, then have the MPU toggle the control pin and clock pin to shift the data out at Q8, which you have flagged as 'IN_DATA', although I do not see that on the connector.

Slow down and pay attention to details, double and triple check your work, or software will drive you crazy.

  • \$\begingroup\$ What do you mean my pin index's are wrong? Those are the pins connecting to the arduino. And clock and latch are inputs on the shift register, but from the arduino they're outputs. \$\endgroup\$
    – bwoogie
    Commented Sep 30, 2018 at 5:13
  • \$\begingroup\$ Where are you taking in your data from pin 8 (4014B) to "IN_DATA"?. You should use a capture pin as this is still boolean data. Best to use a serial input and pad it (data) with start and stop bits. \$\endgroup\$
    – user105652
    Commented Sep 30, 2018 at 5:20
  • \$\begingroup\$ According to the datasheet, pin 9 defines if each flip-flop takes data from the parallel input, or from the previous flip-flop output on the next clock rise. You must set it to high for one clock cycle to load parallel data, and then to low to shift it out the content of the register on the next clocks. \$\endgroup\$
    – sweber
    Commented Sep 30, 2018 at 7:15
  • \$\begingroup\$ @sweber. Yep, the data sheet has all those details. \$\endgroup\$
    – user105652
    Commented Sep 30, 2018 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.