Arduino 7 Segment Display Counter

841

8

7

Published

Introduction: Arduino 7 Segment Display Counter

About: I am an elementary school student and I am passionate about Science and Math. I want to share what I learn with other kids and people from around the world.

Hi there!

My name is Shaya and I'm a 3rd grade student and my brother Loch who is in first grade, love electronics!

We will be working on different projects every week and sharing them with you.

We have included the source code as an attachment for you to download - see later in this document

Check it out in a video here Youtube Video

In this project, I will show you how to design a countdown counter using a 1 digit 7 segment display and an active buzzer.

Here are the components you need

  1. 1 x Arduino Mega 2560
  2. 1 x Active Buzzer
  3. 2 x 220 Ohm resistors (red, red, brown)
  4. 1 x 100 Ohm resistor (brown, black, brown)
  5. 1 x 1 digit 7 segment digital counter
  6. 1 x Bread board
  7. Several wires

Step 1: The 7 Segment Wires and Pin Numbers

How to connect to the display to the Arduino board

In the diagram above, you will see the letter assignment for every segment of the digital display, this is useful when writing the code.

The wire numbers of the Display (see above) will help you connect the pins correctly to the board. You can use the attached diagram below to connect the digital display to the Arduino Board.

Digital Display Pin to Arduino Pin

Pin 1 to 6

Pin 2 to 5

Pin 3 to GND (via 220 Ohm resistor)

Pin 4 to 4

Pin 5 to Nowhere

Pin 6 to 9

Pin 7 to 8

Pin 8 to GND (via 220 Ohm resistor)

Pin 9 to 2

Pin 10 to 3

How to connect to the active buzzer to the Arduino board

Anode on buzzer via 100 Ohm resistor to pin 13 on Arduino

Cathode to GND on breadboard

Needless to say, you need to connect the +5V and GND pins on the Arduino to the breadboard.

Step 2: The Wiring Diagram

This is a wiring diagram for visual aid. I hope it makes it easier for you!

Step 3: Finally, the Code...

// PWM Pins are connected to the 7 segments of the display. 
const int buzzer = 13; //buzzer to arduino pin 13
int pinA = 8;
int pinB = 9;
int pinC = 4;
int pinD = 5;
int pinE = 6;
int pinF = 2;
int pinG = 3;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pins as outputs.
pinMode(buzzer, OUTPUT); // Set buzzer to pin 13
pinMode(pinA, OUTPUT);
pinMode(pinB, OUTPUT);
pinMode(pinC, OUTPUT);
pinMode(pinD, OUTPUT);
pinMode(pinE, OUTPUT);
pinMode(pinF, OUTPUT);
pinMode(pinG, OUTPUT);
//This block of code starts countdown from 9 to 0. With every changing digit, you hear a small beep
//9
digitalWrite(pinA, HIGH);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, LOW);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
tone(buzzer,1000); // Send 1KHz sound.
delay(100);        // wait for 100 msec
noTone(buzzer);     // Stop sound...
delay(900);        // wait for for 900 msec
//8
digitalWrite(pinA, HIGH);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
tone(buzzer,1000); // Send 1KHz sound.
delay(100);        // wait for 100 msec
noTone(buzzer);     // Stop sound...
delay(900);        // wait for for 900 msec
//7
digitalWrite(pinA, HIGH);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
tone(buzzer,1000); // Send 1KHz sound.
delay(100);        // wait for 100 msec
noTone(buzzer);     // Stop sound...
delay(900);        // wait for for 900 msec
//6
digitalWrite(pinA, HIGH);
digitalWrite(pinB, LOW);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
tone(buzzer,1000); // Send 1KHz sound.
delay(100);        // wait for 100 msec
noTone(buzzer);     // Stop sound...
delay(900);        // wait for for 900 msec
//5
digitalWrite(pinA, HIGH);
digitalWrite(pinB, LOW);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, LOW);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
tone(buzzer,1000); // Send 1KHz sound.
delay(100);        // wait for 100 msec
noTone(buzzer);     // Stop sound...
delay(900);        // wait for for 900 msec
//4
digitalWrite(pinA, LOW);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
tone(buzzer,1000); // Send 1KHz sound.
delay(100);        // wait for 100 msec
noTone(buzzer);     // Stop sound...
delay(900);        // wait for for 900 msec
//3
digitalWrite(pinA, HIGH);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, HIGH);
tone(buzzer,1000); // Send 1KHz sound.
delay(100);        // wait for 100 msec
noTone(buzzer);     // Stop sound...
delay(900);        // wait for for 900 msec
//2
digitalWrite(pinA, HIGH);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, LOW);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, LOW);
digitalWrite(pinG, HIGH);
tone(buzzer,1000); // Send 1KHz sound.
delay(100);        // wait for 100 msec
noTone(buzzer);     // Stop sound...
delay(900);        // wait for for 900 msec
//1
digitalWrite(pinA, LOW);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
tone(buzzer,1000); // Send 1KHz sound.
delay(100);        // wait for 100 msec
noTone(buzzer);     // Stop sound...
delay(900);        // wait for for 900 msec
//0
digitalWrite(pinA, HIGH);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, LOW);
tone(buzzer,1000); // Send 1KHz sound.
delay(100);        // wait for 100 msec
noTone(buzzer);     // Stop sound...
delay(900);        // wait for for 900 msec
//This block sounds a longer beep to announce the end of the countdown
tone(buzzer,10); // Send 10Hz sound 
delay(1000);        // wait 1 sec
noTone(buzzer);     // Stop sound..
}  
// the loop routine runs over and over again forever:
void loop() {
}

Share

    Recommendations

    • Make it Move Contest

      Make it Move Contest
    • Woodworking Contest

      Woodworking Contest
    • Microcontroller Contest

      Microcontroller Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    7 Comments

    You know u could have done it using an array and by iterating through its values

    1 reply

    Hi Ashish, thank you for writing to me. I will learn more about arrays, it's new to me.

    Keep up the good work!!

    Hi everybody, I just added a link to the youtube video for this project in the introduction step in this article. I hope you find it helpful! It's cool to see the counter in action.

    Please like the video and subscribe to my channel for more videos coming soon!!

    Thanks for the tip DIY! I just entered the contest :)