Me and My Arduino Uno updated 11 JAN 2016


7 seg display with segments labelled


Arduino Uno with Breadboard wired up to run a Radio Shack 7 Segment LED.


Wiring looks (and is) messy, due to the strange layout of the pins.

There is a nice table of the segment bytes on the
Wiki 7-seg page. And a wonderful diagram of the
Arduino Uno by PIGHIXXX here and many more diagrams of boards & processors from the same source.

To ALL ARDUINOISTS! There is a wonderful online course offered by UCI, Irvine called Introduction to the Internet of Things and Embedded Systems. It's a six module course working with Arduino, Raspberry Pi, and C programming conducted by Professor Ian Harris who is fantastic. Auditing is free.

Arduino and breadboard with 7-segment LED wired up.

The code shown below runs on an Arduino Uno to drive a 7 segment LED from Radio Shack (276-075 which is a National Semiconductor one: ELS321HDB/A) very different from the ones you see in the Arduino tutorials.

// Arduino 7 segment display example software
// http://www.hacktronics.com/Tutorials/arduino-and-7-segment-led.html
// License: http://www.opensource.org/licenses/mit-license.php (Go crazy)
// modified by Clair Dunn http://www.borderlinegeek.com
// ---------------------------------------------------------------------
// common anode section and in-code comments added by Clair Dunn 12/2011
// pin connection comments clarified by Clair Dunn 1/2016
//----------------------------------------------------------------------
// Define the LED digit patterns, from 0 - 9
// Note that these patterns are for common cathode displays
// For common anode displays, change the 1's to 0's and 0's to 1's
// 1 = LED on, 0 = LED off, in this order:

//                                    Arduino pin: 2,3,4,5,6,7,8

/*If you were using a common anode LED you would use this section
byte seven_seg_digits[10][7] = { { 0,0,0,0,0,0,1 },  // = 0 x
                                      { 1,0,0,1,1,1,1 },  // = 1 x
                                      { 0,0,1,0,0,1,0 },  // = 2 x
                                      { 0,0,0,0,1,1,0 },  // = 3 x
                                      { 1,0,0,1,1,0,0 },  // = 4 x
                                      { 0,1,0,0,1,0,0 },  // = 5 x
                                      { 0,1,0,0,0,0,0 },  // = 6 x
                                      { 0,0,0,1,1,1,1 },  // = 7 x
                                      { 0,0,0,0,0,0,0 },  // = 8 x
                                      { 0,0,0,1,1,0,0 }   // = 9 x
                                       };
*/

//                                    Arduino pin: 2,3,4,5,6,7,8

 byte seven_seg_digits[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
                                       };

// set the Arduino pins connected to the LED segments on Radio Shack 276-075
// which is National Semiconductor ELS-321HDB/A (very different from
// standard 7-seg display
// the LED seg lights are, starting with the flat top and moving clockwise:
// A B C D(bottom seg) E F G(middle bar)

// comment list     //  LEDpin# > Arduino pin#    seg name
void setup() {
  pinMode(2, OUTPUT);  // 14      >     2             A
  pinMode(3, OUTPUT);  // 13      >     3             B
  pinMode(4, OUTPUT);  //  8      >     4             C
  pinMode(5, OUTPUT);  //  7      >     5             D
  pinMode(6, OUTPUT);  //  6      >     6             E
  pinMode(7, OUTPUT);  //  2      >     7             F
  pinMode(8, OUTPUT);  //  1      >     8             G
  pinMode(9, OUTPUT);  // RDP9    >     9        decimal point
  writeDot(0);  // start with the "dot" off
}

void writeDot(byte dot) {
  digitalWrite(9, dot); // decimal point - pin 9 on Arduino
}

void sevenSegWrite(byte digit) {
  byte pin = 2; // Arduino pin where the segment list starts
  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pin, seven_seg_digits[digit][segCount]);
    ++pin;
  }
}

// displays digits from 9 to 0
void loop() {
  for (byte count = 10; count > 0; --count) {
   delay(1000);
   sevenSegWrite(count - 1);
  }
  delay(4000);
}