Feedback!

7 Segment LED + Shift Register

Views: 37764 Difficulty: 1 Status: Complete
Shift_register_7segment_daisied2

Display numbers in big bright red LEDs use only 3 micro-controller pins and the 74HC595 shift register

Easily display numbers on a 7-Segment LED Display with this simple breakout board. This PCB uses all easy-to-solder through-hole components. You can get one at our store. We use a 74HC595 shift register to multiplex the Arduino's outputs. Using three control lines: data, clock, and latch, we can control 8 different output pins on the 74HC595 chip. Bonus feature: we can daisy-chain these LED modules and get tons of outputs for those same 3 pins on the atmega.

Lucky Number 7

Shift_75
Sevens all the way!

Video of Arduino Controlling the 7 Segment LED Display

Watch the little breakout board in action!

Soldering Video

Watch the 74HC595 shift register and 7-segment LED number display board get assembled and soldered. The actual process takes about 20 minutes but here you can see it happen in one minute.

Step-by-Step Instructions

Step 0 Get the Kit

First get the kit from our store. You can check the parts list below for exact product numbers, but basically what you get is the PCB, a big 7 segment LED display, a 74HC595 shift register, eight 300 ohm resistors, two capacitors, and male and female headers (not shown in the image).

Step 1 schematic

Positioning is important for board wiring to function correctly. Luckily the manufacturers give us a little U-Shaped depression to show which way is up. See those little squiggly lines on the schematic? Those symbolize the resisters we need for each LED segment.

Step 2 Insert the Shift Register in the Correct Orientation

Put the 74HC595 shift register into the board as shown in the image. Pin number 1 is the first pin to the left of the U-shaped depression at the top of the chip. Make sure that the U-shape lines up with the silkscreen numer 1 on the PCB.

Step 3 Grab a Resistor

Grab a resistor from the set of ten and separate it from the rest.
Why do you need 8 resistors for a 7 segment LED?


...The decimal point!

Step 4 Pinch the Resistor Legs with Pliers

This step is optional, put you may have an easier time slipping the resistor into the board if you first pinch it with pliers.

Step 5 Insert the Resistor

Insert the resistor into the board. Resistors are symmetric so the orientation doesn't matter.

Step 6 Insert All the Resistors

Now wash, rinse, and repeat the process with all of the resistors. You can fold the resistors legs out so that they don't fall out of the PCB.

Step 7 Insert the Headers and the Capacitors

Insert the male and female headers and the capacitors. By convention, we put the male headers on the output side of board, and the female headers on the input side of the board. You can do it either way as long as you are consistent. Now solder everybody down.

Step 8 Insert The 7 Segment LED in the Correct Orientation

Insert the 7 segment LED in the orientation show in the image. Notice one corner of the LED display is bevelled off, line this corner up with the bottm right corner on the PCB where it says "CORNER" and there is an arrow pointing at it.

Step 9 Hook it Up to an Arduino

Now you are all set! Hook up your LED board to an Arduino and upload the code we supply below. We connect the data pin (the pin closest to 5V) to the digital pin 2 on the Arduino, the latch pin is connected to the Arduino digital pin 3, and the clock pin is connected to digital pin 4.

Arduino Code to show Numbers on 7 Segment LED Display

One annoying things about getting new 7 Segment LED modules is figuring out which pin goes to which LED-segment. So, the first thing we do in the code is set up the byte array dec_digits:
byte dec_digits[] = {0b11000000,0b11111001,0b10100100,0b10110000,0b10011001,0b10010010,0b10000011,0b11111000,0b10000000,0b10011000 };
Here a zero corresponds to an LED being ON and a 1 corresponds to an LED being OFF. Maybe a little counter-intuitive, but it is this way because the seven segment Display we are using is a common anode device so you toggle the different LEDs on and off by connecting ground to the LED pins. This array contains the LED settings to display the ten decimal digits (thanks arabic numerals! Roman numerals are lame...) So, now that we know which bytes we want to send to the shift registers the code just boils down to looping over the byte array and sending out a new byte every so often. This is the code to do that:
  for (int numberToDisplay = 0; numberToDisplay < 10; numberToDisplay++) {
    // take the latchPin low so 
    // the LEDs don't change while you're sending in bits:
    digitalWrite(latchPin, LOW);
    // shift out the bits:
    shiftOut(dataPin, clockPin, MSBFIRST, dec_digits[numberToDisplay]); 
    //take the latch pin high so the LEDs will light up:
    digitalWrite(latchPin, HIGH);
    // pause before next value:
    delay(300);
  }
Note that in the line:
    shiftOut(dataPin, clockPin, MSBFIRST, dec_digits[numberToDisplay]); 
We grab the LED segment settings from the dec_digits array. We cannot just write the number out to the shift register. For example, if you shift out an 8 you are sending the shift register the byte 00001000, this means light up all of the segment of the 7-Segment LEDs except the third one. This would look like A not an 8. If you want to see an 8 you have to write out the byte: 128 (decimal) = 0x80(hex) = 10000000 (binary), which means every LED segment on except the decimal point.
/* LucidTronix 7 Segment LED
 * and 74HC595 shift register
 * Tutorial at: 
 * http://www.lucidtronix.com/tutorials/41
 */

int dataPin = 2;
int latchPin = 3;
int clockPin = 4;

byte dec_digits[] = {0b11000000,0b11111001,0b10100100,0b10110000,0b10011001,0b10010010,0b10000011,0b11111000,0b10000000,0b10011000 };

void setup() {
  //set pins to output so you can control the shift register
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() {
  for (int numberToDisplay = 0; numberToDisplay < 10; numberToDisplay++) {
    // take the latchPin low so 
    // the LEDs don't change while you're sending in bits:
    digitalWrite(latchPin, LOW);
    // shift out the bits:
    shiftOut(dataPin, clockPin, MSBFIRST, dec_digits[numberToDisplay]); 
    //take the latch pin high so the LEDs will light up:
    digitalWrite(latchPin, HIGH);
    // pause before next value:
    delay(300);
  }
}

Parts

Title Description # Cost Link Picture
PCB 7 Segment LED Display and 74HC595 Shift Register 74HC595 Shift Register breakout board for 7 Segment LED numeric display 1 $4.0 Link 7segment_pcb_naked
LED Display 7 Segment numeric LED Display RED Value: 7 Red LEDs 1 $0.95 Link 7segmentredled-01-l
Shift Register IC 8-BIT SHIFT REGISTER 16-DIP Serial to Parallel Tri-State 2 V ~ 6 V Value: 74HC 1 $0.63 Link Screen_shot_2012-12-28_at_7.40.34_pm
Capacitor Ceramic Capacitors CAP CER 0.1UF 50V 20% RADIAL Value: 0.1µF 2 $0.24 Link Screen_shot_2012-12-28_at_7.39.17_pm
Resistor RES 300 OHM 1/4W 5% CARBON FILM Value: 300 8 $0.08 Link Screen_shot_2012-12-28_at_7.28.01_pm

    Comments:

    Missing_profile
    Feather
    If you are interested in electronic design, share with you an free, powerful and easy-to-use EDA tool aiming to bring electronics hobbyists an Easier EDA Experience and integrates powerful schematic capture, mixed-mode circuit simulation and PCB layout. The this free tool called EasyEDA, Try and learn more about it by https://easyeda.com/
    Thu, Jun 16 2016 11:14PM
Permalink: http://lucidtronix.com/tutorials/41
The 74HC595 shift register controls a 10 LED Bar Graph....
Two LED matrices give 70 LEDs to light up a necklace with messages....
Display 4 digits using only 3 MCU wires with the 4 x 7 Segment LED and shift register breakout board....
Build your own clock with the MCP79410 chip and 4 7-Segment LED modules....
Connect shift registers together to get more output and input pins from your microcontroller....
A QWERTY keyboard you build yourself....
Standalone programmable Heart-Shaped LED display....
Make an interactive light show using a proximity sensor, and a bunsh of shift registers and LEDs....