0% found this document useful (0 votes)
11 views

Arduino Activity 06 - Seven-Segment LED Count-Down Timer

The document outlines a beginner-level robotics training project at Our Own High School, Dubai, focused on creating a countdown timer using a seven-segment LED display and Arduino. It provides detailed instructions on the setup, wiring, and coding necessary to display a countdown from 9 to 0, including error handling for invalid inputs. The project emphasizes the importance of using a common-cathode LED and includes a main sketch for programming the timer functionality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Arduino Activity 06 - Seven-Segment LED Count-Down Timer

The document outlines a beginner-level robotics training project at Our Own High School, Dubai, focused on creating a countdown timer using a seven-segment LED display and Arduino. It provides detailed instructions on the setup, wiring, and coding necessary to display a countdown from 9 to 0, including error handling for invalid inputs. The project emphasizes the importance of using a common-cathode LED and includes a main sketch for programming the timer functionality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Our Own High School, Dubai

Dept. of RAISE
Robotics Training – Beginner Level 1 (Arduino)

Activity 06 – Seven-Segment LED Count-Down Timer


➢ In this project, you will create a simple timer that counts
down from 9 to 0.
➢ This can be used in any number of useful projects!

HOW IT WORKS:
A seven-segment LED display shows a single digit or character
using LED segments. Each segment is an individual LED, and by
controlling which segments are lit at any time, we can display
numeric values. We’re using a single-digit display in this
project, shown in Figure, but there are also two-, three-, four-
, and eight-digit variations available.

This project will create a simple timer to count down from 9 to 0. The seven-segment
LED has 10 pins. Seven pins control the seven LEDs that light up to form each digit,
and the eighth pin controls the decimal point.

The other two pins are the common-cathode (–) or common-anode (+) pins, which
add power to the project. Our seven-segment LED is a common cathode, meaning
one side of each LED needs to connect to the ground. It’s important to note that the
code will work only with a common-cathode LED. If you have a common-anode LED you want to use, check the
troubleshooting section at the end of this chapter before uploading the sketch. Each LED segment requires a resistor
to limit the current; otherwise, it will burn out. The pins are labeled with a letter, as shown in Figure 3-2. The
numbered pins control the segments as shown on the right. The Arduino creates the number by turning the LEDs
off or on in different combinations.

THE BUILD:

1. Place the seven-segment display on a breadboard as shown in


Figure, making sure the pins straddle either side of the center
break. Connect LED pins 3 and 8 to the GND rail. The seven-
segment LED pins should straddle the center break of the
breadboard.
2. Connect LED pins 1, 2, 4, 5, 6, 7, and 9 as shown in the following
table, remembering to insert a 220-ohm resistor between the
LED and the Arduino connection. It’s important that the resistors
straddle the center break on the breadboard, as shown in the
circuit diagram in Figure.

Arduino Training - Activities


Our Own High School, Dubai
Dept. of RAISE
Robotics Training – Beginner Level 1 (Arduino)

The Main Sketch:

// Define the LEDs to be lit to create a number


byte seven_seg_digits[10][7] = { { 1, 1, 1, 1, 1, 1, 0 }, // = 0
{ 0, 1, 1, 0, 0, 0, 0 }, // = 1
{ 1, 1, 0, 1, 1, 0, 1 }, // = 2
{ 1, 1, 1, 1, 0, 0, 1 }, // = 3
{ 0, 1, 1, 0, 0, 1, 1 }, // = 4
{ 1, 0, 1, 1, 0, 1, 1 }, // = 5
{ 1, 0, 1, 1, 1, 1, 1 }, // = 6
{ 1, 1, 1, 0, 0, 0, 0 }, // = 7
{ 1, 1, 1, 1, 1, 1, 1 }, // = 8
{ 1, 1, 1, 0, 0, 1, 1 } // = 9
};

// Set the seven-segment LED pins as output


void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
writeDot(0); // Start with the decimal point off
}

void writeDot(byte dot) {

Arduino Training - Activities


Our Own High School, Dubai
Dept. of RAISE
Robotics Training – Beginner Level 1 (Arduino)

digitalWrite(9, dot);
}

void sevenSegWrite(byte digit) {


byte pin = 2;
for (byte segCount = 0; segCount < 7; ++segCount) {
digitalWrite(pin, seven_seg_digits[digit][segCount]);
++pin;
}
}

void loop() {
for (byte count = 10; count > 0; --count) { // Start the countdown
delay(1000); // 1 second between each digit
sevenSegWrite(count - 1); // Counting down by 1
}
delay(4000);
}

Task 1:

1. Take input from serial monitor like 0, 1, 2, 3, … up to 9


2. Ignore the input other than the above and display the error message “Error: Enter only single digit”
3. Display it on the LED counter.

// Define the LEDs to be lit to create a number


byte seven_seg_digits[10][7] = { { 1, 1, 1, 1, 1, 1, 0 }, // = 0
{ 0, 1, 1, 0, 0, 0, 0 }, // = 1
{ 1, 1, 0, 1, 1, 0, 1 }, // = 2
{ 1, 1, 1, 1, 0, 0, 1 }, // = 3
{ 0, 1, 1, 0, 0, 1, 1 }, // = 4
{ 1, 0, 1, 1, 0, 1, 1 }, // = 5
{ 1, 0, 1, 1, 1, 1, 1 }, // = 6
{ 1, 1, 1, 0, 0, 0, 0 }, // = 7
{ 1, 1, 1, 1, 1, 1, 1 }, // = 8
{ 1, 1, 1, 0, 0, 1, 1 } // = 9
};
int digit;

// Set the seven-segment LED pins as output


void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);

Arduino Training - Activities


Our Own High School, Dubai
Dept. of RAISE
Robotics Training – Beginner Level 1 (Arduino)

pinMode(9, OUTPUT);
writeDot(0); // Start with the decimal point off
serial.begin(9600);
digit = 0;
}

void writeDot(byte dot) {


digitalWrite(9, dot);
}

void sevenSegWrite(byte digit) {


byte pin = 2;
for (byte segCount = 0; segCount < 7; ++segCount) {
digitalWrite(pin, seven_seg_digits[digit][segCount]);
++pin;
}
}

void loop() {

digit = serial.parseint();

if (digit >= 0 || digit <= 9) {


sevenSegWrite(digit);
delay(4000);
}
}

Arduino Training - Activities

You might also like