7-Segment LED Displays Guide with Arduino Interfacing

Introduction

  • 7-segment LED displays are formed by LED segments. It is basically used to display numerical values from 0 to 9. One more segment is also present there which is used as decimal point.
7-Segment Display
7-Segment Display

 

  • In 7-segment displays there are two types, common anode and common cathode.

1.  Common Anode (CA)

In common anode display, all anode pins are connected together to VCC and LEDs are controlled via cathode terminals. It means to turn ON LED (segment), we have to make that cathode pin logic LOW or Ground.

Common Anode Configuration

2.  Common Cathode (CC)

In common cathode display, all cathode pins are connected together and led are controlled via anode terminal. It means to turn ON LED (segment), we have to apply proper voltage to the anode pin.

Common Cathode Configuration

Following demonstration will show the working of above configuration,

Seven segment Connection configuration

 

7 Segment Display Pinout

  • 7-segment display has total 10 pins.
  • The common pin (com) is connected either in common anode or common cathode configuration.
7 Segment display
Pin Diagram of 7-Segment Display

 

Specification of 7-Segment Display

  • Display Type: 7-segment LED displays are either common anode or common cathode.
  • LED Colors: Available in different colors such as red, green, yellow, etc.
  • Dimensions: The common sizes ranging from 0.3 inches to 2.3 inches.
  • Viewing Angle: The viewing angle of the 7-segment LED display determines the range from which the display can be easily viewed.
  • Forward Voltage: The forward voltage is the voltage required to drive the LED, and it varies based on the LED color.
  • Forward Current: The forward current is the amount of current required to drive the LED to its maximum brightness.
  • Power Consumption: The power consumption of a 7-segment LED display is an important specification for battery-operated applications.

 

Alternate options for 7-Segment Display

  • Dot Matrix Display
  • Alpha-Numeric Display
  • OLED Display
  • LCD Display
  • TFT Display

 

 

 

Resistor Connections

  • We have to connect resistor to each segment individually.
  • Avoid LED's connection in parallel with one resistor, because each LED segment doesn't have exact same forward voltage drop.
  • If we connect one resistor to the parallel LEDs then some LEDs will glow and some will not. Because forward voltage drops are different for each LEDs, LEDs which are having lowest voltage drop across them will only glow. And though if we connect LEDs with ideally equal voltage drop, current will get divided and brightness will get affected each time while switching the LEDs.
Incorrect Way Of Connecting Resistor

 

Note: Please refer required voltage, absolute max current and forward voltage drop of the segment from the datasheet.

 

Calculation of Resistor Value

Resistor Value Calculation

R = (VS - VLED) / ILED

Where,

R = Resistor in series with LED.

Vs = Source voltage.

VLED = LED forward voltage drop.

ILED = LED forward current.

Example

Normally voltage is 5volt and abs. max. current is about 20mA to 25mA. Let’s take current ILED = 10mA (considering safer margin) as 10mA is sufficient to glow the segment.

VS = 5V and VLED = 1.7V then resistor value is.

R = (5 – 1.7)/ 0.010 = 300 Ohm

 

Display Driver

Why to use driver

  • Display driver requires only 4 pins of microcontroller to drive the 7-segment display.
  • We do not need to convert decimal numbers into 7 segment display format (from 0-9).We just need to provide BCD (Binary Coded Decimal) numbers and it will take care rest of seven segment conversion.
  • No external Resistor is required.
  • It makes easy to interface with microcontroller.

7-Segment Display Driver IC SN7446AN

  • SN7446AN is a 16 pin IC, used to drive common anode type 7-segment LED display.
  • This driver IC accepts 4 line of BCD (Binary Coded Decimal) input data, and drives 7-segments display directly.

SN7446AN Pinout

SN7446N Pin Diagram
SN7446AN Pin Diagram

 

Pin Description

 

Numerical Designations Resultant Display

Possible Displays On 7-Segment Display

 

7-Segment Display interfacing with Arduino

Interfacing 7-Segment Display with Arduino UNO
7-Segment Display interfacing with Arduino

 

7-Segment Display code for Arduino

int disp_pin[7];  /* array for a-g pins of 7-Segment display */

void define_segment_pins(int a, int b, int c, int d, int e, int f, int g)    /* Assigns 7-segment display pins to board */
{ 
  disp_pin[0] = a;
  disp_pin[1] = b;
  disp_pin[2] = c;
  disp_pin[3] = d;
  disp_pin[4] = e;
  disp_pin[5] = f;
  disp_pin[6] = g;
}

void display_number(int num)   /* Function for displaying number (0-9) */
{
  switch(num)
  {
    case 0:
   digitalWrite(disp_pin[0], LOW);     /* Drive disp_pin[0] to LOW */
   digitalWrite(disp_pin[1], LOW);     /* Driving LOW turns on LED segment for common anode display */
   digitalWrite(disp_pin[2], LOW);
   digitalWrite(disp_pin[3], LOW);
   digitalWrite(disp_pin[4], LOW);
   digitalWrite(disp_pin[5], LOW);
   digitalWrite(disp_pin[6], HIGH); 
   break;
    case 1:
   digitalWrite(disp_pin[0], HIGH);    /* Drive disp_pin[7] to HIGH */
   digitalWrite(disp_pin[1], LOW);
   digitalWrite(disp_pin[2], LOW);
   digitalWrite(disp_pin[3], HIGH);    /* Driving HIGH turns off LED segment for common anode display */
    digitalWrite(disp_pin[4], HIGH);
   digitalWrite(disp_pin[5], HIGH);
   digitalWrite(disp_pin[6], HIGH);
    break;
    case 2:
   digitalWrite(disp_pin[0], LOW);
   digitalWrite(disp_pin[1], LOW);
   digitalWrite(disp_pin[2], HIGH);
    digitalWrite(disp_pin[3], LOW);
   digitalWrite(disp_pin[4], LOW);
   digitalWrite(disp_pin[5], HIGH);
   digitalWrite(disp_pin[6], LOW);
    break;
    case 3:
   digitalWrite(disp_pin[0], LOW);
   digitalWrite(disp_pin[1], LOW);
   digitalWrite(disp_pin[2], LOW);
   digitalWrite(disp_pin[3], LOW);
   digitalWrite(disp_pin[4], HIGH);
   digitalWrite(disp_pin[5], HIGH);
   digitalWrite(disp_pin[6], LOW);
    break;
    case 4:
   digitalWrite(disp_pin[0], HIGH);
   digitalWrite(disp_pin[1], LOW);
   digitalWrite(disp_pin[2], LOW);
   digitalWrite(disp_pin[3], HIGH);
   digitalWrite(disp_pin[4], HIGH);
   digitalWrite(disp_pin[5], LOW);
   digitalWrite(disp_pin[6], LOW);
    break;
    case 5:
   digitalWrite(disp_pin[0], LOW);
   digitalWrite(disp_pin[1], HIGH);
   digitalWrite(disp_pin[2], LOW);
   digitalWrite(disp_pin[3], LOW);
   digitalWrite(disp_pin[4], HIGH);
   digitalWrite(disp_pin[5], LOW);
   digitalWrite(disp_pin[6], LOW);
    break;
    case 6:
   digitalWrite(disp_pin[0], LOW);
   digitalWrite(disp_pin[1], HIGH);
   digitalWrite(disp_pin[2], LOW);
   digitalWrite(disp_pin[3], LOW);
   digitalWrite(disp_pin[4], LOW);
   digitalWrite(disp_pin[5], LOW);
   digitalWrite(disp_pin[6], LOW);
    break;
    case 7:
   digitalWrite(disp_pin[0], LOW);
   digitalWrite(disp_pin[1], LOW);
   digitalWrite(disp_pin[2], LOW);
   digitalWrite(disp_pin[3], HIGH);
   digitalWrite(disp_pin[4], HIGH);
   digitalWrite(disp_pin[5], HIGH);
   digitalWrite(disp_pin[6], HIGH);
    break;
    case 8:
   digitalWrite(disp_pin[0], LOW);
   digitalWrite(disp_pin[1], LOW);
   digitalWrite(disp_pin[2], LOW);
   digitalWrite(disp_pin[3], LOW);
   digitalWrite(disp_pin[4], LOW);
   digitalWrite(disp_pin[5], LOW);
   digitalWrite(disp_pin[6], LOW);
    break;
    case 9:
   digitalWrite(disp_pin[0], LOW);
   digitalWrite(disp_pin[1], LOW);
   digitalWrite(disp_pin[2], LOW);
   digitalWrite(disp_pin[3], LOW);
   digitalWrite(disp_pin[4], HIGH);
   digitalWrite(disp_pin[5], LOW);
   digitalWrite(disp_pin[6], LOW);
    break;
    default:
   digitalWrite(disp_pin[0], HIGH);
   digitalWrite(disp_pin[1], LOW);
   digitalWrite(disp_pin[2], LOW);
   digitalWrite(disp_pin[3], LOW);
   digitalWrite(disp_pin[4], LOW);
   digitalWrite(disp_pin[5], HIGH);
   digitalWrite(disp_pin[6], LOW);
    break;
  }
}

voidsetup(){
  pinMode(6, OUTPUT);  
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
 define_segment_pins(12,11,10,9,8,7,6); /* a-g segment pins to Arduino */
}

void loop(){
  int i;
  for(i = 9; i>=0; i--)
  {
   display_number(i);
    delay(1000);
  }
  for(i = 0; i<=9; i++)
  {
   display_number(i);
    delay(1000);
  }
}

 

The above code displays the numbers on 7 segment display with a delay of one second.

To know more about 7-segment display using Arduino refer to this link

 

Examples of 7-Segment LED Display interfacing

  1. 7-Segment Display Interfacing with ATmega16
  2. 7-Segment Display Interfacing with Arduino
  3. 7-Segment Display Interfacing with TI Launchpad

Components Used

Seven 7 Segment Display
Seven 7 Segment Display
1
SN7447AN BCD-To-Seven-Segment Driver
SN7447AN BCD-To-Seven-Segment Decoder/Driver
1
Ad