Call Us Now
0242159130 | 0546096840
Up to 2% reward

For new all Customers

Delevery schedule

We deliver  the same day through VIP bus parcel Service in Ghana

Discount on order gift

Save ¢10.00 when you spend ¢600+! 

how to control segment display

how to control segment display

Experiment description 13

In this tutorial, we will program the Arduino to achieve the controlling of a segment display. 

Hardware required

1 * Arduino UNO

1 * USB Cable 

1 * 220Ω Resistor 

1 * 7-segment Display 

1 * Breadboard 

Several jumper wires 

Principle of operation

The 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, electronic meters, basic calculators, and other electronic devices that display numerical information. The seven-segment display is an 8-shaped LED display device composed of eight LEDs (including a decimal point).The segments respectively named a,b, c, d, e, f, g, and dp. The segment display can be divided into two types: common anode and common cathode segment displays, by internal connections.

For a common-anode LED, the common anode should be connected to the power supply(VCC);for a common-cathode LED,the common cathode should be connected to the ground (GND).
Each segment of a segment display is composed of an LED, so a resistor is needed for protecting the LED. A 7-segment display has seven segments for displaying a figure and one more for displaying a decimal point. For example,if you want to display a number'1', you should only light the segment b and c, as shown below.
 Code

//File name:   Experiment 13

//Description:  Segment display Numbers 0 to 9 .

//Website: www.okuelectronics.com

//E-mail: support@okuelectronics.com

//Author: Okudzeto osei prince

//Date: 2019/08/08 

int a=7; //definition digital 7  pins as pin to control 'a' section(segment)

int b=6; //definition digital 6  pins as pin to control 'b' section(segment)

int c=4; //definition digital 4  pins as pin to control 'c' section(segment)

int d=11;//definition digital 11 pins as pin to control 'd' section(segment)

int e=10;//definition digital 10 pins as pin to control 'e' section(segment)

int f=8; //definition digital 8  pins as pin to control 'f' section(segment)

int g=9; //definition digital 9  pins as pin to control 'g' section(segment)

int dp=5;//definition digital 5  pins as pin to control 'dp' section(segment)

void digital_0(void) //Segment display digital 0

{

  digitalWrite(a,HIGH);

  digitalWrite(b,HIGH);

  digitalWrite(c,HIGH);

  digitalWrite(d,HIGH);

  digitalWrite(e,HIGH);

  digitalWrite(f,HIGH);

  digitalWrite(g, LOW);

  digitalWrite(dp,LOW);

}

void digital_1(void) //Segment display digital 1

{

  digitalWrite(a,LOW);

  digitalWrite(b,HIGH);

  digitalWrite(c,HIGH);

  digitalWrite(d,LOW);

  digitalWrite(e,LOW);

  digitalWrite(f,LOW);

  digitalWrite(g,LOW);

  digitalWrite(dp,LOW);

}

void digital_2(void) //Segment display digital 2

{

  digitalWrite(a,HIGH);

  digitalWrite(b,HIGH);

  digitalWrite(c,LOW);

  digitalWrite(d,HIGH);

  digitalWrite(e,HIGH);

  digitalWrite(f,LOW);

  digitalWrite(g,HIGH);

  digitalWrite(dp,LOW);

}

void digital_3(void) //Segment display digital 3

{

  digitalWrite(a,HIGH);

  digitalWrite(b,HIGH);

  digitalWrite(c,HIGH);

  digitalWrite(d,HIGH);

  digitalWrite(e,LOW);

  digitalWrite(f,LOW);

  digitalWrite(g,HIGH);

  digitalWrite(dp,LOW);

}

void digital_4(void) //Segment display digital 4

{

  digitalWrite(a,LOW);

  digitalWrite(b,HIGH);

  digitalWrite(c,HIGH);

  digitalWrite(d,LOW);

  digitalWrite(e,LOW);

  digitalWrite(f,HIGH);

  digitalWrite(g,HIGH);

  digitalWrite(dp,LOW);

}

void digital_5(void) //Segment display digital 5

{

  digitalWrite(a,HIGH);

  digitalWrite(b,LOW);

  digitalWrite(c,HIGH);

  digitalWrite(d,HIGH);

  digitalWrite(e,LOW);

  digitalWrite(f,HIGH);

  digitalWrite(g,HIGH);

  digitalWrite(dp,LOW);

}

void digital_6(void) //Segment display digital 6

{

  digitalWrite(a,HIGH);

  digitalWrite(b,LOW);  

  digitalWrite(c,HIGH);

  digitalWrite(d,HIGH);

  digitalWrite(e,HIGH);

  digitalWrite(f,HIGH);

  digitalWrite(g,HIGH);

  digitalWrite(dp,LOW);

}

void digital_7(void) //Segment display digital 7

{

  digitalWrite(a,HIGH);

  digitalWrite(b,HIGH);  

  digitalWrite(c,HIGH);  

  digitalWrite(d,LOW); 

  digitalWrite(e,LOW);

  digitalWrite(f,LOW);

  digitalWrite(g,LOW);

  digitalWrite(dp,LOW);

}

void digital_8(void) //Segment display digital 8

{

  digitalWrite(a,HIGH);

  digitalWrite(b,HIGH);

  digitalWrite(c,HIGH);

  digitalWrite(d,HIGH);

  digitalWrite(e,HIGH);

  digitalWrite(f,HIGH);

  digitalWrite(g,HIGH);

  digitalWrite(dp,LOW);

}

void digital_9(void) //Segment display digital 9

{

  digitalWrite(a,HIGH);

  digitalWrite(b,HIGH);

  digitalWrite(c,HIGH);

  digitalWrite(d,HIGH);

  digitalWrite(e,LOW);

  digitalWrite(f,HIGH);

  digitalWrite(g,HIGH);

  digitalWrite(dp,LOW);

}

void setup()

{

  int i;             //Define variables

  for(i=4;i<=11;i++)

  pinMode(i,OUTPUT); //Set up 4 ~ 11 pins to output mode

}

void loop()

{

  digital_0(); //Segment display digital 0

  delay(1000); //Delay 1s

  digital_1(); //Segment display digital 1

  delay(1000); //Delay 1s

  digital_2(); //Segment display digital 2

  delay(1000); //Delay 1s

  digital_3(); //Segment display digital 3

  delay(1000); //Delay 1s

  digital_4(); //Segment display digital 4

  delay(1000); //Delay 1s

  digital_5(); //Segment display digital 5

  delay(1000); //Delay 1s

  digital_6(); //Segment display digital 6

  delay(1000); //Delay 1s

  digital_7(); //Segment display digital 7

  delay(1000); //Delay 1s

  digital_8(); //Segment display digital 8

  delay(1000); //Delay 1s

  digital_9(); //Segment display digital 8

  delay(1000); //Delay 1s

}


Compile the program and upload to Arduino UNO board Now,you should see the number 0~9 and characters A~F displayed in turn on the segment display.



Add Comment