What Will I Learn?
At the end of this tutorial:
♦ The readers will be able to create a single digit counter using seven segment display and arduino uno
♦ The readers will be able to know how the circuit works.
♦ Learn to apply the circuit in the future electronic projects
Introduction
Today, we will create a simple single digit counter using the seven segment display and arduino uno. The counter will count from 0-9, and it will be displayed on the seven segment.
You can read more about seven segment display Here
Requirements
Electronic Components
♦ Arduino Uno
♦ Seven segment display (common anode)
♦ Resistor
♦ Breadboard
♦ Connecting wires
Software
♦ Fritzing application
Difficulty
♦ Intermediate
Tutorial Contents
Using the fritzing software, we will create our circuit diagram, arduino codes and prototype using the breadboard
Part I. Schematic Diagram
So first let us construct our circuit diagram.
Select the electronic components needed for the circuit in the fritzing library. We need 1 arduino uno, 1 seven segment display common anode and 1 resistor.
Arrange the components before constructing the circuit.
In arranging the components, place all the components for the input side (left side) of the arduino and the components for the output side (right side).
We have no input component; all we have is output components, seven segment displays and a resistor.
In connecting the seven segment, we will need 7 output pins from our microcontroller that will be connected in the seven segment pins. Cathode pin C of the seven segment will be connected to pin D4 of our arduino, cathode pin D to pin D5 and cathode pin E to D6 as you can see in the figure below
The cathode pin A to be connected to pin D2, cathode pin F to pin D7 and cathode pin G to pin D8 of our arduino.
Since we use the common anode seven segment display, we will connect it to the ground using the resistor as you can see below.
Now this is our final circuit diagram.
The cathode pin E is connected to output pin D6 of our arduino. When there is output signal from this pin, seven segment will display the corresponding led display.
The cathode pin D is connected to output pin D5 of our arduino. When there is an output signal from this pin, seven segment will display the corresponding led display.
The cathode pin C is connected to output pin D4 of our arduino. When there is an output signal from this pin, seven segment will display the corresponding led display.
The cathode pin G is connected to output pin D8 of our arduino. When this pin is HIGH, seven segment will display the corresponding led display.
The cathode pin F is connected to output pin D7 of our arduino. When this pin is HIGH, seven segment will display the corresponding led display.
The cathode pin A is connected to output pin D2 of our arduino. When this pin is HIGH, seven segment will display the corresponding led display
The cathode pin B is connected to output pin D3 of our arduino. When this pin is HIGH, seven segment will display the corresponding led display.
Since in this is a single digit counter, we cannot use the decimal point so we will remain this unconnected. We can use this pin in creating counter with decimal point.
The common anode is the negative or the ground terminal of the seven segment display, so we will connect this pin to the ground as you can see in the figure below.
Part II. Code
Now let us do programming of our Arduino uno.
Click on code to start.
Now let us define first the pin connection from the seven segment display to the pins from the arduino uno..
#define ssdA 2 //cathode A is connected to arduino pin 2
#define ssdB 3 //cathode B is connected to arduino pin 3
#define ssdC 4 //cathode C is connected to arduino pin 4
#define ssdD 5 //cathode D is connected to arduino pin 5
#define ssdE 6 //cathode E is connected to arduino pin 6
#define ssdF 7 //cathode F is connected to arduino pin 7
#define ssdG 8 //cathode G is connected to arduino pin 8
int count = 0; //initial counter 0 to 9
void setup(){
for(int x =2; x<9; x++)
{
pinMode(x, OUTPUT); //output pin from pin 2 – pin 8
}
}
void loop(){
switch (count)
{
Case 0: //Show “0” on display
// pin combination in displaying zero
digitalWrite(ssdA, HIGH);
digitalWrite(ssdB, HIGH);
digitalWrite(ssdC, HIGH);
digitalWrite(ssdD, HIGH);
digitalWrite(ssdE, HIGH);
digitalWrite(ssdF, HIGH);
digitalWrite(ssdG, LOW);
break;
Case 1: //Show “1” on display
// pin combination in displaying one
digitalWrite(ssdA, LOW);
digitalWrite(ssdB, HIGH);
digitalWrite(ssdC, HIGH);
digitalWrite(ssdD, LOW);
digitalWrite(ssdE, LOW);
digitalWrite(ssdF, LOW);
digitalWrite(ssdG, LOW);
break;
Case 2 : //Show “2” on display
// pin combination in displaying two
digitalWrite(ssdA, HIGH);
digitalWrite(ssdB, HIGH);
digitalWrite(ssdC, LOW);
digitalWrite(ssdD, HIGH);
digitalWrite(ssdE, HIGH);
digitalWrite(ssdF, LOW);
digitalWrite(ssdG, HIGH);
break;
Case 3 : //Show “3” on display
// pin combination in displaying three
digitalWrite(ssdA, HIGH);
digitalWrite(ssdB, HIGH);
digitalWrite(ssdC, HIGH);
digitalWrite(ssdD, HIGH);
digitalWrite(ssdE, LOW);
digitalWrite(ssdF, LOW);
digitalWrite(ssdG, HIGH);
break;
Case 4 : //Show “4” on display
// pin combination in displaying four
digitalWrite(ssdA, LOW);
digitalWrite(ssdB, HIGH);
digitalWrite(ssdC, HIGH);
digitalWrite(ssdD, LOW);
digitalWrite(ssdE, LOW);
digitalWrite(ssdF, HIGH);
digitalWrite(ssdG, HIGH);
break;
Case 5 : //Show “5” on display
// pin combination in displaying five
digitalWrite(ssdA, HIGH);
digitalWrite(ssdB, LOW);
digitalWrite(ssdC, HIGH);
digitalWrite(ssdD, HIGH);
digitalWrite(ssdE, LOW);
digitalWrite(ssdF, HIGH);
digitalWrite(ssdG, HIGH);
break;
Case 6 : //Show “6” on display
// pin combination in displaying six
digitalWrite(ssdA, HIGH);
digitalWrite(ssdB, LOW);
digitalWrite(ssdC, HIGH);
digitalWrite(ssdD, HIGH);
digitalWrite(ssdE, HIGH);
digitalWrite(ssdF, HIGH);
digitalWrite(ssdG, HIGH);
break;
Case 7 : //Show “7” on display
// pin combination in displaying seven
digitalWrite(ssdA, HIGH);
digitalWrite(ssdB, HIGH;
digitalWrite(ssdC, HIGH);
digitalWrite(ssdD, LOW);
digitalWrite(ssdE, LOW);
digitalWrite(ssdF, LOW);
digitalWrite(ssdG, LOW);
break;
Case 8 : //Show “8” on display
// pin combination in displaying eight
digitalWrite(ssdA, HIGH);
digitalWrite(ssdB, HIGH;
digitalWrite(ssdC, HIGH);
digitalWrite(ssdD, HIGH);
digitalWrite(ssdE, HIGH);
digitalWrite(ssdF, HIGH);
digitalWrite(ssdG, HIGH);
break;
Case 9 : //Show “9” on display
// pin combination in displaying nine
digitalWrite(ssdA, HIGH);
digitalWrite(ssdB, HIGH;
digitalWrite(ssdC, HIGH);
digitalWrite(ssdD, HIGH);
digitalWrite(ssdE, LOW);
digitalWrite(ssdF, HIGH);
digitalWrite(ssdG, HIGH);
break;
break;
}
If (count<10){
Count++;
delay(1000); //every second increment by 1
}
If (count == 10){
Count = 0; //reset to zero if counter reach to 10
Delay(1000); //1 second delay
}
}
Here are our arduino codes.
#define ssdA 2 //cathode A is connected to arduino pin 2
#define ssdB 3 //cathode B is connected to arduino pin 3
#define ssdC 4 //cathode C is connected to arduino pin 4
#define ssdD 5 //cathode D is connected to arduino pin 5
#define ssdE 6 //cathode E is connected to arduino pin 6
#define ssdF 7 //cathode F is connected to arduino pin 7
#define ssdG 8 //cathode G is connected to arduino pin 8
int count = 0; //initial counter 0 to 9
void setup(){
for(int x =2; x<9; x++)
{
pinMode(x, OUTPUT); //output pin from pin 2 – pin 8
}
}
void loop(){
switch (count)
{
Case 0: //Show “0” on display
digitalWrite(ssdA, HIGH);
digitalWrite(ssdB, HIGH);
digitalWrite(ssdC, HIGH);
digitalWrite(ssdD, HIGH);
digitalWrite(ssdE, HIGH);
digitalWrite(ssdF, HIGH);
digitalWrite(ssdG, LOW);
break;
Case : //Show “1” on display
digitalWrite(ssdA, LOW);
digitalWrite(ssdB, HIGH);
digitalWrite(ssdC, HIGH);
digitalWrite(ssdD, LOW);
digitalWrite(ssdE, LOW);
digitalWrite(ssdF, LOW);
digitalWrite(ssdG, LOW);
break;
Case 2 : //Show “2” on display
digitalWrite(ssdA, HIGH);
digitalWrite(ssdB, HIGH);
digitalWrite(ssdC, LOW);
digitalWrite(ssdD, HIGH);
digitalWrite(ssdE, HIGH);
digitalWrite(ssdF, LOW);
digitalWrite(ssdG, HIGH);
break;
Case 3 : //Show “3” on display
digitalWrite(ssdA, HIGH);
digitalWrite(ssdB, HIGH);
digitalWrite(ssdC, HIGH);
digitalWrite(ssdD, HIGH);
digitalWrite(ssdE, LOW);
digitalWrite(ssdF, LOW);
digitalWrite(ssdG, HIGH);
break;
Case 4 : //Show “4” on display
digitalWrite(ssdA, LOW);
digitalWrite(ssdB, HIGH);
digitalWrite(ssdC, HIGH);
digitalWrite(ssdD, LOW);
digitalWrite(ssdE, LOW);
digitalWrite(ssdF, HIGH);
digitalWrite(ssdG, HIGH);
break;
Case 5 : //Show “5” on display
digitalWrite(ssdA, HIGH);
digitalWrite(ssdB, LOW);
digitalWrite(ssdC, HIGH);
digitalWrite(ssdD, HIGH);
digitalWrite(ssdE, LOW);
digitalWrite(ssdF, HIGH);
digitalWrite(ssdG, HIGH);
break;
Case 6 : //Show “6” on display
digitalWrite(ssdA, HIGH);
digitalWrite(ssdB, LOW);
digitalWrite(ssdC, HIGH);
digitalWrite(ssdD, HIGH);
digitalWrite(ssdE, HIGH);
digitalWrite(ssdF, HIGH);
digitalWrite(ssdG, HIGH);
break;
Case 7 : //Show “7” on display
digitalWrite(ssdA, HIGH);
digitalWrite(ssdB, HIGH;
digitalWrite(ssdC, HIGH);
digitalWrite(ssdD, LOW);
digitalWrite(ssdE, LOW);
digitalWrite(ssdF, LOW);
digitalWrite(ssdG, LOW);
break;
Case 8 : //Show “8” on display
digitalWrite(ssdA, HIGH);
digitalWrite(ssdB, HIGH;
digitalWrite(ssdC, HIGH);
digitalWrite(ssdD, HIGH);
digitalWrite(ssdE, HIGH);
digitalWrite(ssdF, HIGH);
digitalWrite(ssdG, HIGH);
break;
Case 9 : //Show “9” on display
digitalWrite(ssdA, HIGH);
digitalWrite(ssdB, HIGH;
digitalWrite(ssdC, HIGH);
digitalWrite(ssdD, HIGH);
digitalWrite(ssdE, LOW);
digitalWrite(ssdF, HIGH);
digitalWrite(ssdG, HIGH);
break;
break;
}
if (count<10){
Count++;
delay(1000); //every second increment by 1
}
if (count == 10){
Count = 0; //reset to zero if counter reach to 10
delay(1000); //1 second delay
}
}
Part III. Breadboard
Click on the breadboard.
Arrange each component in the breadboard before connecting.
Now connect each component if you don’t know how to connect using breadboard just read my previous tutorial about how to construct a circuit in the breadboard
Application
The readers can create their own counter using seven segment display like the example below.
Curriculum
Here are my other tutorials for electronic projects.
ELECTRONIC PROJECTS
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
thanks @cha0s0000
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey @rfece143 I am @utopian-io. I have just upvoted you!
Achievements
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit