Introduction: 7 Segment Display on Arduino

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();
 }
}

Comments

author
DarthV14 made it!(author)2017-04-21

Why resistors before GND?

author
CHRISTO+CJ made it!(author)2017-07-11

to save the arduino pins from overload

author
AnaviD made it!(author)2016-09-29

What's the ! mark after digit mean?

author
ScottyM10 made it!(author)2017-05-31

! is like saying not.

!= means 'not equal'

author
BilalS14 made it!(author)2017-02-25

Alhamdulillah .... :)

IMG-20170225-WA0006.jpeg
author
NicholasR67 made it!(author)2016-10-15

Works!

Photo on 10-16-16 at 12.29 AM.jpg
author
sbyas made it!(author)2014-05-16

Doesn't work correctly. could you tell me why.

author
SherMarri made it!(author)2014-05-17

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

author
ishan+udyoga made it!(author)2014-06-24

me 2 bro.. not work correctly.. fix this if u can.

author
PaulA24 made it!(author)2015-08-09

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.

author
RomeliiA made it!(author)2016-10-12

5 star bro ! your the man!

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

author
ajmifaz made it!(author)2015-07-25

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.
author
ssarwar made it!(author)2016-01-26

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

author
Electronics_Creator made it!(author)2015-10-06

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

author
ajmifaz made it!(author)2015-07-25

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.
author
ktrantham made it!(author)2014-09-30

HERE IS THE FIX!!!!!!!!!!!!!!!!!!! the code is defunct now due to newer IDE versions: to fix the code change in the line of Void Loop

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

remove int after for(i=0;i<10;i++) < should look like this

and in the same Void loop add this line before the if statement

int 1;

so it should look like :

void loop()

{

int i;

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

{

DONE

author
mohammed+breky made it!(author)2016-06-22

thanks its work

i doit in proteus

7 seg.PNG
author
functionaldesign made it!(author)2016-04-21

Took me a while to figure out I had a common anode display and that the instructable was made for a common cathode display. If you have a common anode display, change the Ground jumper wire on the arduino to the 3V or 5V pins and things will be more interesting.

7 Segment Display On Arduino.jpg
author
aidanm19 made it!(author)2016-04-12

Where is the code for this?

author
IbarLikesFire made it!(author)2016-02-04

wow couldnt beliwvbe it whgewnb i saw i vy is di it!

imgres.jpg
author
1Wally made it!(author)2016-01-23

Worked fine

Thank-you for sharing

author
MagnusH3 made it!(author)2015-10-26

The reason it does'nt work is because Arduino pin 1 and 7 is not used, correct code :

{
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
}

And yes, I made it but don't have an image :D

author
Herr+Scientisto made it!(author)2015-08-16

doesnt work correctly! could you tell me why?

code is accepted but there has been an error

author
smithphyo made it!(author)2015-08-06

The code is written for Common Cathode 7 segment LED so if you are
using Common Anode one, just exchange "HIGH' & "LOW" in codes. for
example, Common Cathode 7 segment LED pin 3 & 8 are connected to
GROUND so we need to make respective pin to go HIGH then the related
segment will be on. But Common Anode will be opposite. so 7 segment pin 3
& 8 should be connected to 5V supply then respective pin has to be
in "LOW" so that related segment will be on. I believe it is the only
thing causing some of yours program not working.

7 Segment.jpg
author
nfarrow made it!(author)2015-07-29
author
ajmifaz made it!(author)2015-07-25

Connections which is in the description is wrong.

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

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.
photo1355.jpg
author
king.of.winterfell made it!(author)2015-02-18

doesn't work and when i change the code nothing happened and the connections in the picture aren't the same in the writting or the numbering were wrong

author
ajmifaz made it!(author)2015-07-25

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.
author
navneet+kaur made it!(author)2015-02-23

It doesn't work...the connections done in circuit diagram and those given in description are different...which one is correct? The code works fine with the changes given in the comments.. can u tell me where lies the flaw?

author
ajmifaz made it!(author)2015-07-25

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.
author
cristianoab made it!(author)2015-05-29

Works

IMG_20150529_224939.jpg
author
navneet+kaur made it!(author)2015-02-23

It doesn't work...the connections done in circuit diagram and those given in description are different...which one is correct? The code works fine with the changes given in the comments.. can u tell me where lies the flaw?

author
navneet+kaur made it!(author)2015-02-23

It doesn't work...the connections done in circuit diagram and those given in description are different...which one is correct? The code works fine with the changes given in the comments.. can u tell me where lies the flaw?

author
just+for+rate made it!(author)2015-02-02

thank you a lot this works 100% with me :) :)

author
ktrantham made it!(author)2014-09-30

HERE IS THE FIX!!!!!!!!!!!!!!!!!!! the code is defunct now due to newer IDE versions: to fix the code change in the line of Void Loop

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

remove int after for(i=0;i<10;i++) < should look like this

and in the same Void loop add this line before the if statement

int 1;

so it should look like :

void loop()

{

int i;

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

{

DONE

author
ktrantham made it!(author)2014-09-29

Code is defunct can you fix or identify problems in all if statements compile reports errors with all if"s

author
sbyas made it!(author)2014-07-08

I do but when I turned the Arduino on then the 7 segment display was flashing on and off the letters.

author
craftclarity made it!(author)2014-05-14

Looks like it's all there....

About This Instructable

120,514views

59favorites

License:

More by SherMarri:7 Segment Display On Arduino
Add instructable to: