Arduino 7 Segment Display Counter

by Shayan09 in Circuits > Arduino

8018 Views, 14 Favorites, 0 Comments

Arduino 7 Segment Display Counter

pic1.jpg

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

The 7 Segment Wires and Pin Numbers

Blank Diagram - Page 1-2.png

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.

The Wiring Diagram

1-digit 7 segment counter_bb.png

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

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() {
}