ad space

Seven Segment Display with Arduino and Shift Register

Seven segment modules are useful in displaying numbers. You can find seven segments display module used in digital alarm clocks, speedometers and other numeric displays. Here we will show how to use Seven Segment Display module with Arduino. We will utilize a shift register 74HC595 to output digits from 0 to 9 and from A to F. 

Seven Segment Display on Breadboard with Arduino & Shift Register

The following picture shows  7 segment wiring on breadboard along with Arduino and Shift Register(74HC595). We have provided a separate +5V power supply for the shift register and the seven segment display module. The ground of the Arduino is connected to the common ground of the breadboard. As shown in the figure we have also provided a 0.1uF electrolytic capacitor across the +5V and ground terminal as suggested by the shift register datasheet. 

The seven segment, shift register along with circuit diagram are explained below.

Circuit Diagram of Interfacing Arduino with Seven Segment Display and Shift Register

The seven segment display circuit with Arduino and Shift Register 74HC595 is as shown below.


The Q0 to Q7 pins of the shift register is connected to the a, b, c, d, e, f, g and DP pins of the seven segment display. As suggested in the shift register datasheet we have used 560Ohm resistors between the Q0 to Q7 pins and the a, b, c, d, e, f, g and DP pins of the seven segment display. The seven segment display we used here has two common cathode pins and they should be grounded.

Seven Segment Display Module

seven segment display
A seven segment display consist of eight LEDs internal to the module. They are available in different colors. They come in two different types, common anode and common cathode. In common anode, 7 segment display, the anode of all the eight LED inside the module are connected together and in common cathode the cathode of the eight LEDs are connected together. They are designed this way in order to reduce number of pins used for display. In this tutorial we will be using common cathode seven segment module.

The LEDs inside the display module is labeled from A to G and DP(for decimal point) as shown in the figure. For each LED there is anode pins to which external signal is connected to turn on the corresponding LED. All the LED cathode are connected to common ground. By applying different combination of High inputs to the display pins we can display a digit. This different combination of signal required for digits from 0 to 9 and from A to F is shown in the Truth Table for Seven Segment Display below.


74HC595 Shift Register

shift register 74HC595
The 74HC595 shift register is 16 pin DIP package Integrated Circuit(IC). It is an 8-bit Serial-In, Parallel-Out Shift Registers. It can be operated from 2V to 6 V. It has low power consumption with maximum of 80-μA. 

As shown in the 74HC595 pin out diagram on the right, the QA to QH pins are to be connected to the seven segment display a through g and DP. The SER(pin 14) which is the Data input pin(DS in the schematic above) is connected to the Arduino pin 9. The ~OE pin is active low pin which is connected to the +5V source. The RCLK pin 12, in the schematic labelled ST_CP is latch pin which is connected to Arduino pin 8. The SRCLK pin 11, in the schematic above labelled SH_CP, is the clock pin which is connected to pin 10 of the Arduino. The ~SRCLR pin 10 is connected to +5V source. The QH' pin 9 is not used. The Vcc(pin 16) and GND(pin 8) are connected to the +5V power supply and ground respectively.

Video demonstration of Seven Segment Display with Arduino and Shift Register

Below is a short video demonstration of how Seven Segment Display works with Arduino and using Shift Register. 


Seven Segment Program Code using Arduino and Shift Register

The programming code for Seven Segment Display using Arduino and Shift Register is shown below. In this code we have used 


// Single-Digit Seven Segment Display
// by ee-diary(https://ee-diary.blogspot.com)


#define latch 8 // connect to pin 12 on the 74HC595
#define data 9 // connect to pin 14 on the 74HC595
#define clk 10 // connect to pin 11 on the 74HC595

// set up the array with the segments for 0 to 9, A to F
int digits[] = {252, 96, 218, 242, 102, 182, 190, 224, 254, 246, 238, 62, 156, 122, 158, 142};

void setup(){
  pinMode(data, OUTPUT);
  pinMode(latch, OUTPUT);
  pinMode(clk, OUTPUT);
}

void loop(){
    int i;
    for ( i = 0 ; i < 16 ; i++ ) // display digits 0-9, A-F
    {
    digitalWrite(latch, LOW);
    shiftOut(data, clk, LSBFIRST, digits[i]);
    digitalWrite(latch, HIGH);
    delay(500);   //500ms delay
    }

    for ( i = 0 ; i < 16 ; i++ ) // display digits 0-9, A-F with DP
    {
    digitalWrite(latch, LOW);
    shiftOut(data, clk, LSBFIRST, digits[i]+1); // +1 is to turn on the DP bit
    digitalWrite(latch, HIGH);
    delay(500);
    }
}


Post a Comment

Previous Post Next Post