ARDUINO
PROJECT – SEVEN SEGMENT DISPLAY COUNTING

 

 

PROJECT DESCRIPTION

 

You will connect your Arduino to a seven segment display and have numbers 0 through 9 get displayed changing every second.

 

LESSONS

 

You should have looked at all lessons up to and including Lesson 5 before starting this project.  You should also have used a seven segment display before.

 

WARNING: If you do not know how to connect your seven segment display, you will destroy it.  You need a resistor connect to either one of the CA pins.  Leave the other CA pin open.

 

STEPS

 

1-Place your seven segment display on a breadboard.  You probably want to place it to the end that will be close to your Arduino.

 

2-Connect your Arduino’s 5V and GND pins to the positive and negative rail of your breadboard.

 

3-Connect one of the CA pins to the positive rail.

 

4-Connect pin a to pin 2, pin b to pin 3, pin c to pin 4 and so on until pin g is connected to pin 8.

 

5-It is now time to code.  Open your Arduino IDE.

 

6-At the top of your program, about the setup function, declare a variable for each pin:

 

//pins for 7 segment

int a = 2;

int b = 3;

int c = 4;

int d = 5;

int e = 6;

int f = 7;

int g = 8;

 

7-Inside the setup function, you need to set each of the pins 2 through 8 as output pins.  Here is how you do this for the first pin:

 

  pinMode(a, OUTPUT);

 

Do the same as above for pins 3 to 8 (or I should say, for pins b to g);

 

8-Inside the loop function, write the statements to display the number zero.  Note that we simply need to make every LED on the segment be on except for g.  Also, remember that all LEDs on the 7-segment are connected to a common positive input and that our Arduino is connected to the negative side of each LED.  So our Arduino can turn on an LED by outputting a LOW value.  (This is the opposite of one you would expect if you don’t understand this.)

This will display a zero:

 

  digitalWrite(a, LOW);

  digitalWrite(b, LOW);

  digitalWrite(c, LOW);

  digitalWrite(d, LOW);

  digitalWrite(e, LOW);

  digitalWrite(f, LOW);

  digitalWrite(g, HIGH);

 

9-Test your program by uploading it to your Arduino.  You should see a zero on your display.

 

10-Add a 1 second delay after the code to display the 0 so that the 0 shows for a second.

 

11-Add the code needed to display the number 1.

 

  digitalWrite(a, HIGH);

  digitalWrite(b, LOW);

  digitalWrite(c, LOW);

  digitalWrite(d, HIGH);

  digitalWrite(e, HIGH);

  digitalWrite(f, HIGH);

  digitalWrite(g, HIGH);

 

12-Test your program/circuit.  You should see an alternating 0 and 1 now.

 

13-Continue adding delays and the code for all numbers up to nine.

 

14-Test your program/circuit.

 

PROJECT EXPECTATIONS

 

Show Mr. Campeau your working display that shows numbers gradually moving from 0 to 9 and restarting. (LVL 4)

 

Show Mr. Campeau your working display that shows numbers gradually moving from 0 to 9 and then A, b, C, d, E and F.  So you are counting in hex now.  (Can you figure out why B and D are in lower case instead of upper case?) (LVL 4+)

 

POSSIBLE ADDITION (NOT REQUIRED)

 

Can you make the user enter a number (in the Serial Monitor) and have the display show that number?  Note that you need to look at the User Input lesson to be able to do this.