7Segment Interfacing using Arduino

ARDUINO Tutorial Series

7 segment interfacing

O..7SEG..Can you Display My Digits..?? 

 

Contributed By :- Vedant Patil

-----------------------------------------------------------

7segment basics

As its name suggests that it should consists of 7 segmented LEDs. This segments of LEDs arranged in a rectangular fashion as shown.

An additional 8th LED is used within the same package to indicating a decimal point.

 

7segment interfacing

As we already done it with LEDs “common cathode” and “common anode” modes of connections.

 

Let us discuss both modes:-

 

1. Commom cathode mode

In the common cathode display, all the cathode connections of the LED segments are joined together to logic “0” or ground. For a practical 7segment we connect the COM aur the middle one to the GND pin of the ARDUINO. We provide logic “1” to turn ON the particular segment.

 

2. Common anode mode

In the common anode display, all the anode connections of the LED segments are joined together to logic “1” or Vcc. For a practical 7segment we connect the COM or the middle one pin to the VCC pin of the ARDUINO. We provide logic “0” turn ON the particular segment.

 

NOTE:- We generally use common cathode mode.

 

Table for displaying numbers 0-9

 

dp

g

f

e

d

c

b

a

Hex code

0

0

0

1

1

1

1

1

1

0x3f

1

0

0

0

0

0

1

1

0

0x06

2

0

1

0

1

1

0

1

1

0x5b

3

0

1

0

0

1

1

1

1

0x4f

4

0

1

1

0

0

1

1

0

0x66

5

0

1

1

0

1

1

0

1

0x6d

6

0

1

1

1

1

1

0

1

0x7d

7

0

0

0

0

0

1

1

1

0x07

8

0

1

1

1

1

1

1

1

0x7f

9

0

1

1

0

1

1

1

1

0x6f

 

 

Write a program to display 0-9 on 7seg display with first 8 pins of ARDUINO UNO

int i,j=0;   //i and j declared as global variable

//declare an array for 0-9 digits

char mynum[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

void setup()

{

for(i=0;i<8;i++)

{

pinMode(i,1);          //declare pins 0-8 as output

}

}

void show(char a)  //create a new function show

{

char temp=0;          //define a character temp

for(j=0;j<8;j++)

{temp=(0x01)&(a>>j);

if(temp==1)                     

digitalWrite(j,1);   

else

digitalWrite(j,0);

}

}

void loop()

{

for(i=0;i<10;i++)

{

show (mynum[i]);  //show the ith number

delay(1000);           //delay for 1s

}

}

 

CLICK HERE TO VIEW / DOWNLOAD ARDUINO TRAINING SYLLABUS

 

CLICK HERE TO REGISTER NOW FOR ARDUINO TRAINING

 

Top