Introduction: Arduino Powered 7 Seg LED Display Using Shift Registers - I Made It at TechShop

Seven segmented displays are great. They are pretty simple, don't take much power, and have a lot of flexibility when it comes to displaying numbers. But setting aside 14 pins just to run it is such a pain. If only there was a way to use them without sacrificing so many precious pins. Turns out there is! Shift Registers are logical IC's that can hold or shift data sent into them.  They only take up three pins! Combine this with the arduino function "ShiftOut" and there is a lot more options suddenly open. Oh, and one more great thing. They can be chained together to have even greater flexibility and still only using three pins. Just another one of the many things that I made at TechShop today.

http://techshop.ws

Step 1: Materials

Arduino Uno

2 digit 7 segmented display (common anode)

2x 74HC595 (the shift registers can be picked up on places like sparkfun.com for about $1.50)

14x 660ohm resistors

breadboard

wire

usb cable

Step 2: Circuit

Now this can get a little dense and crazy if you're not careful so plan ahead and try to be as clean as possible. Not only do you have to keep track of which led goes where, you also have to keep track of how it interfaces with the shift registers. I used two colors for wiring so I knew which digit when where. Following the schematic and labeling your wires will be your best bet. Don't forget that because this is a common anode display all of the led's will be on when the IC sinks the current into them instead of being a source. 

Step 3: Shift Registers

But how does this all work? Shift registers have a very specific function. They either store a digital state or shift that state to the next bit on the next clock cycle. This means that a stream of bits can be shifted into registers in combination with the clock using just those two inputs. It doesn't "erase" anything, it just tries to shift it left and out to another register if possible. The third input, the latch, is used as a read/write safety. Even thought the clock tells when to shift, the latch must allow a shift to happen. If the latch is high, then data cannot be written to the register and the register holds the data.

Step 4: Code

Similar to the port manipulation process in an earlier instructable, the positions of each led need to be translated into numbers. By marking the combinations that result in numbers and formatting that into binary of hex data, each number can be easily accessed. 

This is the code for making the shift registers count from 0 to 99 and loop. Notice how the latch first has to be set low, then shifted out out, then set high again. The latch is what allows the registers to retain their position in between clock cycles. The second digit comes first because it is sent into register 1 and then shifted by 1 byte out to register 2 as digit one takes its place.



#define LATCH 4
#define CLK 3
#define DATA 2

//This is the hex value of each number stored in an array by index num
byte digitOne[10]= {0x6F, 0x09, 0x73, 0x3B, 0x1D, 0x3E, 0x7C, 0x0B, 0x7F, 0x1F};
byte digitTwo[10]= {0x7B, 0x11, 0x67, 0x37, 0x1D, 0x3E, 0x7C, 0x13, 0x7F, 0x1F};

int i;

void setup(){

  pinMode(LATCH, OUTPUT);
  pinMode(CLK, OUTPUT);
  pinMode(DATA, OUTPUT);

}

void loop(){

  for(int i=0; i<10; i++){
    for(int j=0; j<10; j++){
      digitalWrite(LATCH, LOW);
      shiftOut(DATA, CLK, MSBFIRST, ~digitTwo[i]); // digitTwo
      shiftOut(DATA, CLK, MSBFIRST, ~digitOne[j]); // digitOne
      digitalWrite(LATCH, HIGH);
      delay(500);
    }
  }
}


That's all for shift registers!