Driving 7-Segment Displays with Arduino and ICs

Using 7 Segment Displays with and without Arduino

Some time ago, I was asked to make a video about a 7 segment Arduino clock, and I thought it sounded like a cool project. Now, everybody knows what an Arduino is, but those 7 segment displays are kinda old school and not often used in modern consumer electronics.

Different Types of 7 Segment Displays

There are different species of this display. There is a really simple one with only one digit in a case, and the more common two digits in one case. And whatever kind of display you get, always check the datasheet to find the pinout.

Understanding the Datasheet

In my case, I have a LTS546AG. What do we learn from the datasheet? First of all, we see that we are basically working with 8 individual LEDs, 7 for the bars and one for the decimal point. These LEDs are connected in a common anode configuration.

Controlling the Bars and Dot

We check the datasheet and see that the bars are labeled from A to G and the dot is DP. We scroll down a bit, and there it is. Now we know which pin is which bar, and we can use this display to our heart's desire.

Displaying Numbers without an Arduino

The easy solution is a BCD to 7 segment display driver. I'm using a SN74LS247, which has an active low level, which means it is capable of controlling all individual cathodes of our display.

Using a Binary Counter

We can use a 4-bit binary counter, the SN74290. Why this counter? Well, it has a BCD count sequence, so these two are pretty easy to combine.

Building a Homemade Range Meter

Now whenever we connect clock A to ground, the counter goes 1 up, and we see the next number. You can for example hook it up to a button and display the count on the 7 segment display.

Using an I2C Driver

For more advanced projects, we can use an I2C driver. The SAA1064 is a popular choice, and it supports up to 16 digits.

Building the Circuit

Here is my schematic. We connect pin 1 directly to ground to set the I2C address to 0x70. I use a 2.2 nanofrads capacitor on pin 2 to set the speed for the multiplexing.

Writing the Code

We need code, and code for I2C is a bit more advanced. So let's use a cool SAA1064 library.

When the circuit is done, we can upload the example code, and all digits do the right thing. Now I can display all kinds of things pretty easily on my display without using too much processing power of the Arduino.



7 Segment Display
A 7-segment display is an electronic device that displays decimal numbers using seven segments of LEDs (Light Emitting Diodes), LCDs (Liquid Crystal Displays) or other light sources. The segments are arranged in a specific pattern to form the digits from 0 to 9.
Each segment is typically designated by a letter (A, B, C, D, E, F and G), with A being the top horizontal segment, B and C being the right and left vertical segments respectively, and so on. By illuminating specific combinations of these segments, the display can show digits, letters, and even some special characters.
The concept of using a segmented display to represent numbers dates back to the early days of electronic displays, with one of the earliest forms being the Nixie tube, which used glow discharge to illuminate individual wire mesh numerals. However, these were expensive and prone to burnout.
The advent of LED technology in the late 1960s revolutionized display technology by offering a more efficient, longer-lasting alternative to traditional incandescent displays. LEDs could be grouped into seven segments to form numerical digits, thus giving birth to the modern 7-segment display.
Today, 7-segment displays are ubiquitous in digital watches, calculators, and electronic counters of all sorts. They remain a cost-effective way to display numeric information in a wide range of applications, from simple clocks and kitchen timers to more sophisticated medical devices and industrial control panels.


Driving 7-Segment Displays with Arduino and ICs

Seven-segment displays are a common way to display numerical information in digital circuits. They consist of seven LED segments that can be individually lit up to form digits from 0 to 9. In this article, we will explore how to drive 7-segment displays using Arduino and ICs.

Hardware Requirements

  • Arduino Board (e.g. Arduino Uno)
  • 7-Segment Display Module (Common Anode or Common Cathode)
  • ICs (Integrated Circuits) such as ULN2003, 74HC595, or CD4026
  • Jumper Wires

Software Requirements

  • Arduino IDE (Version 1.8.x or later)

Understanding the 7-Segment Display

A 7-segment display consists of seven LED segments, labeled a to g. Each segment can be individually lit up to form digits from 0 to 9.

7-Segment Display

Using ICs to Drive the 7-Segment Display

ICs such as ULN2003, 74HC595, or CD4026 can be used to drive the 7-segment display. These ICs provide a convenient way to control multiple LEDs with fewer pins.

ULN2003

The ULN2003 is an 8-channel Darlington transistor array that can be used to drive the 7-segment display. Each channel can sink up to 500mA, making it suitable for high-current applications.

ULN2003 Pinout

74HC595

The 74HC595 is an 8-bit serial-in/parallel-out shift register that can be used to drive the 7-segment display. It provides a convenient way to control multiple LEDs with fewer pins.

74HC595 Pinout

CD4026

The CD4026 is a BCD-to-7-segment decoder that can be used to drive the 7-segment display. It provides a convenient way to control multiple LEDs with fewer pins.

CD4026 Pinout

Arduino Code

const int digitPins[] = {2, 3, 4, 5};
const int segmentPins[] = {6, 7, 8, 9, 10, 11, 12};

void setup() {
  for (int i = 0; i < 4; i++) {
    pinMode(digitPins[i], OUTPUT);
  }
  for (int i = 0; i < 7; i++) {
    pinMode(segmentPins[i], OUTPUT);
  }
}

void loop() {
  // Display the digit 5
  displayDigit(5);
  delay(1000);
  
  // Display the digit 3
  displayDigit(3);
  delay(1000);
}

void displayDigit(int digit) {
  for (int i = 0; i < 4; i++) {
    digitalWrite(digitPins[i], LOW);
  }
  switch (digit) {
    case 0:
      // Display the digit 0
      digitalWrite(segmentPins[0], HIGH); // a
      digitalWrite(segmentPins[1], HIGH); // b
      digitalWrite(segmentPins[2], HIGH); // c
      digitalWrite(segmentPins[3], HIGH); // d
      digitalWrite(segmentPins[4], HIGH); // e
      digitalWrite(segmentPins[5], HIGH); // f
      break;
    case 1:
      // Display the digit 1
      digitalWrite(segmentPins[2], HIGH); // c
      digitalWrite(segmentPins[5], HIGH); // f
      break;
    case 2:
      // Display the digit 2
      digitalWrite(segmentPins[0], HIGH); // a
      digitalWrite(segmentPins[2], HIGH); // c
      digitalWrite(segmentPins[3], HIGH); // d
      digitalWrite(segmentPins[4], HIGH); // e
      digitalWrite(segmentPins[6], HIGH); // g
      break;
    case 3:
      // Display the digit 3
      digitalWrite(segmentPins[0], HIGH); // a
      digitalWrite(segmentPins[2], HIGH); // c
      digitalWrite(segmentPins[4], HIGH); // e
      digitalWrite(segmentPins[5], HIGH); // f
      digitalWrite(segmentPins[6], HIGH); // g
      break;
    case 4:
      // Display the digit 4
      digitalWrite(segmentPins[1], HIGH); // b
      digitalWrite(segmentPins[2], HIGH); // c
      digitalWrite(segmentPins[5], HIGH); // f
      digitalWrite(segmentPins[6], HIGH); // g
      break;
    case 5:
      // Display the digit 5
      digitalWrite(segmentPins[0], HIGH); // a
      digitalWrite(segmentPins[2], HIGH); // c
      digitalWrite(segmentPins[4], HIGH); // e
      digitalWrite(segmentPins[6], HIGH); // g
      break;
    case 6:
      // Display the digit 6
      digitalWrite(segmentPins[0], HIGH); // a
      digitalWrite(segmentPins[1], HIGH); // b
      digitalWrite(segmentPins[3], HIGH); // d
      digitalWrite(segmentPins[4], HIGH); // e
      digitalWrite(segmentPins[5], HIGH); // f
      break;
    case 7:
      // Display the digit 7
      digitalWrite(segmentPins[0], HIGH); // a
      digitalWrite(segmentPins[2], HIGH); // c
      digitalWrite(segmentPins[5], HIGH); // f
      break;
    case 8:
      // Display the digit 8
      digitalWrite(segmentPins[0], HIGH); // a
      digitalWrite(segmentPins[1], HIGH); // b
      digitalWrite(segmentPins[2], HIGH); // c
      digitalWrite(segmentPins[3], HIGH); // d
      digitalWrite(segmentPins[4], HIGH); // e
      digitalWrite(segmentPins[5], HIGH); // f
      break;
    case 9:
      // Display the digit 9
      digitalWrite(segmentPins[0], HIGH); // a
      digitalWrite(segmentPins[1], HIGH); // b
      digitalWrite(segmentPins[2], HIGH); // c
      digitalWrite(segmentPins[4], HIGH); // e
      digitalWrite(segmentPins[5], HIGH); // f
      break;
  }
}


Q1: What is a 7-segment display? A 7-segment display is an electronic display device that uses seven segments of LEDs or LCDs to display numerical digits.
Q2: How can I connect a 7-segment display to Arduino? You can connect a 7-segment display to Arduino using a common cathode (CC) or common anode (CA) configuration, and then use the Arduino's digital output pins to control each segment.
Q3: What is the purpose of an IC (Integrated Circuit) in driving a 7-segment display? An IC such as the 74HC595 or TPIC6B595 can be used to drive a 7-segment display, providing additional current and voltage capabilities, as well as allowing for serial communication with the Arduino.
Q4: What is the difference between a common cathode (CC) and common anode (CA) 7-segment display? A CC display has all the segment cathodes connected together, while a CA display has all the segment anodes connected together. This affects how the display is driven by the Arduino or IC.
Q5: How do I control multiple 7-segment displays with Arduino and ICs? You can use a technique called "multiplexing" to control multiple displays, where each display is turned on for a short period of time in sequence, creating the illusion that all displays are on simultaneously.
Q6: What is the advantage of using an IC such as the MAX7219 or MAX7221 to drive a 7-segment display? These ICs provide built-in support for driving 7-segment displays, including automatic digit multiplexing and segment decoding, making it easier to control the display with Arduino.
Q7: Can I use a shift register IC such as the 74HC595 to drive a 7-segment display? Yes, you can use a shift register IC to drive a 7-segment display, but it requires additional logic and software control to generate the necessary segment signals.
Q8: How do I calculate the current requirements for driving a 7-segment display with Arduino and ICs? You need to consider the total current required by all segments, including any additional components such as resistors or transistors, and ensure that the Arduino and IC can supply sufficient current.
Q9: What is the purpose of a resistor in series with each segment of a 7-segment display? The resistor limits the current flowing through each segment, preventing damage to the display and helping to ensure consistent brightness across all segments.
Q10: Can I drive a 7-segment display directly from Arduino's digital output pins without an IC? Yes, but it may require using external transistors or resistors to boost the current and voltage capabilities of the Arduino's output pins, and may be limited by the number of available pins.




Pioneer/Company Description
1. Arduino Popularized the use of microcontrollers in DIY electronics projects, including driving 7-segment displays.
2. Intel Developed the first microprocessor (Intel 4004) that could be used to drive 7-segment displays.
3. Texas Instruments Created the first single-chip microcomputer (TMS0100) that could drive 7-segment displays.
4. STMicroelectronics Developed a range of ICs for driving 7-segment displays, including the popular STP16CPC26.
5. NXP Semiconductors Offers a range of ICs for driving 7-segment displays, including the PCA9632 and PCA9685.
6. Maxim Integrated Developed a range of ICs for driving 7-segment displays, including the MAX6950 and MAX6960.
7. ON Semiconductor Offers a range of ICs for driving 7-segment displays, including the CAT4016 and CAT9532.
8. Microchip Technology Developed a range of microcontrollers that can be used to drive 7-segment displays, including the PIC16F877A.
9. SparkFun Electronics Popularized the use of Arduino and other microcontrollers in DIY electronics projects, including driving 7-segment displays.
10. Digi-Key Electronics Provides a wide range of ICs and other components for driving 7-segment displays, making it easier for hobbyists and professionals to source parts.




Component Description Pinout Arduino Connection
7-Segment Display (Common Cathode) A single digit display with 7 segments and a decimal point
  • a - Segment A
  • b - Segment B
  • c - Segment C
  • d - Segment D
  • e - Segment E
  • f - Segment F
  • g - Segment G
  • dp - Decimal Point
  • a - Arduino Digital Pin 2-9
  • b - Arduino Digital Pin 3-10
  • c - Arduino Digital Pin 4-11
  • d - Arduino Digital Pin 5-12
  • e - Arduino Digital Pin 6-13
  • f - Arduino Digital Pin 7-14
  • g - Arduino Digital Pin 8-15
  • dp - Not connected or Arduino Digital Pin 9-16 (optional)
74HC595 Shift Register IC An 8-bit serial-in/parallel-out shift register with output latches
  • Vcc - Positive Supply Voltage (5V)
  • GND - Ground
  • SHCP - Shift Register Clock Pulse (Arduino Digital Pin)
  • STCP - Storage Register Clock Pulse (Arduino Digital Pin)
  • DS - Serial Data Input (Arduino Digital Pin)
  • Q0-Q7 - Parallel Output Bits
  • Vcc - Arduino 5V Pin
  • GND - Arduino GND Pin
  • SHCP - Arduino Digital Pin (e.g. Pin 4)
  • STCP - Arduino Digital Pin (e.g. Pin 5)
  • DS - Arduino Digital Pin (e.g. Pin 6)
ULN2003A Darlington Transistor Array IC A high-voltage, high-current 7-channel Darlington transistor array
  • Vcc - Positive Supply Voltage (5V)
  • GND - Ground
  • IN1-IN7 - Input Bits
  • OUT1-OUT7 - Output Bits
  • Vcc - Arduino 5V Pin
  • GND - Arduino GND Pin
  • IN1-IN7 - 74HC595 Q0-Q7 Output Bits
Connection Diagram
        +-----------+       +-----------+
        |           |       |           |
        |  Arduino  |       | 74HC595  |
        |           |       |           |
        +-----------+       +-----------+
             |                       |
             |  (digital pins)    (serial data)
             |                       |
             v                       v
        +-----------+       +-----------+
        |           |       |           |
        | ULN2003A |       | 7-Segment  |
        |           |       | Display   |
        +-----------+       +-----------+
      
Example Arduino Code
// Define shift register pins
const int shcp = 4;  // SHCP pin
const int stcp = 5;  // STCP pin
const int ds = 6;   // DS pin

void setup() {
  pinMode(shcp, OUTPUT);
  pinMode(stcp, OUTPUT);
  pinMode(ds, OUTPUT);

  // Initialize shift register
  digitalWrite(shcp, LOW);
  digitalWrite(stcp, LOW);
}

void loop() {
  // Example: Display '1' on the first digit
  byte data = B00000110; // Binary representation of '1'

  // Shift out data to the shift register
  shiftOut(ds, shcp, MSBFIRST, data);

  // Latch data into the output registers
  digitalWrite(stcp, HIGH);
  delayMicroseconds(10); // Ensure sufficient pulse width
  digitalWrite(stcp, LOW);

  delay(1000); // Wait for 1 second
}