Experiment 10
Experiment 10
Experiment 10
La Paz, Iloilo
Discussion
A seven-segment display (SSD), or seven-segment indicator, 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.
Figure 10.1 A typical 7-segment LED display component with decimal point.
46
Figure 10.2.The individual segments of a seven-segment display
The 7-segment display, also written as “seven segment display”, consists of seven LEDs
(hence its name) arranged in a rectangular fashion as shown in Figure 10.2. Each of the seven
LEDs is called a segment because when illuminated the segment forms part of a numerical digit
(both Decimal and Hex) to be displayed. An additional 8th LED is sometimes used within the
same package thus allowing the indication of a decimal point, (DP) when two or more 7-segment
displays are connected together to display numbers greater than ten.
Each one of the seven LEDs in the display is given a positional segment with one of its
connection pins being brought straight out of the rectangular plastic package. These individually
LED pins are labelled from a through to g representing each individual LED. The other LED
pins are connected together and wired to form a common pin.
So by forward biasing the appropriate pins of the LED segments in a particular order,
some segments will be light and others will be dark allowing the desired character pattern of the
number to be generated on the display. This then allows us to display each of the ten decimal
digits 0 through to 9 on the same 7-segment display.
The displays common pin is generally used to identify which type of 7-segment display it
is. As each LED has two connecting pins, one called the “Anode” and the other called the
“Cathode”, there are therefore two types of LED 7-segment display called: Common Cathode
(CC) and Common Anode(CA).
47
The difference between the two displays, as their name suggests, is that the common
cathode has all the cathodes of the 7-segments connected directly together and the common
anode has all the anodes of the 7-segments connected together and is illuminated as follows.
Common Cathode
In the common cathode display, all the cathode connections of the LED segments are
joined together to logic “0” or ground. The individual segments are illuminated by application of
a “HIGH”, or logic “1” signal via a current limiting resistor to forward bias the individual Anode
terminals (a-g).
48
In general, common anode displays are more popular as many logic circuits can sink
more current than they can source. Also note that a common cathode display is not a direct
replacement in a circuit for a common anode display and vice versa, as it is the same as
connecting the LEDs in reverse, and hence light emission will not take place.
Depending upon the decimal digit to be displayed, the particular set of LEDs is forward
biased. For instance, to display the numerical digit 0, we will need to light up six of the LED
segments corresponding to a, b, c, d, e and f. Then the various digits from 0 through 9 can be
displayed using a 7-segment display as shown in Figure 10.5.
.
Figure 10.5. Segments corresponds to a number to be displayed.
Then for a 7-segment display, we can produce a truth table giving the individual
segments that need to be illuminated in order to produce the required decimal digit from 0
through 9 as shown in the Table 7.1 below.
Individual Segments
Decimal
Illuminated
Digit
a b c d e f g
0 × × × × × ×
1 × ×
2 × × × × ×
3 × × × × ×
4 × × × ×
5 × × × × ×
6 × × × × × ×
7 × × ×
8 × × × × × × ×
9 × × × × ×
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
void loop()
{
// loop to turn leds od seven seg ON
for(int i=2;i<9;i++)
{
digitalWrite(i,HIGH);
delay(600);
}
delay(1000);
2. After uploading, disconnect first the Arduino microcontroller to the laptop/computer. Prepare
seven-segment display and follow the connections of Figure 10.6 below.
50
Wired the following connections:
4. After connecting all the necessary configurations, connect again the Arduino microcontroller
to the laptop/computer by a usb-to-serial cord.
//function header
void Num_Write(int);
void setup()
{
// set pin modes
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
void loop()
{
52
Answer guide question number 2.
7. And also with the same connections still, upload this source code:
void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(9, 0); // start with the "dot" off
}
void loop() {
// write '9'
digitalWrite(2, 1);
digitalWrite(3, 1);
digitalWrite(4, 1);
digitalWrite(5, 0);
digitalWrite(6, 0);
digitalWrite(7, 1);
digitalWrite(8, 1);
delay(1000);
// write '8'
digitalWrite(2, 1);
digitalWrite(3, 1);
digitalWrite(4, 1);
digitalWrite(5, 1);
digitalWrite(6, 1);
digitalWrite(7, 1);
digitalWrite(8, 1);
delay(1000);
// write '7'
digitalWrite(2, 1);
digitalWrite(3, 1);
digitalWrite(4, 1);
digitalWrite(5, 0);
digitalWrite(6, 0);
digitalWrite(7, 0);
digitalWrite(8, 0);
delay(1000);
// write '6'
digitalWrite(2, 1);
digitalWrite(3, 0);
digitalWrite(4, 1);
digitalWrite(5, 1);
53
digitalWrite(6, 1);
digitalWrite(7, 1);
digitalWrite(8, 1);
delay(1000);
// write '5'
digitalWrite(2, 1);
digitalWrite(3, 0);
digitalWrite(4, 1);
digitalWrite(5, 1);
digitalWrite(6, 0);
digitalWrite(7, 1);
digitalWrite(8, 1);
delay(1000);
// write '4'
digitalWrite(2, 0);
digitalWrite(3, 1);
digitalWrite(4, 1);
digitalWrite(5, 0);
digitalWrite(6, 0);
digitalWrite(7, 1);
digitalWrite(8, 1);
delay(1000);
// write '3'
digitalWrite(2, 1);
digitalWrite(3, 1);
digitalWrite(4, 1);
digitalWrite(5, 1);
digitalWrite(6, 0);
digitalWrite(7, 0);
digitalWrite(8, 1);
delay(1000);
// write '2'
digitalWrite(2, 1);
digitalWrite(3, 1);
digitalWrite(4, 0);
digitalWrite(5, 1);
digitalWrite(6, 1);
digitalWrite(7, 0);
digitalWrite(8, 1);
delay(1000);
// write '1'
digitalWrite(2, 0);
digitalWrite(3, 1);
digitalWrite(4, 1);
digitalWrite(5, 0);
digitalWrite(6, 0);
digitalWrite(7, 0);
digitalWrite(8, 0);
54
delay(1000);
// write '0'
digitalWrite(2, 1);
digitalWrite(3, 1);
digitalWrite(4, 1);
digitalWrite(5, 1);
digitalWrite(6, 1);
digitalWrite(7, 1);
digitalWrite(8, 0);
delay(4000);
}
Guide Questions:
3. What do you think is the purpose of the 220 ohm resistor connected from a Arduino outputs to the
Seven-segment display.
Answer:
___________________________________________________________________________________ __
___________________________________________________________________________________
_____________________________________________________________________________________
Review Questions:
1. What is the difference between the void setup() and void loop() sections in an Arduino sketch?.
Answer:
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
2. In the source code, how does the seven segment displays a number?
Answer:
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
3. What are the two types of a Seven-segment? Differentiate each other.
Answer:
55
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
Challenge Yourself:
1. Program a Arduino microcontroller such that the Seven-segment display is capable of showing a
number from 0 up to 9 and also your student ID number. Present your output to your instructor if done.
Conclusion:
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
______________________________________________________________________________
56