Controlling a 7-Segment LED Display


The following is for the Common Anode F5161BH, 5161BS, 5611BS, or 5611BH with pins on the top and bottom.
 

    7-Segment LED display           7-segment display common anode pins
1 Make the following 9 connections:

Arduino pins 7-segment pins Description
1 1 e
2 2 d
3
4 4 c
5 5 DP
6 6 b
7 7 a
5V 8 to 150 Ω Vcc
9 9 f
10 10 g
common anode connections
2 Create a new Bare Minimum program by selecting File from the menu
  • then select Examples
  • then select Basics
  • then select BareMinimum
Type in this program to turn on segments b and c to show the digit 1.  



















For a Common Anode display, a LOW signal turns on the LED, and a HIGH signal turns off the LED.
// show the digit 1 on a Common Anode 7-segment LED display
int segA = 7;
int segB = 6;
int segC = 4;
int segD = 2;
int segE = 1;
int segF = 9;
int segG = 10;
int segDP = 5;

void setup() {
  pinMode(segA, OUTPUT);
  pinMode(segB, OUTPUT);
  pinMode(segC, OUTPUT);
  pinMode(segD, OUTPUT);
  pinMode(segE, OUTPUT);
  pinMode(segF, OUTPUT);
  pinMode(segG, OUTPUT);
  pinMode(segDP, OUTPUT);

}

void loop() {
  // this is for a Common Anode display where a LOW turns on a segment
  // displays the digit 1
  digitalWrite(segA, HIGH);   // turn off LED
  digitalWrite(segB, LOW);    // turn on LED
  digitalWrite(segC, LOW);
  digitalWrite(segD, HIGH);
  digitalWrite(segE, HIGH);
  digitalWrite(segF, HIGH);
  digitalWrite(segG, HIGH);
  digitalWrite(segDP, HIGH);
}
3 Upload and run the program. You should see the digit 1.