0
0
AutocadHow-ToBeginner · 3 min read

How to Use Seven Segment Display with Arduino: Simple Guide

To use a seven segment display with Arduino, connect each segment pin to Arduino digital pins through resistors, then control segments by setting pins HIGH or LOW. Use a simple program to turn on segments to display numbers or letters.
📐

Syntax

Each segment of the seven segment display is connected to an Arduino digital pin. You control each segment by setting the pin HIGH (on) or LOW (off). Use pinMode(pin, OUTPUT) to set pins as outputs and digitalWrite(pin, value) to control them.

arduino
pinMode(segmentPin, OUTPUT);
digitalWrite(segmentPin, HIGH); // turn segment on
digitalWrite(segmentPin, LOW);  // turn segment off
💻

Example

This example shows how to display the digit '3' on a common cathode seven segment display connected to Arduino pins 2 to 8.

arduino
const int a = 2;
const int b = 3;
const int c = 4;
const int d = 5;
const int e = 6;
const int f = 7;
const int g = 8;

void setup() {
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);

  // Display digit '3'
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, HIGH);
}

void loop() {
  // Nothing to do here
}
Output
The seven segment display shows the digit '3'.
⚠️

Common Pitfalls

  • Not using current-limiting resistors can damage the display or Arduino pins.
  • Confusing common cathode and common anode displays causes wrong segment lighting.
  • For common anode, segments turn on by setting pins LOW, not HIGH.
  • Incorrect wiring of pins leads to wrong digits or no display.
arduino
/* Wrong way for common anode display */
digitalWrite(a, HIGH); // This turns segment off

/* Right way for common anode display */
digitalWrite(a, LOW);  // This turns segment on
📊

Quick Reference

SegmentArduino PinState ON (Common Cathode)State ON (Common Anode)
a2HIGHLOW
b3HIGHLOW
c4HIGHLOW
d5HIGHLOW
e6HIGHLOW
f7HIGHLOW
g8HIGHLOW

Key Takeaways

Always use resistors to protect your seven segment display and Arduino pins.
Know if your display is common cathode or common anode to set pin states correctly.
Control each segment by setting Arduino pins HIGH or LOW depending on display type.
Test wiring carefully to ensure correct digits show on the display.
Use simple code to turn on segments and display numbers or letters.