Note: ALL OSOYOO Products for Arduino are Third Party Board which is fully compatitable with Arduino

Authorized Online Retailers:

AMAZON
amzuk

Content

  1. Introduction
  2. Preparations
  3. About the 1 Digit 7 Segment LED Display
  4. Connection
  5. Upload Sketch
  6. Program Running Result

Introduction

In this project, we will show how to drive a single 7 segment LED display with an Osoyoo Basic board.

Preparations

Hardware

Software

About the 1 Digit 7 Segment LED Display

One digit seven segment displays are used in many embedded system and industrial applications where the range of outputs to be shown is known beforehand. Basic 1 digit seven segment display can show numbers from 0-9 and a few characters. 7 segment displays are of different types; especially they differ in the number of digits/character it can display. Basically a 7 segment display is a single unit, which can display only 1 digit or 1 character. More digits are displayed by multiplexing single unit 7 segment displays together to form 2 digit display, 3 digit display or 4 digit 7 segment display. Its quiet easy to interface Arduin and 7 Segment display together! Lets begin the tutorial.

A 7 segment display has many limitations, especially in the range of characters it can display.There are displays in market which are much more advanced than seven segment displays and can display almost every character in the alphabet. For example:- a 16×2 LCD – which can display almost all ASCII characters. You might think why 7 segment display still exist in market. Well, 7 segment displays are the cheapest option when it comes to display devices available in market. A single digit/character 7 segment display unit is available at 1/10th of the cost of a 16×2 LCD module.

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.

As shown in the following figure, the segment pins b and c set to “HIGH”.

           

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.

As shown in the following figure, the segment pins b and c set to “LOW”.

               

Note:

Even though many different types of 7 segment LED displays follow the above schematics, it is not guaranteed. The best way to know the connections is to obtain the datasheet for the LED display in use or to buzz it out by connecting power to each of the pins to see which lights up. If you don’t get the connections right, the circuit will not produce the output of showing numerals 0-9. So it is very important to know which pins are which.

Connection

In this experiment, connect each of pin A-G of the 7-Segment Display to one 200 ohm 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).

The wiring between the 7-segment display and the OSOYOO Basic board:

7-Segment Display

Osoyoo Basic Board

A

7

B

6

C

5

D

11

E

10

F

8

G

9

DP

4

Com

GND

Circuit Diagram

Upload Sketch

After above operations are completed, connect the board to your computer using the USB cable. The green power LED (labelled PWR) should go on. Load up the following sketch onto your board.

int a=7; 
int b=6; 
int c=5; 
int d=11; 
int e=10; 
int f=8; 
int g=9; 
int dp=4; 
//display number 1
void display1(void) 
{ 
    digitalWrite(b,HIGH);
    digitalWrite(c,HIGH);
} 
//display number2
void display2(void) 
{
    digitalWrite(a,HIGH);
    digitalWrite(b,HIGH);
    digitalWrite(g,HIGH);
  digitalWrite(e,HIGH);
    digitalWrite(d,HIGH);
} 
// display number3
void display3(void) 
{ 
    digitalWrite(a,HIGH);
    digitalWrite(b,HIGH);
    
  digitalWrite(c,HIGH);
    digitalWrite(d,HIGH);
    digitalWrite(g,HIGH);
} 
// display number4
void display4(void) 
{ 
    digitalWrite(f,HIGH);
    digitalWrite(b,HIGH);
    digitalWrite(g,HIGH);
  digitalWrite(c,HIGH);
  
} 
// display number5
void display5(void) 
{ 
    digitalWrite(a,HIGH);
    digitalWrite(f,HIGH);
    digitalWrite(g,HIGH);
  digitalWrite(c,HIGH);
    digitalWrite(d,HIGH);
} 
// display number6
void display6(void) 
{ 
    digitalWrite(a,HIGH);
    digitalWrite(f,HIGH);
    digitalWrite(g,HIGH);
  digitalWrite(c,HIGH);
    digitalWrite(d,HIGH);  
    digitalWrite(e,HIGH);  
} 
// display number7
void display7(void) 
{   
   digitalWrite(a,HIGH);
    digitalWrite(b,HIGH);
    digitalWrite(c,HIGH);
} 
// display number8
void display8(void) 
{ 
    digitalWrite(a,HIGH);
    digitalWrite(b,HIGH);
    digitalWrite(g,HIGH);
  digitalWrite(c,HIGH);
    digitalWrite(d,HIGH);  
    digitalWrite(e,HIGH);  
  digitalWrite(f,HIGH);  
} 
void clearDisplay(void) 
{ 
    digitalWrite(a,LOW);
    digitalWrite(b,LOW);
    digitalWrite(g,LOW);
  digitalWrite(c,LOW);
    digitalWrite(d,LOW);  
    digitalWrite(e,LOW);  
  digitalWrite(f,LOW);  
} 
void display9(void) 
{ 
    digitalWrite(a,HIGH);
    digitalWrite(b,HIGH);
    digitalWrite(g,HIGH);
  digitalWrite(c,HIGH);
    digitalWrite(d,HIGH);  
  digitalWrite(f,HIGH);  
} 
void display0(void) 
{ 
    digitalWrite(a,HIGH);
    digitalWrite(b,HIGH);
  digitalWrite(c,HIGH);
    digitalWrite(d,HIGH);  
    digitalWrite(e,HIGH);  
  digitalWrite(f,HIGH);  
} 
void setup() 
{ 
    int i;
    for(i=4;i<=11;i++) 
        pinMode(i,OUTPUT);
} 
void loop() 
{     
    while(1) 
    {   clearDisplay();
  display0(); 
        delay(2000); 
        clearDisplay();
        display1(); 
        delay(2000); 
        clearDisplay();
        display2(); 
        delay(2000); 
        clearDisplay();
        display3(); 
        delay(2000);
        clearDisplay();
        display4(); 
        delay(2000);
        clearDisplay(); 
        display5(); 
        delay(2000);
        clearDisplay(); 
        display6(); 
        delay(2000);
        clearDisplay(); 
        display7(); 
        delay(2000); 
        clearDisplay();
        display8(); 
        delay(2000); 
        clearDisplay();  
        display9(); 
        delay(2000);      
    }
}

Running Result

A few seconds after the upload finishes, you should now see the 7-segment display from 0 to 9.