PROJECT – 7 Segment Display
In this
tutorial you will learn how to use 7 Segment with Arduino and making a count
from 0 to 9.
STEP – 1 Components
Components
Required:-
1.
Arduino Uno
2.
Breadboard
3.
7 Segment
4.
Wires.
5.
Resistance.
6.
Slide Button.
STEP – 2: Circuit
The connections are pretty easy, see the image above with the breadboard circuit schematic. |
STEP – 3 : Code
int a = 7;
int b = 6;
int c = 4;
int d = 3;
int e = 2;
int f = 8;
int g = 9;
int dp = 5;
int Button = 10;
int num = 0;
void setup()
{
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
pinMode(dp, OUTPUT);
pinMode(Button,INPUT);
}
void loop()
{
if
(num == 0) {
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
digitalWrite(dp, HIGH);
} else
if (num == 1) {
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(dp, HIGH);
} else
if (num == 2) {
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
digitalWrite(dp, HIGH);
} else
if (num == 3) {
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
digitalWrite(dp, HIGH);
} else
if (num == 4) {
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(dp, HIGH);
} else
if (num == 5) {
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(dp, HIGH);
} else
if (num == 6) {
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(dp, HIGH);
} else
if (num == 7) {
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(dp, HIGH);
} else
if (num == 8) {
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(dp, HIGH);
} else
if (num == 9) {
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(dp, HIGH);
}
if
(digitalRead(Button) == HIGH) {
num++;
num
= num % 10;
delay(500);
}
} }
/* Copy above Code and Paste in Your Arduino
Sketch */
Step 4: Well Done!
You have successfully
completed one more Arduino Project and you learned how to use a 7 Segment
Display with Arduino.
THANKYOU!
Previous Project - 10 :- KeyPad By Using Arduino
Comments
Post a Comment