I'm trying to control a 4-digit 7 segment display with an Arduino Nano, but I'm getting something wrong. I'm using the ICSP header to interface with a 74HC595 Shift Register which is then connected to the display. I've tested and retested the connections and everything seems to be alright, however the shift register doesn't have the desired output, and I notice it only shifs one single bit when I press the reset button on the arduino board.

74HC595   |    A. Nano
DS     <-----> MOSI (ICSP)
SH_CP  <-----> SCK (ICSP)
ST_CP  <-----> D6
MR     <-----> 5V (ICSP)
OE     <-----> GND (ICSP)
VDD    <-----> 5V (ICSP)
GND    <-----> GND (ICSP)

My code:

//pin connected to STCP
const int latchPin = 6;
//pin connected to SHCP
const int clockPin = 17;
//pin connected to DS (MOSI)
const int dataPin = 11;

byte val=0;

void setup() {
  // put your setup code here, to run once:
  //SPI pins are output



void loop() {
  // put your main code here, to run repeatedly:
  for (int i=0; i<8; i++) {


void updateRegister() {
  //pull latch low to write new bits to the register
  //shift out the data
  //pull latch pin high so that the leds light up
  • This site has a question and answer format. What is your question, exactly? (Note that questions generally end with a question mark). Please read How do I ask a good question?
    – Nick Gammon
    Commented Jan 26, 2016 at 7:10
  • Please post a schematic of your wiring. You say in the question that you are using the ICSP header, but then the code uses pins 6 and 17 which are not ICSP (or SPI) pins.
    – Nick Gammon
    Commented Jan 26, 2016 at 20:13

3 Answers 3


const int clockPin = 17;

I'm pretty sure that should be 13, not 17.


It is extremely confusing to have a variable val and then use _val in your function but then:


As James pointed out, you are not sending the value passed to the function, to the shift register.

Also this is just going to give you a boolean:


Why take "not i" there?

I suggest you use SPI and not muck around with shiftOut. I have a page about the 595 chip including example code. eg.

#include <SPI.h>

const byte LATCH = 10;

void setup ()
  SPI.begin ();
}  // end of setup

byte c;
void loop ()
  digitalWrite (LATCH, LOW);
  SPI.transfer (c);
  digitalWrite (LATCH, HIGH);
  delay (20);
}  // end of loop
  • I posted the code with some errors (I was paying with the varaibles trying to solve the problem). As it was it was bovisously not going to work, but that was not the cause of the problem. I tried that snippet with the SPI library, but the display/leds do not light up at all. Also, it just crossed my mind - could the problem be caused by calling shiftOut() on SPI pins?
    – joaocandre
    Commented Jan 26, 2016 at 3:59
  • What LEDs exactly?
    – Nick Gammon
    Commented Jan 26, 2016 at 4:31
  • could the problem be caused by calling shiftOut() on SPI pins? - No. If you don't call SPI.begin() then SPI is inactive.
    – Nick Gammon
    Commented Jan 26, 2016 at 7:13
  • The leds on the 7-segment display
    – joaocandre
    Commented Jan 26, 2016 at 10:58

Do you need to add the _ to the shiftOut(dataPin,clockPin,LSBFIRST,val); ?

  • James, you were right about the underscore, but the Stack Exchange system automatically flags very short answers. If you expand it out a bit more you are protected from this automated flagging. Welcome to Arduino Stack Exchange. :)
    – Nick Gammon
    Commented Jan 26, 2016 at 0:23
  • It was a mistake, I was tinkering with the code. I've updated the question, but I can say that was not the source of the problem.
    – joaocandre
    Commented Jan 26, 2016 at 3:57
  • Your updated code sends 0 to the shift register, so I'm not too surprised nothing lights up.
    – Nick Gammon
    Commented Jan 26, 2016 at 7:04
  • The 7-segment display has a common anode, sending a '0' to the shift register should light up all the segments (an '8'), since I'm pulling the anode up with 'digitalWrite(3,HIGH); '
    – joaocandre
    Commented Jan 26, 2016 at 11:00

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.