Display 0 to 9 on Seven segment display

To display 0 to 9 on seven segment we need same connection we made in previous topic. As we make function one() to display ‘1’(previous topic) same like that we will make function zero(), one(), two(), three(), four(), five(), six(), seven(), eight() and nine() to display 0,1,2,3,4,5,6,7,8,9. After making these functions we will call all function by 1 second delay (it is same like blinking led).

This is just for showing concept of 7 Segment working, It is highly recommended to use shift register concept to display on seven segment display.

display 0 to 9 on seven segment

Now connect as follows

Seven-Segment Arduino
A 2
B 3
C 4
D 5
E 6
F 7
G 8
CC GND
DP
Arduino Interfacing with Seven Segment
Circuit Diagram

PROGRAMMING CODE to DISPLAY 0 TO 9 ON SEVEN SEGMENT

#define del 1000
void setup() {
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(10, INPUT);

}

void loop() {
  // --This is comment-- Call all functions from zero() to nine()
  // We provide delay in functions
  zero() ;
  one();
  two() ;
  three();
  four();
  five();
  six();
  seven();
  eight();
  nine();
}

void zero() {
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(8, LOW);
  delay(del);
}

void one() {
  digitalWrite(2, LOW);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  delay(del);
}

void two() {
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(4, LOW);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, LOW);
  digitalWrite(8, HIGH);
  delay(del);
}

void three() {
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, HIGH);
  delay(del);
}

void four() {
  digitalWrite(2, LOW);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);
  delay(del);
}

void five() {
  digitalWrite(2, HIGH);
  digitalWrite(3, LOW);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, LOW);
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);
  delay(del);
}

void six() {
  digitalWrite(2, HIGH);
  digitalWrite(3, LOW);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);
  delay(del);
}

void seven() {
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  delay(del);
}

void eight() {
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);
  delay(del);
}

void nine() {
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, LOW);
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);
  delay(del);
}

Note: The steps above are just to show you how 7 Segment Led works. But it is Highly Recommended to use shift register concept to display on seven segment display (start with the data type “byte” if you didn’t read from this).

 

Read Next : HOW TO USE 7 SEGMENT USING SHIFT REGISTER

Leave a Reply

avatar
  Subscribe  
Notify of

Arduino Tutorials with Basic Electronics: CONTENT

Translate »