Menu
CoddyTech

Seven-Segment Display

Part of the Displays and Sensors section of Coddy's Arduino journey. Lesson 1 of 24.

A seven-segment display draws a digit with seven small bars called segments. They are named with letters: a along the top, then clockwise b and c down the right side, d along the bottom, e and f up the left side, and g across the middle.

Each segment is an LED with its own pin. On this display the segments share one positive leg, the common anode, wired to 5V. That turns the usual rule upside down: a segment lights when its pin is LOW, because current flows from 5V into the pin. A HIGH pin turns it off.

digitalWrite(2, LOW);   // segment a lights
digitalWrite(3, HIGH);  // segment b goes dark

To draw a digit, light its segments and leave the rest off. A 1 is b and c. An 8 lights all seven.

challenge icon

Challenge

Easy

The segments are on pins 2 (a), 3 (b), 4 (c), 5 (d), 6 (e), 7 (f) and 8 (g). The starter turns them all off. Draw a 2:

  • a 2 is segments a, b, g, e and d
  • light each one with digitalWrite(pin, LOW) in setup()

Press Run to see your digit, then Check.

Try it yourself

// Segment pins: a 2, b 3, c 4, d 5, e 6, f 7, g 8
// Common anode: LOW lights a segment, HIGH turns it off.

void setup() {
  for (int pin = 2; pin <= 8; pin++) {
    pinMode(pin, OUTPUT);
    digitalWrite(pin, HIGH);  // every segment off
  }

  // light the segments of a 2 here
}

void loop() {
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Displays and Sensors

Practice on your own: Arduino playground