Single Digit Decimal counter using Arduino

Summary of Single Digit Decimal counter using Arduino


This tutorial guides beginners on how to use an Arduino to control a 7-segment display, automatically counting numbers from 1 to 9. It explains the hardware connections for a common anode 7-segment display and provides a sample Arduino program to light the appropriate segments for each digit. The project involves connecting the 7-segment display pins through resistors to Arduino digital pins and powering the display's common pins with +5V. The tutorial also mentions adjustments needed for a common cathode display.

Parts used in the 7-Segment Display Counter Project:

  • Arduino Uno
  • Breadboard
  • 7-segment display (common anode or cathode)
  • 220 ohm resistor (8 pieces)
  • Wires (at least 8 pieces)

“Hello world”,I am not going to start this blog with typical “Hello world” program,since lot of resources already covered Arduino way of telling “hello world”,that is Blinking a LED.

This project is absolutely for beginners who prefers to run than taking a walk,I am going to control 7 segment display to automatically count numbers from 1-9 using Arduino,well I hope you know the basics of 7 segment display.If not,don’t worry here is a concise tutorial about 7 segment display.

Single Digit Decimal counter

lets get started,Here is some components you need before proceeding

  1. Arduino (Uno will be cheap)
  2. Breadboard
  3. 7 segment display (common anode or cathode)
  4. 220ohm resistor – 8 pieces
  5. some wire stripes (at least 8 pieces)

In this tutorial I am going to build the project using common anode type 7 segment display but at the end of the post you can find program and schematic for common cathode also.

The connection is pretty simple,Just connect pin 1-10 (excluding 3,5,8) to series resistors.First short, pin 3 and 8 os seven segment display,which is to be connected with +5V pin on Arduino.Now connect other end of R1 with Arduino Digital pin 1,Here note that R1 is connected with the pin 1 of seven segment display.

Now similarly connect other series resistor pins to corresponding pins of Arduino.

Note that since we are not going to use pin 5,which is used to display a dot.Also the pin 3 and 8 are connected with 5V,So the corresponding Arduino pins 3 and 8 will also be not used.

If You want to change the pin configuration you need to modify the code as well.

Program :

In above code snippet I have defined seven constants which will be defined as INPUT or OUPUT port,later in the program(void setup()).

I have assigned a=7,since the In 7 segment display the segment ‘a’ is connected to pin ‘7’.You can vary this according to your wish but I did like this since you don’t need to remember anything while connecting Arduino pins and 7 segment display.Just connect pin 1 with Arduino pin 1,pin 2 with Arduino pin 2 and so on.

void LightLed(int n){  switch(n)  {    case 0:
    digitalWrite(a, LOW);
    digitalWrite(b, LOW);
    digitalWrite(c, LOW); 
    digitalWrite(d, LOW); 
    digitalWrite(e, LOW);
    digitalWrite(f, LOW);
    digitalWrite(g, HIGH);
    break;

        case 1:
    digitalWrite(a, HIGH);
    digitalWrite(b, LOW);
    digitalWrite(c, LOW); 
    digitalWrite(d, HIGH); 
    digitalWrite(e, HIGH);
    digitalWrite(f, HIGH);
    digitalWrite(g, HIGH);
    break;

        case 2:
    digitalWrite(a, LOW);
    digitalWrite(b, LOW);
    digitalWrite(c, HIGH); 
    digitalWrite(d, LOW); 
    digitalWrite(e, LOW);
    digitalWrite(f, HIGH);
    digitalWrite(g, LOW);
    break;
        case 3:
    digitalWrite(a, LOW);
    digitalWrite(b, LOW);
    digitalWrite(c, LOW); 
    digitalWrite(d, LOW); 
    digitalWrite(e, HIGH);
    digitalWrite(f, HIGH);
    digitalWrite(g, LOW);
    break;
Single Digit Decimal counter
        case 4:
    digitalWrite(a, HIGH);
    digitalWrite(b, LOW);
    digitalWrite(c, LOW); 
    digitalWrite(d, HIGH); 
    digitalWrite(e, HIGH);
    digitalWrite(f, LOW);
    digitalWrite(g, LOW);
    break;

        case 5:
    digitalWrite(a, LOW);
    digitalWrite(b, HIGH);
    digitalWrite(c, LOW); 
    digitalWrite(d, LOW); 
    digitalWrite(e, HIGH);
    digitalWrite(f, LOW);
    digitalWrite(g, LOW);
    break;

 

For more detail: Single Digit Decimal counter


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top