Create Arduino projects with your students.

Seven segment displays

7 segment display

Hardware required

  • Arduino Board
  • 7 Resistors (330 or 220 Ohms)
  • A seven segment display
  • Breadboard
  • Jumper wires

Theoretical concepts

Seven segment display scheme

A seven-segment display is one of the most widely used electronic devices for displaying numbers. Any scoreboard, digital clock, calculator, etc. uses this type of displays so recognized by anyone.
Seven segment displays have been used since the 1970s in electronics. Some displays of this type were made using vacuum tubes and fluorescent filaments. With the advent of LEDs in electronics, this type of circuit was widely used.
As you can see, this display has a series of contacts to control each of the segments and a common ground connection for all of them. Each segment is assigned a letter from A to G and the point is assigned the letters DP.
In our circuitry we are going to connect the ports of the arduino and the display as follows:

  • We connect port A to pin 2
  • We connect port B to pin 3
  • We connect port C to pin 4
  • We connect port D to pin 5
  • We connect port E to pin 6
  • We connect port F to pin 7
  • We connect port G to pin 8

 

In the code we have made each number independent with a separate function so that it is easier for the student to interpret it.
We have also included lines to turn on all the LEDs but commented the instructions that cause some LEDs not to light up to show the required number. In this way it is easier to know which LEDs must be turned on and which must be turned off to represent a number.

In this practice we use functions. Functions in C++, which is the language used by arduino, are very useful when we want to isolate a block of code that executes a specific operation.
Functions can take input values and return a value as output, but in this exercise it has not been necessary.

Code

 

#define A 2
#define B 3
#define C 4
#define D 5
#define E 6
#define F 7
#define G 8

void setup()
{
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(E, OUTPUT);
pinMode(F, OUTPUT);
pinMode(G, OUTPUT);
}

void loop()
{
cero();
delay(1000); // Wait for 1000 millisecond(s)
apaga();
delay(1000); // Wait for 1000 millisecond(s)

uno();
delay(1000); // Wait for 1000 millisecond(s)
apaga();
delay(1000); // Wait for 1000 millisecond(s)

dos();
delay(1000); // Wait for 1000 millisecond(s)
apaga();
delay(1000); // Wait for 1000 millisecond(s)

tres();
delay(1000); // Wait for 1000 millisecond(s)
apaga();
delay(1000); // Wait for 1000 millisecond(s)

cuatro();
delay(1000); // Wait for 1000 millisecond(s)
apaga();
delay(1000); // Wait for 1000 millisecond(s)

cinco();
delay(1000); // Wait for 1000 millisecond(s)
apaga();
delay(1000); // Wait for 1000 millisecond(s)

seis();
delay(1000); // Wait for 1000 millisecond(s)
apaga();
delay(1000); // Wait for 1000 millisecond(s)

siete();
delay(1000); // Wait for 1000 millisecond(s)
apaga();
delay(1000); // Wait for 1000 millisecond(s)

ocho();
delay(1000); // Wait for 1000 millisecond(s)
apaga();
delay(1000); // Wait for 1000 millisecond(s)

nueve();
delay(1000); // Wait for 1000 millisecond(s)
apaga();
delay(1000); // Wait for 1000 millisecond(s)

}
void cero(){
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
//digitalWrite(G, HIGH);
}
void uno(){
//digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
//digitalWrite(D, HIGH);
//digitalWrite(E, HIGH);
//digitalWrite(F, HIGH);
//digitalWrite(G, HIGH);
}
void dos(){
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
//digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
//digitalWrite(F, HIGH);
digitalWrite(G, HIGH);
}
void tres(){
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(G, HIGH);
}
void cuatro(){
//digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
//digitalWrite(D, HIGH);
//digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, HIGH);
}

void cinco(){
digitalWrite(A, HIGH);
//digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
//digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, HIGH);
}

void seis(){
digitalWrite(A, HIGH);
//digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, HIGH);
}

void siete(){
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
//digitalWrite(D, HIGH);
//digitalWrite(E, HIGH);
//digitalWrite(F, HIGH);
//digitalWrite(G, HIGH);
}

void ocho(){
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, HIGH);
}

void nueve(){
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
//digitalWrite(D, HIGH);
//digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, HIGH);
}

void apaga(){
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
}

The Demeter Project