7 Segment Arduino Interface

Seven Segment Displays are very much useful to show and communicate numbers visually, and it is used widely in different applications, this simple article describes about the seven segment display and its types then 7 Segment Arduino interface.




7 Segment Display

The name it self says about this display module, it contains seven LEDs to display numeric numbers or Hexa decimal numbers and most display available with dot point LED.

Here each LED connected with separate terminals and either Anode or Cathode of all LEDs are commonly connected to give the power supply.

7 Segment Display pinout

This is single Seven segment module some display available with two or more seven segments and refer datasheet for proper pin configurations. Here each segment contains single LED, some large display will have LED array for each segments.

Arduino 7 Segment Interface

Here Common Cathode 7 segment display is taken for experiments and the common terminals 3, 8 are connected to the ground through 220Ω / 1 Watt Resistor and each terminals are connected to the Arduino digital pins, and these digital pins are assigned as output.

This is valid for only common cathode type of 7 segment display and you can alter it as 3 & 8 pin to +Vcc for common Anode.

7 Segment Arduino Code

 

int segment_a = 7; // declare the variables
int segment_b = 6;
int segment_c = 5;
int segment_d = 4;
int segment_e = 3;
int segment_f = 2;
int segment_g = 1;
int segment_dp = 0;


void setup() 
{
  pinMode(segment_a,OUTPUT); // configure all seven segment pins to outputs
  pinMode(segment_b,OUTPUT);
  pinMode(segment_c,OUTPUT);
  pinMode(segment_d,OUTPUT);
  pinMode(segment_e,OUTPUT);
  pinMode(segment_f,OUTPUT);
  pinMode(segment_g,OUTPUT);
  pinMode(segment_dp,OUTPUT);
 
}

void loop() {

for (int i = 0; i < 10; i++) 
{ // make count 0 - 9
 switch(i)
   { // switch statemet to display the number 
  
  case 0: // set relevent segments HIGH and others LOW to display Number 0
  digitalWrite(segment_a,HIGH);
  digitalWrite(segment_b,HIGH);
  digitalWrite(segment_c,HIGH);
  digitalWrite(segment_d,HIGH);
  digitalWrite(segment_e,HIGH);
  digitalWrite(segment_f,HIGH);
  digitalWrite(segment_g,LOW);
  digitalWrite(segment_dp,LOW);
  break;

  case 1: // set relevent segments HIGH and others LOW to display Number 1
  digitalWrite(segment_a,LOW);
  digitalWrite(segment_b,HIGH);
  digitalWrite(segment_c,HIGH);
  digitalWrite(segment_d,LOW);
  digitalWrite(segment_e,LOW);
  digitalWrite(segment_f,LOW);
  digitalWrite(segment_g,LOW);
  digitalWrite(segment_dp,LOW);
  break;

  case 2: // set relevent segments HIGH and others LOW to display Number 2
  digitalWrite(segment_a,HIGH);
  digitalWrite(segment_b,HIGH);
  digitalWrite(segment_c,LOW);
  digitalWrite(segment_d,HIGH);
  digitalWrite(segment_e,HIGH);
  digitalWrite(segment_f,LOW);
  digitalWrite(segment_g,HIGH);
  digitalWrite(segment_dp,LOW);
  break;

  case 3: // set relevent segments HIGH and others LOW to display Number 3
  digitalWrite(segment_a,HIGH);
  digitalWrite(segment_b,HIGH);
  digitalWrite(segment_c,HIGH);
  digitalWrite(segment_d,HIGH);
  digitalWrite(segment_e,LOW);
  digitalWrite(segment_f,LOW);
  digitalWrite(segment_g,HIGH);
  digitalWrite(segment_dp,LOW);
  break;

  case 4: // set relevent segments HIGH and others LOW to display Number 4
  digitalWrite(segment_a,LOW);
  digitalWrite(segment_b,HIGH);
  digitalWrite(segment_c,HIGH);
  digitalWrite(segment_d,LOW);
  digitalWrite(segment_e,LOW);
  digitalWrite(segment_f,HIGH);
  digitalWrite(segment_g,HIGH);
  digitalWrite(segment_dp,LOW);
  break;

  case 5: // set relevent segments HIGH and others LOW to display Number 5
  digitalWrite(segment_a,HIGH);
  digitalWrite(segment_b,LOW);
  digitalWrite(segment_c,HIGH);
  digitalWrite(segment_d,HIGH);
  digitalWrite(segment_e,LOW);
  digitalWrite(segment_f,HIGH);
  digitalWrite(segment_g,HIGH);
  digitalWrite(segment_dp,LOW);
  break;

  case 6: // set relevent segments HIGH and others LOW to display Number 6
  digitalWrite(segment_a,HIGH);
  digitalWrite(segment_b,LOW);
  digitalWrite(segment_c,HIGH);
  digitalWrite(segment_d,HIGH);
  digitalWrite(segment_e,HIGH);
  digitalWrite(segment_f,HIGH);
  digitalWrite(segment_g,HIGH);
  digitalWrite(segment_dp,LOW);
  break;

  case 7: // set relevent segments HIGH and others LOW to display Number 7
  digitalWrite(segment_a,HIGH);
  digitalWrite(segment_b,HIGH);
  digitalWrite(segment_c,HIGH);
  digitalWrite(segment_d,LOW);
  digitalWrite(segment_e,LOW);
  digitalWrite(segment_f,LOW);
  digitalWrite(segment_g,LOW);
  digitalWrite(segment_dp,LOW);
  break;

  case 8: // set relevent segments HIGH and others LOW to display Number 8
  digitalWrite(segment_a,HIGH);
  digitalWrite(segment_b,HIGH);
  digitalWrite(segment_c,HIGH);
  digitalWrite(segment_d,HIGH);
  digitalWrite(segment_e,HIGH);
  digitalWrite(segment_f,HIGH);
  digitalWrite(segment_g,HIGH);
  digitalWrite(segment_dp,LOW);
  break;

  case 9: // set relevent segments HIGH and others LOW to display Number 9
  digitalWrite(segment_a,HIGH);
  digitalWrite(segment_b,HIGH);
  digitalWrite(segment_c,HIGH);
  digitalWrite(segment_d,HIGH);
  digitalWrite(segment_e,LOW);
  digitalWrite(segment_f,HIGH);
  digitalWrite(segment_g,HIGH);
  digitalWrite(segment_dp,LOW);
  break;

   }
  delay(1000); // delay for 1 second.
  }

}

Invert the code  as low to HIGH and high to LOW if you use Common Anode type seven segment display.




Add a Comment

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