Electronic Project 32: A simple guide on how to make a single digit counter 0-9 using a common anode seven segment display

in utopian-io •  7 years ago  (edited)

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

image.png

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.

image.png

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.

image.png

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.

image.png

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

image.png

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.

image.png

Since we use the common anode seven segment display, we will connect it to the ground using the resistor as you can see below.

image.png

Now this is our final circuit diagram.

image.png

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.

image.png

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.

image.png

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.

image.png

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.

image.png

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.

image.png

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

image.png

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.

image.png

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.

image.png

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.

image.png

Part II. Code

Now let us do programming of our Arduino uno.
Click on code to start.

image.png

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

image.png

int count = 0;  //initial counter 0 to 9

image.png

void setup(){
for(int x =2; x<9; x++) 
{ 
pinMode(x, OUTPUT); //output pin from pin 2 – pin 8
}
}

image.png

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;

image.png

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;

image.png

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;

image.png

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;

image.png

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;

image.png

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
}
}

image.png

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.

image.png

Arrange each component in the breadboard before connecting.

image.png

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

image.png

Application
The readers can create their own counter using seven segment display like the example below.

link source

Curriculum

Here are my other tutorials for electronic projects.

ELECTRONIC PROJECTS

Tutorial 1

Tutorial 2

Tutorial 3

Tutorial 4

Tutorial 5

Tutorial 6

Tutorial 7

Tutorial 8

Tutorial 9

Tutorial 10

Tutorial 11

Tutorial 12

Tutorial 13

Tutorial 14

Tutorial 15

Tutorial 16

Tutorial 17

Tutorial 18

Tutorial 19

Tutorial 20

Tutorial 21

Tutorial 22

Tutorial 24

Tutorial 25

Tutorial 26

Tutorial 27

Tutorial 28

Tutorial 29

Tutorial 30

Tutorial 31



Posted on Utopian.io - Rewarding Open Source Contributors

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

thanks @cha0s0000

Hey @rfece143 I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

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