Seven segment display counter

A seven segment display is typically used to display numbers from 0-9. It consists of 7 bar segments and a dot( 8 Segments). They are numbered A to F and DP for the dot or decimal place. There are 2 types of 7 Segment display

  • Common anode
  • Common cathode

 

Seven Segments are labelled as below.

For more detail on 7 segment display refer my blog post on it here.

To display number we need to turn on the correct segments as shown below:

0- ABCDEF
1- BC
2- ABGED
3- ABCDG
4- BCFG
5- ACDFG
6- ACDEFG
7- ABC
8- ABCDEFG
9- ABCFG

List of Parts needed

  1. Common cathode seven segment LED display
  2. 470 Ohm resistors – 7 nos
  3. Arduino UNO

Schematic diagram:

Seven Segment counter

 

Below is the code for the one digit counter

//Pins for seven segment
int sega = 1;
int segb = 2;
int segc = 3;
int segd = 4;
int sege = 5;
int segf = 6;
int segg = 7;
int dispa = 8;
int dispb = 9;

void setup() {
 // Setup code to run once
   pinMode(sega,OUTPUT);
   pinMode(segb,OUTPUT);
   pinMode(segc,OUTPUT);
   pinMode(segd,OUTPUT);
   pinMode(sege,OUTPUT);
   pinMode(segf,OUTPUT);
   pinMode(segg,OUTPUT);
   pinMode(dispa,OUTPUT);
   pinMode(dispb,OUTPUT);
}

void loop() {
 // put your main code here, to run repeatedly:
  for(int count=0;count<10;count++)
  {
    digitalWrite(sega,LOW);
    digitalWrite(segb,LOW);
    digitalWrite(segc,LOW);
    digitalWrite(segd,LOW);
    digitalWrite(sege,LOW);
    digitalWrite(segf,LOW);
    digitalWrite(segg,LOW);
    if(count==0){
     digitalWrite(sega,HIGH);
     digitalWrite(segb,HIGH);
     digitalWrite(segc,HIGH);
     digitalWrite(segd,HIGH);
     digitalWrite(sege,HIGH);
     digitalWrite(segf,HIGH);
  }
  if(count==1){
    digitalWrite(segb,HIGH);
    digitalWrite(segc,HIGH);
  }
  if(count==2){
    digitalWrite(sega,HIGH);
    digitalWrite(segb,HIGH);
    digitalWrite(segg,HIGH);
    digitalWrite(sege,HIGH);
    digitalWrite(segd,HIGH);
  }
  if(count==3){
    digitalWrite(sega,HIGH);
    digitalWrite(segb,HIGH);
    digitalWrite(segc,HIGH);
    digitalWrite(segd,HIGH);
    digitalWrite(segg,HIGH);
  }
  if(count==4){
    digitalWrite(segb,HIGH);
    digitalWrite(segc,HIGH);
    digitalWrite(segf,HIGH);
    digitalWrite(segg,HIGH);
  }
  if(count==5){
    digitalWrite(sega,HIGH);
    digitalWrite(segc,HIGH);
    digitalWrite(segd,HIGH);
    digitalWrite(segf,HIGH);
    digitalWrite(segg,HIGH);
  }
  if(count==6){
    digitalWrite(sega,HIGH);
    digitalWrite(segc,HIGH);
    digitalWrite(segd,HIGH);
    digitalWrite(sege,HIGH);
    digitalWrite(segf,HIGH);
    digitalWrite(segg,HIGH);
  }
  if(count==7){
    digitalWrite(sega,HIGH);
    digitalWrite(segb,HIGH);
    digitalWrite(segc,HIGH);
  }
  if(count==8){
    digitalWrite(sega,HIGH);
    digitalWrite(segb,HIGH);
    digitalWrite(segc,HIGH);
    digitalWrite(segd,HIGH);
    digitalWrite(sege,HIGH);
    digitalWrite(segf,HIGH);
    digitalWrite(segg,HIGH);
  }
  if(count==9){
    digitalWrite(sega,HIGH);
    digitalWrite(segb,HIGH);
    digitalWrite(segc,HIGH);
    digitalWrite(segf,HIGH);
    digitalWrite(segg,HIGH);
  } 
  delay(1000);
 }
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.