How to Use a 7 Segment Display w/ Arduino

7 segment display arduino uno how to use

In this tutorial, a guide on how to use a 7-segment display together with Arduino UNO will be presented. Also in this tutorial, we will have a simple assembly using the 7-segment display in Arduino UNO. The 7-segment display is a very interesting piece of hardware as it is one of the most practical ways to display numbers in an easy, economical and readable way.

The 7-segment display is a component still used for signalization at various levels, an example of which is the Kennedy Space Center’s countdown clock, which still uses the same 7-segment display since the launch of the Apollo rocket.

Arduino Uno

In order to understand a little more what an Arduino Uno is, I’ll do a brief description of it here. This is a microcontroller based on the Microchip ATmega328P and developed by Arduino.cc, it has a set of digital and analog pins with 14 of these digital ones, with 6 of them capable of performing PWM (Pulse-width modulation), as well as having 6 analog pins, you can check this in Figure 1.

Figure 1 – Arduino Uno pins (https://lobodarobotica.com/blog/arduino-uno-pinout/)

These boards can be powered via USB cable or by a 7 to 20 volt transformer, you can check more relevant technical specifications below in Table 1.

MicrocontrollerATmega168
Operating Voltage5V
Input Voltage (recommended)7 – 12V
Input Voltage (limits)6 – 20V
Digital I/O Pins14
Analog Input Pins6
DC Current per I/O Pin40 mA
DC Current for 3.3V Pin50 mA
Flash Memory32KB (ATmega328)
SRAM2 KB (ATmega328)
EEPROM1 KB (ATmega328)
Clock Speed16 MHz
Table 1 – Arduino UNO specifications

7-segment display

This hardware contains 8 LEDs (Light-emitting diode), each separated by segments defined as a, b, c, d, e, f, g and DP, as shown in Figure 2. When one of these LEDs is activated, numbers and/or letters can be formed, although this equipment is limited to numbers 0 to 9 and letters from A to F.

Note: You should pay attention to what type of display we are using, as there are two types: one where the cathode is the common one, that is, all segments are connected to a single negative pin; and in the others, the anode is the one that is common, that is, all segments are connected to a single positive pin.

Figure 2 – 7 segments display configurations

Parts Required

Building the Circuit

With what was described above, we can make the most diverse applications, in this case, we will make a small counter from “0 to 9” with 7-segment display using the Arduino Uno for this. To start we need the breadboard, where we will be connecting the 7-segment display, ensuring that each side that contains pins are separated (Figure 3). Now, using a jumper wire, we are going to connect pin 3 or 8 of the display to pin 5v of the Arduino, in this case of a common anode display (connect it to GND if the display is of common cathode).

The remaining pins can be connected to any Arduino digital pin. Not forgetting that between the connection to the Arduino and the display there must be a 220 ohm resistor, in order to limit the current, preventing it from burning out (usually each LED on the display consumes about 15 mA).

Note: in this tutorial, we will be using digital pins 2, 3, 4, 5, 6, 7, 8 and 9.

Figure 3 – Circuit

Code

Step 1: In this case, we will use the open-source IDE (integrated development environment) available by Arduino. If you haven’t installed it yet, you can download the latest version here: https://www.arduino.cc/en/Main/Donate

Step 2: After downloading, you should install it.

Step 3: Open the IDE and select your card in “Tools -> Card -> Card Manager…”.

Step 4: Select your COM port “Tools -> Port->…”.

Step 5: Now copy the code below to your Arduino IDE project and save it.

int segmentos[]={4,5,3,6,7,9,2,8};
void setup()
{
for(int i=0;i<8;i++)
pinMode(segmentos[i],OUTPUT);
}
void OutputDisplay(int numero)
{
int digitos[10][8]={
{HIGH,HIGH,HIGH,HIGH,HIGH,HIGH,LOW,LOW}, // 0
{LOW,HIGH,HIGH,LOW,LOW,LOW,LOW,LOW}, // 1
{HIGH,HIGH,LOW,HIGH,HIGH,LOW,HIGH,LOW}, // 2
{HIGH,HIGH,HIGH,HIGH,LOW,LOW,HIGH,LOW}, // 3
{LOW,HIGH,HIGH,LOW,LOW,HIGH,HIGH,LOW}, // 4
{HIGH,LOW,HIGH,HIGH,LOW,HIGH,HIGH,LOW}, // 5
{HIGH,LOW,HIGH,HIGH,HIGH,HIGH,HIGH,LOW}, // 6
{HIGH,HIGH,HIGH,LOW,LOW,LOW,LOW,LOW}, // 7
{HIGH,HIGH,HIGH,HIGH,HIGH,HIGH,HIGH,LOW}, // 8
{HIGH,HIGH,HIGH,HIGH,LOW,HIGH,HIGH,LOW}, // 9
};
for(int i=0;i<8;i++)
digitalWrite(segmentos[i],digitos[numero%10][i]);
}
void loop()
{
OutputDisplay(millis()/1000);
delay(1000);
}

Step 6: Connect your Arduino to PC using USB 2.0 Type A / B to USB cable and upload the code by pressing the upload button.

Endnotes

If you need more details about this tutorial just make a comment below that I will be available to help, hope you like the result. If you liked this tutorial, you can visit other works that have already been published on our site https://www.geekering.com/, besides that you can see in particular the posts published by me in https://www.geekering.com/author/jaimesilva/.

Leave a Reply

Your email address will not be published. Required fields are marked *