Introduction: How to Use a Seven Segment Display - Arduino Tutorial

About: Arduino Tutorials by Team

A Seven Segment Display, 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.

In this tutorial you will learn how to use one 7 Segment Display with Arduino uno.

You will be able to print a number from 1 to 9 at the 7 segment display from the serial monitor.

Before we start, let's see more information about this type of display.

Step 1: About the Seven Segment Display

The 7 segment display consists of seven LEDs (hence its name) arranged in a rectangular fashion as shown (see first image above). Each of the seven LEDs is called a segment because when illuminated the segment forms part of a numerical digit (decimal numbers and some letters) to be displayed. An additional 8th LED (right corner) 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' (see second image above) representing each individual LED. The other LED pins are connected together and wired to form a common pin.

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 7 segment display called "common cathode - cc" and "common anode - ca" (see third image above).

In this tutorial we will use a common cathode 7 segment display.

Step 2: What You Will Need

For this project you will need:

  • Arduino uno
  • Breadboard
  • 7 Segment Display - common cathode

Optional, you will need 7x 220 Ohm resistors, one for each led.

Step 3: The Circuit

The connections are pretty easy, see the image above with the breadboard circuit schematic.

Pinout of 7 segment display:

  • 1 - "E" - Arduino pin 6
  • 2 - "D" - Arduino pin 7
  • 3 - "CC" - Arduino pin 4
  • 4 - "C" - Arduino pin 8
  • 5 - "DP" -
  • 6 - "B" - Arduino pin 9
  • 7 - "A" - Arduino pin 10
  • 8 - "CC" - Arduino pin 4
  • 9 - "F" - Arduino pin 11
  • 10 - "G" - Arduino pin 12

(if you want you can connect resistors to each pin - except "CC")

Step 4: The Code

Here's the code, embedded using codebender!

  • numOfDigits = 1 If we have two seven segment displays we will change this to "2".
  • digitPins [numOfDigits] = {4} If we have two seven segment displays, we have to add the second display CC pin to e.g. arduino pin 3, so we will change it to "{4, 3}".
  • disp.setDutyCycle(50) Control brightness of display - "50" is 50% of led brightness.
  • disp.writeDigit(number) Print a number from 0 to 9

Try downloading the codebender plugin and clicking on the Run on Arduino button to program your Arduino with this sketch. And that's it, you've programmed your Arduino board!

Press the "connect" button to start the serial communication with your board. You can send numbers from 1 to 9.

You can keep playing with that by clicking the "Edit" button and start making your own modifications to the code.
For example, try to change disp.writeDigit(number) "number" with letter "F" (or 'b', 'd', 'A','E').

You can find more info about "SevenSeg.h" library and more available functions here.

Step 5: Well Done

You have successfully completed one more Arduino "How to" tutorial and you learned how to use one Seven Segment Display with Arduino uno.

I hope you liked this, let me know in the comments.

There will be more of them, so make sure to click Follow button!