7-segment Display Using Arduino Uno R3 (2024)

Introduction: 7-segment Display Using Arduino Uno R3

By primerobotics

More by the author:

About: PrimeRobotics is a E-Commerce site, which focus on supplying right products to Electronics Hobbyists, Enthusiast & Students. More About primerobotics »

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.

Step 1: ​Components

Step 2: Principle

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.

Step 3: The Schematic Diagram

Step 4: ​Procedures:

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).

Step 1:

Build the circuit.

Step 2:

Download the code from https://github.com/primerobotics/Arduino

Step 3:

Upload the sketch to the Arduino Uno board

Click the Upload icon to upload the code to the control board.

If "Done uploading" appears at
the bottom of the window, it means the sketch has been successfully uploaded.

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

Step 5: Code

//7-Segment

Display

//You should nowsee the 7-segment display cycle from 0 to F

//Email:info@primerobotics.in

//Website:www.primerobotics.in

const int a=7; //aof 7-segment attach to digital pin 7

const int b=6; //bof 7-segment attach to digital pin 6

const int c=5; //cof 7-segment attach to digital pin 5

const int d=11;//dof 7-segment attach to digital pin 11

const int e=10;//eof 7-segment attach to digital pin 10

const int f=8;//fof 7-segment attach to digital pin 8

const int g=9;//gof 7-segment attach to digital pin 9

const intdp=4;//dp of 7-segment attach to digital pin 4

void setup()

{

//loop over thisPin from 4 to 11 and set themall to output

for(int thisPin = 4;thisPin <=11;thisPin++)

{

pinMode(thisPin,OUTPUT);

}

digitalWrite(dp,LOW);//turn the dp of the7-segment off

}

void loop()

{

digital_1();//diaplay 1 to the 7-segment

delay(1000);//wait for a second

digital_2();//diaplay 2 to the 7-segment

delay(1000); //wait for a second

digital_3();//diaplay 3 to the 7-segment

delay(1000); //wait for a second

digital_4();//diaplay 4 to the 7-segment

delay(1000); //wait for a second

digital_5();//diaplay 5 to the 7-segment

delay(1000); //wait for a second

digital_6();//diaplay 6 to the 7-segment

delay(1000); //wait for a second

digital_7();//diaplay 7 to the 7-segment

delay(1000); //wait for a second

digital_8();//diaplay 8 to the 7-segment

delay(1000); //wait for a second

digital_9();//diaplay 8 to the 7-segment

delay(1000); //wait for a second

digital_A();//diaplay 8 to the 7-segment

delay(1000); //wait for a second

digital_b();//diaplay 8 to the 7-segment

delay(1000); //wait for a second

digital_C();//diaplay 8 to the 7-segment

delay(1000); //wait for a second

digital_d();//diaplay 8 to the 7-segment

delay(1000); //wait for a second

digital_E();//diaplay 8 to the 7-segment

delay(1000); //wait for a second

digital_F();//diaplay 8 to the 7-segment

delay(1000); //wait for a second

}

void digital_1(void)//diaplay 1 to the 7-segment

{

digitalWrite(c,HIGH);//turn the c of the7-segment on

digitalWrite(b,HIGH);//turn the b of the7-segment on

for(int j = 7;j <= 11;j++)//turn off theothers

digitalWrite(j,LOW);

}

voiddigital_2(void) //diaplay 2 to the 7-segment

{

digitalWrite(b,HIGH);

digitalWrite(a,HIGH);

for(int j = 9;j <= 11;j++)

digitalWrite(j,HIGH);

digitalWrite(c,LOW);

digitalWrite(f,LOW);

}

voiddigital_3(void) //diaplay 3 to the 7-segment

{

unsigned char j;

digitalWrite(g,HIGH);

digitalWrite(d,HIGH);

for(j=5;j<=7;j++)

digitalWrite(j,HIGH);

digitalWrite(f,LOW);

digitalWrite(e,LOW);

}

voiddigital_4(void) //diaplay 4 to the 7-segment

{

digitalWrite(c,HIGH);

digitalWrite(b,HIGH);

digitalWrite(f,HIGH);

digitalWrite(g,HIGH);

digitalWrite(a,LOW);

digitalWrite(e,LOW);

digitalWrite(d,LOW);

}

voiddigital_5(void) //diaplay 5 to the 7-segment

{

unsigned char j;

for(j = 7;j <= 9;j++)

digitalWrite(j,HIGH);

digitalWrite(c,HIGH);

digitalWrite(d,HIGH);

digitalWrite(b,LOW);

digitalWrite(e,LOW);

}

voiddigital_6(void) //diaplay 6 to the 7-segment

{

unsigned char j;

for(j = 7;j <= 11;j++)

digitalWrite(j,HIGH);

digitalWrite(c,HIGH);

digitalWrite(b,LOW);

}

void digital_7(void)//diaplay 7 to the 7-segment

{

unsigned char j;

for(j = 5;j <= 7;j++)

digitalWrite(j,HIGH);

for(j = 8;j <= 11;j++)

digitalWrite(j,LOW);

}

voiddigital_8(void) //diaplay 8 to the 7-segment

{

unsigned char j;

for(j = 5;j <=11;j++)

digitalWrite(j,HIGH);

}

voiddigital_9(void) //diaplay 9 to the 7-segment

{

unsigned char j;

for(j = 5;j <=9;j++)

digitalWrite(j,HIGH);

digitalWrite(d,LOW);

digitalWrite(e,LOW);

}

voiddigital_A(void) //diaplay A to the 7-segment

{

unsigned char j;

for(j = 5;j <=10;j++)

digitalWrite(j,HIGH);

digitalWrite(d,LOW);

}

voiddigital_b(void) //diaplay b to the 7-segment

{

unsigned char j;

for(j = 7;j <=11;j++)

digitalWrite(j,HIGH);

digitalWrite(a,LOW);

digitalWrite(b,LOW);

}

voiddigital_C(void) //diaplay C to the 7-segment

{

digitalWrite(a,HIGH);

digitalWrite(b,LOW);

digitalWrite(c,LOW);

digitalWrite(d,HIGH);

digitalWrite(e,HIGH);

digitalWrite(f,HIGH);

digitalWrite(g,LOW);

}

voiddigital_d(void) //diaplay d to the 7-segment

{

unsigned char j;

digitalWrite(a,LOW);

digitalWrite(f,LOW);

digitalWrite(b,HIGH);

digitalWrite(c,HIGH);

digitalWrite(j,HIGH);

for(j = 9;j <=11;j++)

digitalWrite(j,HIGH);

}

voiddigital_E(void) //diaplay E to the 7-segment

{

unsigned char j;

digitalWrite(b,LOW);

digitalWrite(c,LOW);

for(j = 7;j <=11;j++)

digitalWrite(j,HIGH);

}

voiddigital_F(void) //diaplay F to the 7-segment

{

unsigned char j;

digitalWrite(b,LOW);

digitalWrite(c,LOW);

digitalWrite(d,LOW);

for(j = 7;j <=10;j++)

digitalWrite(j,HIGH);

}

Step 6: Code Analysis

7-segment Display Using Arduino Uno R3 (2024)
Top Articles
Latest Posts
Article information

Author: Mrs. Angelic Larkin

Last Updated:

Views: 5859

Rating: 4.7 / 5 (47 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Mrs. Angelic Larkin

Birthday: 1992-06-28

Address: Apt. 413 8275 Mueller Overpass, South Magnolia, IA 99527-6023

Phone: +6824704719725

Job: District Real-Estate Facilitator

Hobby: Letterboxing, Vacation, Poi, Homebrewing, Mountain biking, Slacklining, Cabaret

Introduction: My name is Mrs. Angelic Larkin, I am a cute, charming, funny, determined, inexpensive, joyous, cheerful person who loves writing and wants to share my knowledge and understanding with you.