Lesson 13 7-Segment Display

Share for us

Introduction

A 7-segment display is a device that can display numerals and letters. It’s made up of seven LEDs connected in parallel. Different letters/numbers can be shown by connecting pins on the display to the power source and enabling the related pins, thus turning on the corresponding LED segments. In this lesson let’s learn how to display specific characters on it.

Components

– 1 * SunFounder Uno board

– 1 * 7-segment display (Common Cathode)

– 8 * Resistor (220Ω)

– 1 * USB cable

– 1 * Breadboard

– Jumper wires

Principle

7-Segment Display

A 7-segment display is an 8-shaped component which packages 7 LEDs. Each LED is called a segment – when energized, one segment forms part of a numeral (both decimal and hexadecimal) 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 of the LEDs in the display is given a positional segment with one of its connection pins led out from the rectangular plastic package. These LED pins are labeled from “a” through to “g” representing each individual LED. The other LED pins are connected together forming a common pin. So by forward biasing the appropriate pins of the LED segments in a particular order, some segments will brighten and others stay dim, thus showing the corresponding character on the display.

The common pin of the display generally tells its type. There are two types of pin connection: a pin of connected cathodes and one of connected anodes, indicating Common Cathode (CC) and Common Anode (CA). As the name suggests, a CC display has all the cathodes of the 7 LEDs connected when a CA display has all the anodes of the 7 segments connected.

Common Cathode 7-Segment Display

In a common cathode display, the cathodes of all the LED segments are connected to the logic “0” or ground. Then an individual segment (a-g) is energized by a “HIGH”, or logic “1” signal via a current limiting resistor to forward bias the anode of the segment.

Common Anode 7-Segment Display

In a common anode display, the anodes of all the LED segments are connected to the logic “1”. Then an individual segment (a-g) is energized by a ground, logic “0” or “LOW” signal via a current limiting resistor to the cathode of the segment.

The schematic diagram

Principle: In this experiment, connect each of pin a-g of the 7-Segment Display to one 220ohm current limiting resistor respectively and then to pin 4–11. GND connects to GND. By programming, we can set one or several of pin4-11 as High level to light up the corresponding LED(s).

Experimental Procedures

Step 1: Build the circuit (here a common cathode 7-segment display is used)

The wiring between the 7-segment display and the SunFounder Uno board:

7-Segment DisplaySunFounder Uno Board
a7
b6
c5
d11
e10
f8
g9
dp4
“ – “GND

Step 2: Open the code file

Step 3: Select correct Board and Port

Step 4: Upload the sketch to the SunFounder Uno board

You should now see the 7-segment display from 0 to 9 and then A to F, back and forth.

First we need to know how it looks like when display the numeral 2 on the 7-Segment display. It’s actually the segments a, b, d, e and g are power on, which generates the display of 2. In programming, pins connected to these segments are set High level when c and f are Low level. Here we use a for() statement to set these pins as High level respectively (the braces after for() are deleted as there is only one line). Connect pin dp to pin 4; it’s already defined as LOW in setup().

After running this part, the 7-segment will display 2. Similarly, the display of other characters are the same. Since the letters b and d in upper case, namely B and D, would look the same with 8 and on the display, they are displayed in lower case instead.

Code

//7-Segment Display //You should now see the 7-segment display cycle from 0 to F //Email:support@sunfounder.com //Website:www.sunfounder.com //2015.5.7 const int a=7; //a of 7-segment attach to digital pin 7 const int b=6; //b of 7-segment attach to digital pin 6 const int c=5; //c of 7-segment attach to digital pin 5 const int d=11;//d of 7-segment attach to digital pin 11 const int e=10;//e of 7-segment attach to digital pin 10 const int f=8;//f of 7-segment attach to digital pin 8 const int g=9;//g of 7-segment attach to digital pin 9 const int dp=4;//dp of 7-segment attach to digital pin 4 void setup() { //loop over thisPin from 4 to 11 and set them all to output for(int thisPin = 4;thisPin