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:
- Arduino Pin 2 to Pin 9.
- Arduino Pin 3 to Pin 10.
Arduino Pin 4 to Pin 4.
Arduino Pin 5 to Pin 2..
Arduino Pin 6 to Pin 1.
Arduino Pin 8 to Pin 7.
Arduino Pin 9 to Pin 6.
GND to Pin 3 and Pin 8 each connected with 220 ohm resistors.
Attachments
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(); } }

Participated in the
Arduino Contest
24 People Made This Project!
- andreicool8 made it!
- yrmk made it!
- calyp_so made it!
- calyp_so made it!
- omarkberrow made it!
- RiccardoMasarin made it!
- mithilapansilu47 made it!
- Street Performer Popstep made it!
- VũC4 made it!
See 15 More
44 Comments
Question 1 year ago on Introduction
Connect 7-segments to Arduino board and write a program to show the following letters instead of numbers in the same sequence (O, A,C,E,F,H,I,L,P)
1 year ago on Step 2
Here you can watch my version of 7 segment indicator project:
https://positiveknight.com/arduino-project-4-countdown-on-indicator/
2 years ago
Hi, the pins 3 and 8 are connected inside. So you need to connect the ground only once with one resistor 220ohms. If you connect the pins 3 and 8 with two resistors 220ohms you get 110ohms (parallel)
2 years ago on Step 2
Wow I stuggled for 2 hours.
Problem solved.
Suggest
1. change the GND to VCC
2. Replace all the HIGH to LOW and the LOW to HIGH in code.
3. Pin numbers must be :
Arduino : Display
2 : 7
3 : 6
4 : 4
5 : 2
6 : 1
8 : 9
9 : 10
Hope this helps
Regards
Shanedon
Reply 2 years ago
Thanks!
this helped a lot. I w a s thinking of giving up on Seven Seg Display ; )
2 years ago on Step 2
Hello. For the first time here but did in the meanwhile a lot of small projects with clocks.
It seems that there is a fault with the pinlayout of the 7 seg single display. The pinnumbers from 1 to 5 are correct. The upper ones are reversed in the picture (not on the Fritzing picture). The correct upper pinnumbers are from left to right 6, 7, 8, 9, 10
Just now I saw that Shanedon made the correction. Maybe a good idea the correct the picture of the 7seg layout.
2 years ago
int a = 2;
int b = 3;
int c = 4;
int d = 5;
int e = 6;
int f = 9;
int g = 10;
void setup() {
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
}
void displayDigit(int digit)
{
if(digit!=1 && digit != 4)
digitalWrite(f,HIGH);
if(digit != 5 && digit != 6)
digitalWrite(g,HIGH);
if(digit !=2)
digitalWrite(c,HIGH);
if(digit != 1 && digit !=4 && digit !=7)
digitalWrite(d,HIGH);
if(digit == 2 || digit ==6 || digit == 8 || digit==0)
digitalWrite(e,HIGH);
if(digit != 1 && digit !=2 && digit!=3 && digit !=7)
digitalWrite(a,HIGH);
if (digit!=0 && digit!=1 && digit !=7)
digitalWrite(b,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();
}
}
Question 4 years ago on Introduction
What is the part number for the 7 seven segment display?
Answer 2 years ago
5161AS
3 years ago
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;
}
}
{
for(int i = 0; i < 7; i++)
digitalWrite(numberPins[i], LOW);
}
3 years ago
If have two displays how I command the second display? Do you have a solution for that?
5 years ago
What's the ! mark after digit mean?
Reply 3 years ago
It means if the digit is not equal to. ('!') means not in programming language.
Reply 4 years ago
! is like saying not.
!= means 'not equal'
4 years ago
its working great, better to configure the jumper wires as its in the fritzing diagram.
Thanks
4 years ago
How to run it?
4 years ago
This is an example only for "Common katode" , am i right?
5 years ago
Why resistors before GND?
Reply 4 years ago
to save the arduino pins from overload
8 years ago on Introduction
Doesn't work correctly. could you tell me why.