top of page

Arduino with Seven Segment Display

A seven-segment display is a form of electronic display device for displaying decimal numerals that is an alternative to the more complex dot matrix displays. Seven-segment
displays are widely used in digital clocks, electronics meters, basic calculators, and other electronic devices that display numerical information.
Learn more...

LED-seven-sement-display-pinout-image.pn

Seven Segment Display

Here, we will make a simple counter using Arduino, seven-segment display and the 74HC595 shift register to control the display. Our counter will count from 0-9. You can combine multiple seven-segment displays to display multiple numbers, such as in a timer project.

Schematic

7 segment frtzing.png

Sketch

​

// define the LED digit patterns, from 0 - 9
byte seven_seg_digits[10] = {

  B11111100,  // = 0
  B01100000,  // = 1
  B11011010,  // = 2
  B11110010,  // = 3
  B01100110,  // = 4
  B10110110,  // = 5
  B10111110,  // = 6
  B11100000,  // = 7
  B11111110,  // = 8
  B11100110   // = 9};
 
// connect the ST_CP of 74HC595 to pin3 on the Uno
int latchPin = 2;
// connect the SH_CP of 74HC595 to pin4 on the Uno
int clockPin = 4;
// connect the DS of 74HC595 to pin2 on the Uno
int dataPin = 3;
 
void setup() {
  // Set latchPin, clockPin, dataPin as output
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}
 
// display a number on the digital segment display
void sevenSegWrite(byte digit) {
  // set the latchPin to low, before sending data
  digitalWrite(latchPin, LOW);
     
  // the original data (bit pattern)
  shiftOut(dataPin, clockPin, LSBFIRST, seven_seg_digits[digit]);  
 
  // set the latchPin to high, after sending data
  digitalWrite(latchPin, HIGH);
}
 
void loop() {       
  // count from 9 to 0
  for (byte digit = 10; digit > 0; --digit) {
    delay(1000);
    sevenSegWrite(digit - 1); 
  }
   
  // pause for 3 seconds
  delay(3000);
}

​

Upload the above sketch to your Arduino and watch the seven-segment display make a count down from 9-0, pauses for three seconds then start over.

bottom of page