Skip to main content

How to use 7 segment Display


Digit - LED Display


Introduction 

Picture

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.

About the Seven Segment Display

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

What you will need - Hardware

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

The Circuit

Picture
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")

The code ::

Picture
Here's the code,
  • 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
**************************************************************************
/* Arduino Tutorial - 7 Segment 
   One 7 segment is one digit, from 0 to  9.
*/

//Library
#include "SevenSeg.h"

//Defines the segments A-G: SevenSeg(A, B, C, D, E, F, G);
SevenSeg disp (10,9,8,7,6,11,12);
//Number of 7 segments
const int numOfDigits =1;
//CC(or CA) pins of segment
int digitPins [numOfDigits]={4};

//Variables
int number=0; //Default number
int flag;

void setup() {
  Serial.begin(9600);
  //Defines the number of digits to be "numOfDigits" and the digit pins to be the elements of the array "digitPins"
  disp.setDigitPins ( numOfDigits , digitPins );
  //Only for common cathode 7segments
  disp.setCommonCathode();
  //Control brightness (values 0-100);
  disp.setDutyCycle(50);
  
}

void loop()
{
//Check if incoming data is available:
    if (Serial.available() > 0)
    {
      // If it is, we'll use parseInt() to pull out only numbers:
      number = Serial.parseInt();
      flag=0;
    }

//Valid range is from 1 to 9
if (number>=1 && number<=9){
//Print number to 7 segment display
disp.writeDigit(number);
   //Print message to serial monito only once
   if (flag==0){ 
    //Print number to serial monitor
    Serial.print("Number on 7 segment display:");
    Serial.println(number);
    flag=1;
   }
}
}

**************************************************************************

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.

Well done!

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

Comments

Popular posts from this blog

Build Your Own Arduino Weather Station

Arduino ​Obstacle Avoiding Robot Ardunio Computer

Complete Guide for Nokia 5110 LCD with Arduino