# How to Connect a 7-Segment Display to Arduino: Wiring and Code

Learn how to connect a 7-segment display to Arduino, identify common-anode and common-cathode displays, select resistors, and display numbers with code.

Written by [Jharwin Barrozo](https://www.flux.ai/jharwinbarrozo)

Published Oct 2026 - 9 min read

![How to Connect a 7-Segment Display to Arduino: Wiring and Code](https://www.flux.ai/p/assets/blogs/7-segment-display-arduino/main.webp)

A 7-segment display is one of the simplest ways to add a numeric output to an Arduino project. It can show sensor readings, counters, timers, status codes, and other values without requiring a full LCD or graphical display.

Although the display looks like one component, it contains seven main LED segments and often an eighth LED segment for the decimal point. Each segment must be driven correctly and normally requires its own current-limiting resistor.

This guide explains how 7-segment displays work, how to identify common-anode and common-cathode versions, and how to wire and control one from an Arduino.

## How a 7-Segment Display Works

The seven illuminated bars are identified using the letters `a` through `g`.

![Seven-segment digit layout with segments labeled a (top), b (top right), c (bottom right), d (bottom), e (bottom left), f (top left), and g (middle)](https://www.flux.ai/p/assets/blogs/7-segment-display-arduino/body-1.png)

Many displays also contain a decimal point labeled `dp`.

Each segment is an individual LED. Numbers are formed by illuminating different combinations:

| **Number** | **Active segments** |
| --- | --- |
| 0 | a, b, c, d, e, f |
| 1 | b, c |
| 2 | a, b, d, e, g |
| 3 | a, b, c, d, g |
| 4 | b, c, f, g |
| 5 | a, c, d, f, g |
| 6 | a, c, d, e, f, g |
| 7 | a, b, c |
| 8 | a, b, c, d, e, f, g |
| 9 | a, b, c, d, f, g |

How these LED segments are wired together inside the display package determines whether the device is common cathode or common anode.

## Common Cathode vs Common Anode

In a common-cathode display, the cathodes of the segment LEDs share a common pin connected to ground. The other side of each LED is brought out to a separate package pin, called a segment pin. Driving a segment pin high turns that segment on.

In a common-anode display, the LED anodes share a common connection to the positive supply. Driving a segment pin low turns that segment on.

| **Display type** | **Common connection** | **Segment ON state** |
| --- | --- | --- |
| Common cathode | Ground | HIGH |
| Common anode | Positive supply | LOW |

Do not determine the display type from package appearance alone. Look up its part number or use a multimeter’s diode-test mode.

Pin arrangements also vary. Two displays with identical dimensions can use different pinouts, so consult the manufacturer’s datasheet before wiring. Some packages also expose more than one common pin, so connect every required common pin according to the datasheet.

## Wiring a Single-Digit Display to Arduino

The following example uses a common-cathode display and seven Arduino output pins. The optional decimal point is not connected in this example.

| **Segment** | **Arduino pin** |
| --- | --- |
| a | D2 |
| b | D3 |
| c | D4 |
| d | D5 |
| e | D6 |
| f | D7 |
| g | D8 |
| **Common-cathode pin(s)** | GND |

Place one resistor in series with every segment. Do not use one resistor on the shared common connection. A shared resistor makes segment brightness depend on how many LEDs are illuminated.

Resistor values from a few hundred ohms to around 1 kΩ are common in low-current prototypes, but the correct value should be calculated based on supply voltage, LED forward voltage, desired current, and the board’s GPIO limits:

For example, for a 5 V output, a 2 V red LED, and a target current of 6 mA:

A standard 510 Ω resistor would be a reasonable starting value for this example, producing approximately 5.9 mA using the simplified calculation. Actual LED forward voltage and GPIO output voltage vary, so the calculation should be treated as a design estimate rather than an exact current value.

Current limits vary between Arduino boards. For example, the official [Arduino Uno R4 Minima pinout](https://docs.arduino.cc/5e218c7ed3622cbd09ab25357c345b84/ABX00080-full-pinout.pdf) identifies an 8 mA maximum current per pin and a 60 mA overall limit. The target current should remain below the applicable limits rather than treating a maximum rating as the normal operating point. Check the documentation for the exact Arduino model rather than assuming all Uno-branded boards have identical limits.

## Arduino Code for a 7-Segment Display

This example assumes:

-   A common-cathode display
-   Segment `a` connected to D2
-   Segments continuing sequentially through `g` on D8

```
const byte segmentPins[7] = {
  2, 3, 4, 5, 6, 7, 8
};

// Segment order: a, b, c, d, e, f, g
const byte digitPatterns[10][7] = {
  {1, 1, 1, 1, 1, 1, 0}, // 0
  {0, 1, 1, 0, 0, 0, 0}, // 1
  {1, 1, 0, 1, 1, 0, 1}, // 2
  {1, 1, 1, 1, 0, 0, 1}, // 3
  {0, 1, 1, 0, 0, 1, 1}, // 4
  {1, 0, 1, 1, 0, 1, 1}, // 5
  {1, 0, 1, 1, 1, 1, 1}, // 6
  {1, 1, 1, 0, 0, 0, 0}, // 7
  {1, 1, 1, 1, 1, 1, 1}, // 8
  {1, 1, 1, 1, 0, 1, 1}  // 9
};

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

void displayDigit(byte digit) {
  if (digit > 9) {
    return;
  }

  for (byte segment = 0; segment < 7; segment++) {
    digitalWrite(
      segmentPins[segment],
      digitPatterns[digit][segment]
    );
  }
}

void loop() {
  for (byte digit = 0; digit <= 9; digit++) {
    displayDigit(digit);
    delay(1000);
  }
}
```

For a common-anode display, invert the output state:

```
digitalWrite(
  segmentPins[segment],
  !digitPatterns[digit][segment]
);
```

Alternatively, define an `ON_STATE` constant based on the display type. Make sure the display supply voltage is also compatible with the GPIO voltage of the specific Arduino board you are using.

## Controlling Multi-Digit Displays

Controlling every segment of a four-digit display independently would require a large number of GPIO connections. Multi-digit displays therefore commonly use multiplexing, a technique in which the digits share the same segment-control lines and the microcontroller turns the digits on one at a time in rapid succession.

All corresponding segments share control lines, while each digit has a separate enable connection. The Arduino sets the segment pattern, enables one digit briefly, disables it, and moves to the next digit.

When this cycle repeats fast enough, the digits appear continuously illuminated even though only one digit is being actively driven at a given instant.

Multiplexed displays introduce several considerations:

-   The software must refresh the display continuously.
-   Peak segment current may differ from average current.
-   Digit-enable lines may need [transistors](https://www.flux.ai/p/blog/understanding-the-fundamentals-mosfet-basics-for-beginners) because a digit’s common connection can carry the combined current of several illuminated segments, which may exceed a GPIO pin’s current capability.
-   Brightness depends on duty cycle.
-   Blocking delays can cause visible flicker.
-   GPIO-current limits still apply.

For larger displays or designs that need more available GPIO pins, use a display driver or other GPIO-expansion circuitry. A display-driver IC is designed to control multiple LEDs or display digits on behalf of the microcontroller, reducing the number of GPIO pins and the amount of display-refresh work the Arduino must perform.

Common options include:

-   MAX7219
-   TM1637
-   HT16K33
-   74HC595 shift register with suitable drive circuitry

Dedicated display drivers can provide features such as multiplexing, segment-current control, and brightness adjustment, depending on the device. A 74HC595 is different: it is a serial-to-parallel shift register that can reduce the number of Arduino pins required, but it does not by itself provide regulated LED current or automatically multiplex a multi-digit display. Additional current-limiting and drive circuitry may still be required.

## Designing a 7-Segment Display PCB

A breadboard is useful for validating the display type, resistor values, and software. A custom PCB creates a more durable and compact design.

Before drawing the schematic, verify the display’s:

-   Exact package
-   Pin numbering
-   Common-anode or common-cathode configuration
-   Forward voltage
-   Recommended current
-   Decimal-point location
-   Viewing orientation

For the single-digit direct-drive circuit described above, give every segment its own resistor. Label the nets `SEG_A` through `SEG_G` and `SEG_DP` instead of relying only on unnamed connections.

For a multiplexed multi-digit display, corresponding segments are commonly connected to shared segment lines, so current-limiting components are placed according to that shared topology or the requirements of the selected display driver rather than necessarily using one resistor for every physical segment in every digit.

If the board contains multiple digits, decide whether the microcontroller can drive them directly or whether transistors or a dedicated driver are needed.

During layout:

-   Place the display based on enclosure and viewing requirements.
-   Confirm its orientation from the front of the product.
-   Keep programming and debugging connectors accessible.
-   Place current-limiting resistors in an organized group.
-   Keep the display away from tall components that obstruct visibility.
-   Verify the [footprint](https://www.flux.ai/p/blog/pcb-footprint-design-guide) against the physical display.
-   Add labels for connectors and polarity.
-   Consider light pipes, bezels, tinted covers, and viewing angle.

Flux can be used to build the Arduino interface, assign the display footprint, document each segment connection, and review the completed layout collaboratively. The PCB’s schematic and layout remain synchronized, making pinout or resistor changes easier to trace.

## Troubleshooting a 7-Segment Display

**No segments light up**

Check the common connection and confirm whether the display is common anode or common cathode.

**The wrong segments light up**

The code’s segment order does not match the physical pinout. Trace each package pin back to segments `a` through `g`.

**The display is very dim**

Check resistor values, output voltage, multiplexing duty cycle, and the driver’s current capability.

**The segments are too bright or the Arduino becomes unstable**

The LEDs may be drawing too much current. Increase the resistor values or add proper driver circuitry. **Also verify both the per-pin and total GPIO-current limits for the specific Arduino board.**

**Digits flicker**

Increase the multiplexing refresh rate and remove long blocking delays from the display loop.

## FAQs

### Does every segment need a resistor?

Each independently driven LED segment line needs current limiting unless the selected display driver provides regulated segment current. On a single-digit direct-drive display, this normally means one resistor per segment. On a multiplexed display, one resistor may serve each shared segment line across multiple digits.

### Can an Arduino drive a 7-segment display directly?

It can often drive a single small display at conservative current levels, but the exact limits depend on the Arduino model. Multi-digit or high-brightness displays commonly require a driver.

### How can I tell whether a display is common anode or common cathode?

Check its datasheet or test it carefully with a multimeter in diode mode.

### Why are some numbers displayed incorrectly?

The physical segment pinout probably differs from the array order used in the program.

### What is the easiest way to control a four-digit display?

A module or display-driver IC matched to the display, such as a compatible TM1637 or MAX7219 implementation, reduces wiring and handles multiplexing more conveniently.

## About the author

[Jharwin Barrozo](https://www.flux.ai/jharwinbarrozo)

Electronics Engineer at Flux

Jharwin is an electronics engineer mainly focused on satellites. He built his own ground station using Flux to monitor RF activities on the International Space Station. Find him on Flux [@jharwinbarrozo](https://flux.ai/jharwinbarrozo)

Let’s start building

Build your big idea together with Flux. All you need to do is describe what you want to make, or what problem you want to solve. Flux will work with you to make it a reality.

![Close-up photo of a PCB made with Flux, with an ESP32 module, buttons, and a microSD slot.](https://www.flux.ai/p/assets/blogs/miscellaneous/sidebar-cta-pcb.webp) [Try it Free](https://www.flux.ai/signup)

## More in Component & Platform Guides

[

![A 3d model of arduino uno board](https://www.flux.ai/p/assets/blogs/arduino-getting-started/main.webp)

### Arduino Uno Basics: Beginner's Guide to Getting Started

15 Min Read](https://www.flux.ai/p/blog/arduino-uno-basics-beginners-guide-to-getting-started)[

![ESP32 Board with its pinout label and diagram, each pin label and function on different colors](https://www.flux.ai/p/assets/blogs/esp32-pinout/main.webp)

### ESP32 Pinout Guide: Everything You Need to Know

11 Min Read](https://www.flux.ai/p/blog/esp32-pinout-everything-you-need-to-know)[

![A raspberry pi 3B and zero boards laid out together showing graphical GPIO pinout](https://www.flux.ai/p/assets/blogs/raspberry-pi-guide/main.webp)

### Raspberry Pi Pinouts: A Comprehensive Guide

8 Min Read](https://www.flux.ai/p/blog/raspberry-pi-pinouts-a-comprehensive-guide)[

![An arduino uno microcontroller board with its sketch code on Arduino IDE being used as background in a monitor.](https://www.flux.ai/p/assets/blogs/arduino-code-guide/main.webp)

### Arduino Code for Beginners: How to Write Your First Sketch

8 Min Read](https://www.flux.ai/p/blog/arduino-code-a-comprehensive-guide-for-beginners)[

![Meet the Arduino Nano R4: Why Is This Tiny Upgrade So Big for Makers?](https://www.flux.ai/p/assets/blogs/arduino-nano-r4/main.webp)

### Meet the Arduino Nano R4: Why Is This Tiny Upgrade So Big for Makers?

6 Min Read](https://www.flux.ai/p/blog/meet-the-arduino-nano-r4-why-is-this-tiny-upgrade-so-big-for-makers)[

![A microcontroller board with the words Arduino Pro Micro on it.](https://www.flux.ai/p/assets/blogs/arduino-pro-micro/main.webp)

### What is Arduino Pro Micro: a Comprehensive Introduction for Novices

5 Min Read](https://www.flux.ai/p/blog/what-is-arduino-pro-micro-a-comprehensive-introduction-for-novices)[

![Schematic diagram of arduino uno board with all of its passive and active components](https://www.flux.ai/p/assets/blogs/arduino-uno-schematic-diagram/main.webp)

### Arduino Uno Schematic Diagram: A Comprehensive Guide

8 Min Read](https://www.flux.ai/p/blog/arduino-uno-schematic-diagram)[

![Side by side comparison of the 3 powerful and most common Arduino microcontroller boards; Arduino Mega 2560, Arduino Uno and Arduino Micro.](https://www.flux.ai/p/assets/blogs/arduino-mega-uno-micro/main.webp)

### Arduino Mega vs. Uno vs. Micro: Key Differences

6 Min Read](https://www.flux.ai/p/blog/what-is-the-real-difference-arduino-mega-vs-micro-vs-uno)[

![Different packages or footprint of famous atmega328p microcontroller with its pinout](https://www.flux.ai/p/assets/blogs/atmega328p-still-top-choice/main.webp)

### Why Atmega328p is Still a Top Choice for Microcontroller Projects in 2023

8 Min Read](https://www.flux.ai/p/blog/why-atmega328p-is-still-a-top-choice-for-microcontroller-projects-in-2023)[

![ESP32 Chip in a dark background: A powerful microcontroller with integrated Wi-Fi and Bluetooth, driving IoT innovation with seamless connectivity.](https://www.flux.ai/p/assets/blogs/esp32-history/main.webp)

### Exploring ESP32: from History to Application

3 Min Read](https://www.flux.ai/p/blog/exploring-esp32-from-history-to-application)[

![3d rendered of an ESP8266 microcontroller board, showing its compact size with the Wi-Fi module, chip antenna, and GPIO pins clearly visible, ideal for embedding wireless internet connectivity into DIY electronics projects.](https://www.flux.ai/p/assets/blogs/everything-about-esp8266/main.webp)

### ESP8266 Pinout Guide: Complete GPIO Reference & IoT Project Tips

10 Min Read](https://www.flux.ai/p/blog/esp8266-pinout-everything-you-need-to-know)[

![Attiny85 chip in two different packages viewed on top, also showing pinout diagram](https://www.flux.ai/p/assets/blogs/attiny85/main.webp)

### Introduction to the ATtiny85 Microcontroller

12 Min Read](https://www.flux.ai/p/blog/introduction-to-the-attiny85-microcontroller)[

![STM32 microcontroller chip overview – Why choose STM32? Discover STM32F4 ARM-based processors, optimized for performance with USB OTG, SWD, and UART support](https://www.flux.ai/p/assets/blogs/stm32-things-you-need-to-know/main.webp)

### STM32: Things You Need to Know

10 Min Read](https://www.flux.ai/p/blog/stm32-things-you-need-to-know)[

![Arduino Nano Guide](https://www.flux.ai/p/assets/blogs/arduino-nano-guide/main.webp)

### Arduino Nano Guide

10 Min Read](https://www.flux.ai/p/blog/arduino-nano-guide)[

![A top view photo of raspberry pi zero 2 w board](https://www.flux.ai/p/assets/blogs/pi-zero-2w/main.webp)

### Raspberry Pi Zero 2 W Review: a Powerful and Affordable Mini Computer

9 Min Read](https://www.flux.ai/p/blog/raspberry-pi-zero-2-w-review-a-powerful-and-affordable-mini-computer)[

![RP2350 A4 Stepping: Why Raspberry Pi Pico’s Latest Upgrade Changes Everything](https://www.flux.ai/p/assets/blogs/rp2350-a4-stepping/main.webp)

### RP2350 A4 Stepping: Why Raspberry Pi Pico’s Latest Upgrade Changes Everything

8 Min Read](https://www.flux.ai/p/blog/rp2350-a4-stepping-why-raspberry-pi-picos-latest-upgrade-changes-everything)[

![Photos of Raspberry Pi Pico 2 PCB board and its predecessor Raspberry Pi Pico boards laid out with a text suggesting their key differences](https://www.flux.ai/p/assets/blogs/pi-pico-vs-pi-pico-2/main.webp)

### Raspberry Pi Pico 2 vs Pico: Key Differences and Upgrades

8 Min Read](https://www.flux.ai/p/blog/whats-new-in-the-raspberry-pi-pico-2-a-showdown-with-the-original-raspberry-pi-pico)[

![Choosing the Right Platform to Build Your Project](https://www.flux.ai/p/assets/blogs/choosing-the-right-microcontroller/main.webp)

### Choosing the Right Platform to Build Your Project

9 Min Read](https://www.flux.ai/p/blog/choosing-the-right-platform-to-build-your-project)[

![Raspberry pi boards and arduino boards laid out side by side.](https://www.flux.ai/p/assets/blogs/arduino-vs-raspberry-pi/main.webp)

### Arduino vs. Raspberry Pi: Key Differences and Which to Choose

8 Min Read](https://www.flux.ai/p/blog/arduino-vs-raspberry-pi-comparison)[

![ESP32 boards and Arduino boards side by side, highlighting the comparison between these popular IoT microcontroller platforms.](https://www.flux.ai/p/assets/blogs/esp32-vs-arduino/main.webp)

### ESP32 vs Arduino: Key Differences & Which to Choose?

8 Min Read](https://www.flux.ai/p/blog/esp32-vs-arduino)[

![arduino board and text suggesting this is all about the arduino map () function](https://www.flux.ai/p/assets/blogs/arduino-map-function/main.webp)

### How to Use the Arduino map() Function: A Complete Guide

4 Min Read](https://www.flux.ai/p/blog/how-to-use-the-arduino-map-function-a-complete-guide)[

![A simplified schematic diagram illustrates how pull-up and pull-down resistors are utilized in microcontroller applications](https://www.flux.ai/p/assets/blogs/pull-up-down-resistors/main.webp)

### Understanding Pull-up and Pull-down Resistors: A Guide for Arduino and Microcontrollers

7 Min Read](https://www.flux.ai/p/blog/understanding-pull-up-and-pull-down-resistors-a-guide-for-arduino-and-microcontrollers)[

![What Is an Open Circuit? Causes, Examples, and Troubleshooting](https://www.flux.ai/p/assets/blogs/what-is-an-open-circuit/main.webp)

### What Is an Open Circuit? Causes, Examples, and Troubleshooting

10 Min Read](https://www.flux.ai/p/blog/what-is-an-open-circuit)[

![An HX711 load cell amplifier board connected to a load cell and an Arduino.](https://www.flux.ai/p/assets/blogs/hx711-load-cell-amplifier/main.webp)

### HX711 Load Cell Amplifier: Wiring, Calibration, and PCB Design Guide

8 Min Read](https://www.flux.ai/p/blog/hx711-load-cell-amplifier)

See All (24)

## Let’s start building.

Let’s build your idea together. All you need to do is describe what you want to make, or what problem you want to solve. Flux will work with you to make it a reality.

[Try it Free](https://www.flux.ai/signup)

 ![Close-up of a Flux-designed printed circuit board](https://www.flux.ai/p/assets/homepage-v2/mission-visual.webp)
