7 Segment Display on Arduino

187,853

63

36

This instructable shows how to display 0-9 digits on 7 Segment Display using Arduino.

What do you need:

  • Arduino Uno 3
  • 7 Seven Segment Display
  • 2 x 220 Ohm Resistors
  • Jumper Wires

Step 1: Making Connections

Connect the pins described below:

  1. Arduino Pin 2 to Pin 9.
  2. Arduino Pin 3 to Pin 10.
  3. Arduino Pin 4 to Pin 4.

  4. Arduino Pin 5 to Pin 2..

  5. Arduino Pin 6 to Pin 1.

  6. Arduino Pin 8 to Pin 7.

  7. Arduino Pin 9 to Pin 6.

  8. GND to Pin 3 and Pin 8 each connected with 220 ohm resistors.

Step 2: Arduino Code

int a = 2;  //For displaying segment "a"
int b = 3;  //For displaying segment "b"
int c = 4;  //For displaying segment "c"
int d = 5;  //For displaying segment "d"
int e = 6;  //For displaying segment "e"
int f = 8;  //For displaying segment "f"
int g = 9;  //For displaying segment "g"
void setup() {               
  pinMode(a, OUTPUT);  //A
  pinMode(b, OUTPUT);  //B
  pinMode(c, OUTPUT);  //C
  pinMode(d, OUTPUT);  //D
  pinMode(e, OUTPUT);  //E
  pinMode(f, OUTPUT);  //F
  pinMode(g, OUTPUT);  //G
}
void displayDigit(int digit)
{
 //Conditions for displaying segment a
 if(digit!=1 && digit != 4)
 digitalWrite(a,HIGH);
 
 //Conditions for displaying segment b
 if(digit != 5 && digit != 6)
 digitalWrite(b,HIGH);
 
 //Conditions for displaying segment c
 if(digit !=2)
 digitalWrite(c,HIGH);
 
 //Conditions for displaying segment d
 if(digit != 1 && digit !=4 && digit !=7)
 digitalWrite(d,HIGH);
 
 //Conditions for displaying segment e 
 if(digit == 2 || digit ==6 || digit == 8 || digit==0)
 digitalWrite(e,HIGH);
 
 //Conditions for displaying segment f
 if(digit != 1 && digit !=2 && digit!=3 && digit !=7)
 digitalWrite(f,HIGH);
 if (digit!=0 && digit!=1 && digit !=7)
 digitalWrite(g,HIGH);
 
}
void turnOff()
{
  digitalWrite(a,LOW);
  digitalWrite(b,LOW);
  digitalWrite(c,LOW);
  digitalWrite(d,LOW);
  digitalWrite(e,LOW);
  digitalWrite(f,LOW);
  digitalWrite(g,LOW);
}


void loop() {
 for(int i=0;i<10;i++)
 {
   displayDigit(i);
   delay(1000);
   turnOff();
 }
}

15 People Made This Project!

Recommendations

  • Big and Small Contest

    Big and Small Contest
  • Toys Contest

    Toys Contest
  • Make it Glow Contest 2018

    Make it Glow Contest 2018

36 Discussions

0
None
GeirG1

7 weeks ago

Thanks for nice instructions! Here is how I would code it:

const int numberPins[] = { 9, 8, 6, 5, 4, 3, 2 };
void setup() {
for(int i = 0; i < 7; i++)
pinMode(numberPins[i], OUTPUT);
turnOff();
}
void displayDigit(int digit)
{
static byte numbers[] = { 95, 18, 47, 59, 114, 121, 125, 19, 127, 123 };
byte mask = 1;
for(int pin = 0; pin < 7; pin++)
{
if(numbers[digit] & (1 << pin))
digitalWrite(numberPins[pin], HIGH);
else
digitalWrite(numberPins[pin], LOW);
mask = mask * 2;
}
}
void turnOff()
{
for(int i = 0; i < 7; i++)
digitalWrite(numberPins[i], LOW);
}
0
None
a-sacramento

4 months ago

If have two displays how I command the second display? Do you have a solution for that?

0
None
saurav_hackAnaviD

Reply 4 months ago

It means if the digit is not equal to. ('!') means not in programming language.

1
None
ScottyM10AnaviD

Reply 1 year ago

! is like saying not.

!= means 'not equal'

0
None
ViduraM1

6 months ago

its working great, better to configure the jumper wires as its in the fritzing diagram.

Thanks

0
None
gajesh123

11 months ago

How to run it?

0
None
JaromírI

11 months ago

This is an example only for "Common katode" , am i right?

0
None
SherMarrisbyas

Reply 4 years ago on Introduction

Confirm if you have exact same components? Have you made right connections? Copied all code?

0
None
PaulA24ishan udyoga

Reply 3 years ago on Introduction

Hey! Try to switch from GND to VCC. It worked for me. If you search for a datasheet or a pinout description you will notice that the 3 and 8 pins are connected to VCC not GND. Try this way...maybe it will work.

0
None
RomeliiAPaulA24

Reply 2 years ago

5 star bro ! your the man!

haha its works!! i owe you much for our project!
thanks a lot!

0
None
ajmifazishan udyoga

Reply 3 years ago on Introduction

Connections which is in the circuit diagram is the correct one.

Connections which is in the description is wrong
Correct description
Connect the pins described below:


  1. Arduino Pin 2 to Pin 7.
  2. Arduino Pin 3 to Pin 6.
  3. Arduino Pin 4 to Pin 4.
  4. Arduino Pin 5 to Pin 2.
  5. Arduino Pin 6 to Pin 1.
  6. Arduino Pin 8 to Pin 9.
  7. Arduino Pin 9 to Pin 10.
  8. GND to Pin 3 and Pin 8 each connected with 220 ohm resistors.
0
None
ssarwarajmifaz

Reply 2 years ago

thanks very much (y) ...at last it worked ....

0
None
Electronics_Creatorsbyas

Reply 3 years ago

maby you have a wrong 7 segment display maby it's a common cathode

0
None
ajmifazsbyas

Reply 3 years ago on Introduction

Connections which is in the circuit diagram is the correct one.

Connections which is in the description is wrong
Correct description
Connect the pins described below:


  1. Arduino Pin 2 to Pin 7.
  2. Arduino Pin 3 to Pin 6.
  3. Arduino Pin 4 to Pin 4.
  4. Arduino Pin 5 to Pin 2.
  5. Arduino Pin 6 to Pin 1.
  6. Arduino Pin 8 to Pin 9.
  7. Arduino Pin 9 to Pin 10.
  8. GND to Pin 3 and Pin 8 each connected with 220 ohm resistors.