Wall's Corners Wall's Corners Author
Title: Make a Stevenson Screen with Arduino Part 2 – Display Numerical Values on an Electronic Scoreboard (7 segment LED)
Author: Wall's Corners
Rating 5 of 5 Des:
To understand the big picture of the Stevenson screen we will be making, let’s take a look at its specifications. We should be “thinking bef...

To understand the big picture of the Stevenson screen we will be making, let’s take a look at its specifications. We should be “thinking before making.” But with Arduino, you get to enjoy building upon and expanding things while trying out various parts hands-on. I recommend you to”create something with a goal in mind” only after you’re already familiar with a few sensors.
Now, let’s consider the specs of the Stevenson screen.

Today’s Electronics Recipe

Estimated time to complete: 60 minutes
Parts needed:

Specs of the Stevenson Screen

Let’s look up the definition of “Stevenson screen” on Wikipedia.

Stevenson Screen
“A Stevenson screen or instrument shelter is an enclosure to shield meteorological instruments against precipitation and direct heat radiation from outside sources, while still allowing air to circulate freely around them. Its purpose is to provide a standardized environment in which to measure temperature, humidity, dew-point and atmospheric pressure.” 

Under this definition, it seems like it’s okay to call our project an Stevenson screen as long as it has a thermometer (temperature) and a hygrometer (humidity). We were able to work with the temperature sensor last time. In terms of basic features, once we will be able to operate the hygrometer, we will be able to proudly say, “We made an Stevenson screen!”

Now, let’s think a little deeper about the final design details.

What sort of Stevenson screen would be fun to make? Will you enjoy it, and will others be happy with it?
Are there any skills or tools that you currently lack to build this Stevenson screen? By keeping such questions in mind while thinking about the design, you will be able to picture the final design in your head.

When creating something, your work will be polished by repeating this process.

First, let’s think about usability when thinking about the Stevenson screen we will be making.

Arduino plan 2

In the final design, we want the following:

  • The measured values should always be accessible from the PC over the Internet
  • It should operate without being connected to a PC to easily be moved
  • The number of cables connected to the Stevenson screen should be minimized (none, if possible)
  • The measured values should not only be accessible on the PC, but also on the Stevenson screen itself
  • It should be compact (size-wise)

That’s basically what I want for an Stevenson screen that’s easy to use. Now, let’s think about the necessary parts to build it.

  1. The measured values should always be accessible from the PC over the Internet
    → Connect the Stevenson screen to a LAN cable using components such as the Ethernet module
  2. It should operate without being connected to a PC to easily be moved
    → Change the power supply method of Arduino from USB to a DC adapter or batteries
  3. The number of cables connected to the Stevenson screen should be minimized (none, if possible)
    → Go cable-free by not using a DC adapter (solution mentioned above), and by using Wi-Fi instead of a LAN cable
  4. The measured values should not only be accessible on the PC, but also on the Stevenson screen itself
    → Add a display to show the measurements on the case itself
  5. It should be compact
    → We could solder parts onto the base instead of using a breadboard and/or use a smaller Arduino

These are some solutions.
We got familiar with some of these over the course of this series, but not with all of them. So, let’s have a look at each of them.

We did (1) last time. We haven’t done (2) or (3), so we will need to learn how to do them. (4) “Want to view graphs of the data on the PC” is not really an Arduino topic, but rather about displaying data in a browser, so it might require some skills like HTML.
Once you’ve settled on what to build, by adding features one by one, you can develop a detailed plan on how to progress towards completion.
Today, we will learn about the 7-segment LED, to solve (4) “The measured values should not only be accessible on the PC, but also on the Stevenson screen itself.”

What Is a 7-Segment LED?

There are several methods for displaying measurements from analog input on the Arduino. Let’s look in detail at the 7-segment LED, which we touched on briefly last time.

2014-08-29-05.10.12-e1409570497886

7-segment LED

DSC_0029-e1410917121722

Back side of the 7-segment LED

The 7-segment LED (usually abbreviated as 7-seg LED) is an LED made to display numerical values. There are 7 LEDs to represent a digit and 1 LED to represent a dot, totaling 8 LEDs. We will proceed by using a single-digit version, but there are other versions that support 2 or 4 digits. Perhaps, you’ve already seen the 7-seg LED on vending machines? (But recently, more and more vending machines are using touch screens…)
LEDs have an easy-to-understand display, with durable parts, making them a good fit for reliable use, even in a tough environment.

The 7-Seg LED Composition

There are two types of 7-seg LEDs: “common anode” and “common cathode.” The difference is whether the common is anode (positive) or cathode (negative/ground). Since LEDs are directional, if you wire the anode and cathode in reverse directions, nothing will be displayed.

We will use the “common cathode” type of 7-seg LED.

7segLayer 2

The 7-segment LED composition

Displaying the Digits From 0 to 9

You can see from the above diagram that the part consists of the LEDs a-g and the dot DP. By turning these LEDs on and off, we can represent digits. We sketch the ways to display the digits from 0 to 9.
In the below chart, “1” means to run current through it, and “0” means to not run current through it. We will use this chart in our program later.

7segMap

On-off (1/0) chart for the digits from 0 through 9 on a 7-segment LED

For example, to display “1”, we should run a current through b and c as shown below.

1

As you can tell by its name, a 7-seg LED is an LED, so we have to insert a resistor in the circuit. The circuit, when used with an Arduino, is as above.

n_01

Code-Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//
// A program to up "1" in a 7-segment LED
//
void setup(){
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
}
void loop(){
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
delay(200);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
delay(200);
}

Do you have an idea of how it works?
We’ll now create the circuit to display the digits from 0 to 9 on the 7-seg LED. There’s going to be a fair amount of wiring.

7segmentLEDSingle01

Circuit displaying the digits from 0 to 9

By controlling the 28-pin digital outs, we can turn on the specified LEDs.
In reality, it’s a little difficult to use with the Arduino, so we’ll consider a program that counts up from 0 to 9.

Code-Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
void loop(){
//0
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
//Turn everything off for now
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
//1
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
//Turn everything off for now
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
….

Just counting from 0 to 9 takes a long loop in the program.
We would like to shorten the code. It would be nice if we had a function that takes a number as an input and displays it on the 7-seg LED.

NumPrint(number); //Display the specified number on the 7-segment LED

By using the previous chart, we will be able to write a useful function.

Code-Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//Define the arrangements for the digits
boolean Num_Array[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,1,0}, //7
{1,1,1,1,1,1,1}, //8
{1,1,1,1,0,1,1} //9
};
//Define the function for LED output
void NumPrint(int Number){
for (<code class="cpp color1 bold">int</code> <code class="cpp plain">w=0; w<=7; w++</code>){
digitalWrite(w+2,-Num_Array[Number][w]);
}
}

The NumPrint function defines all patterns for the digits in Num_Array. Based on this variable, we can easily display the digits on the 7-seg LED by controlling its 7 LEDs.
Below is an example of a program that uses this function to count up from 0 to 9.

Code-Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// Program to up 0 to 9 on a 7-segment LED
//
void setup(){
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
}
//Define the LED layout
boolean Num_Array[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,1,0}, //7
{1,1,1,1,1,1,1}, //8
{1,1,1,1,0,1,1} //9
};
//Define the LED display function
void NumPrint(int Number){
for (<code class="cpp color1 bold">int</code> <code class="cpp plain">w=0; w<=7; w++</code>){
digitalWrite(w+2,-Num_Array[Number][w]);
}
}
//Turn off all LEDs
void off7SegLED(){
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
}
void loop(){
NumPrint(0);
delay(2000);
off7SegLED();
delay(50);
NumPrint(1);
delay(2000);
off7SegLED();
delay(50);
NumPrint(2);
delay(2000);
off7SegLED();
delay(50);
NumPrint(3);
delay(2000);
off7SegLED();
delay(50);
NumPrint(4);
delay(2000);
off7SegLED();
delay(50);
NumPrint(5);
delay(2000);
off7SegLED();
delay(50);
NumPrint(6);
delay(2000);
off7SegLED();
delay(50);
NumPrint(7);
delay(2000);
off7SegLED();
delay(50);
NumPrint(8);
delay(2000);
off7SegLED();
delay(50);
NumPrint(9);
delay(2000);
off7SegLED();
delay(50);
}

The digits lit up from 0 to 9!
But even this program seems to drag on with a long series of similar commands. Since the commands inside loop() are simply incrementing from 0 to 9 and back, we can combine them in a statement. Furthermore, we can also combine the initialization in setup() with the off7SegLED() that turns off all of the LEDs.

Code-Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// Program to light up from 0 to 9 on a 7-segment LED
//
void setup(){
// Initialize the use of pins 2-8 using a for statement
for(<code class="cpp color1 bold">int</code> <code class="cpp plain">i=2;i<9;i++</code>){
pinMode(i,OUTPUT);
}
}
// Define the LED layout
boolean Num_Array[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,1,0}, //7
{1,1,1,1,1,1,1}, //8
{1,1,1,1,0,1,1} //9
};
// Define the LED display function
void NumPrint(int Number){
for (<code class="cpp color1 bold">int</code> <code class="cpp plain">w=0; w<=7; w++</code>){
digitalWrite(w+2,-Num_Array[Number][w]);
}
}
// Turn off all LEDs
void off7SegLED(){
// Set pins 2-8 to LOW with a for statement
for(int i=2;i<9;i++){
digitalWrite(i,LOW);
}
}
void loop(){
// Count from 0 to 9 with a for loop
for(int i=0;i<10;i++){
NumPrint(i);
delay(2000);
off7SegLED();
delay(50);
}
}

Now, our program is ready!

If you want to speed up the counter, with a long program you have to change the delay value in multiple sections. By using a “for” statement, you only need to change it in one place. I recommend you to develop this habit as programming this way will be important as we go on.

Display Two Digits

Now that we know how to display a single digit, let’s try to display two digits. Since, we used pins 2-8 to display the first digit, we can use a circuit with the remainder of the pins (0,1,9,10,11,12,13) to display a second digit.

But considering how complex the wiring was for only the first digit one, we can imagine how intricate it would become. So, let’s create a sort of optical illusion, an electronic trick, or use an idea from a predecessor.

The human eye perceives a very fast sequence of flashing images as motion. With television and movies, we perceive series of 30 and 24 images per second as moving pictures. By using this mechanism, we can easily display two digits by rapidly switching between the two digits.

What about the circuit? By making a relatively simple change to the circuit from the one-digit case, we can also display two digits.

7segmentLEDDouble17

Circuit diagram for displaying 2 digits

It’s different from the circuit we made to display one digit. As we’re adding a second 7-seg LED, we have to add another resistor. Another difference is the connection point for GND. In the previous example, GND was connected on the Arduino, but now it’s connected to pins 11 and 13. You might wondering if it’s ok. It’s confusing, but let’s consider again the HIGH and LOW of digital output.

In the HIGH state, 5V of electricity flows from the Arduino. In the LOW state, it’s 0V.
0V? Then, it’s as though there is no flow = just like GND.

To display 2 digits, we switch between them by turning the pins 11 and 13 on and off in order.

Code-Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// Program to light up two 7-segment LEDs
//
int _cnt = 0; //
int _number = 0; //
boolean _flg = false;
void setup(){
Serial.begin(9600);
// Initialize digital output for pins 2-8
for (int i=2; i<=8; i++){
pinMode(i,OUTPUT);
}
pinMode(13,OUTPUT);
pinMode(11,OUTPUT);
}
// Define LED layout
boolean Num_Array[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,1,0}, //7
{1,1,1,1,1,1,1}, //8
{1,1,1,1,0,1,1} //9
};
// Define LED display function
void NumPrint(int Number){
for (int w=0; w<=7; w++){
digitalWrite(w+2,-Num_Array[Number][w]);
}
}
// Function to parse a two-digit number into digits
int NumParse(int Number,int s){
if(s == 1){
return Number % 10; // Remainder after dividing by 10 = first digit
}
else if(s == 2){
return Number / 10; // Get integer part after dividing by 10 = second digit
}
return 0;
}
void loop(){
if(_number &amp;gt;= 100){
_number = 0;
}
// Switch between pin 11 and 13 outputs by changing flg function to true / false
if(_flg){
digitalWrite(11,LOW);
digitalWrite(13,HIGH);
_flg = false;
NumPrint(NumParse(_number,1)); // Display first digit
}
else{
digitalWrite(11,HIGH);
digitalWrite(13,LOW);
_flg = true;
NumPrint(NumParse(_number,2)); // Display second digit
}
//At 100, add an additional number to display (1 count per second at 10 delay ×100)
if(_cnt >= 100){
_number++;
_cnt = 0;
Serial.print("NUMBER:");
Serial.println(_number);
}
_cnt++;
delay(10);
}

Now, we can display two digits!

There are some new functions in the program, but simple operations are used for each part.
There are other ways to compute the individual digits in a 2-digit number than the one we implemented, so please read up on them if you’re interested.

Reviewing the specifications that we defined at the beginning of this article, we have 2-3 things to learn including using the humidity sensor, and once we build the external case (5), it looks like our Stevenson screen will be complete.

  1. The measured values should always be accessible from the PC over the Internet
  2. It should operate without being connected to a PC to easily be moved
  3. The number of cables connected to the Stevenson screen should be minimized (none, if possible)
  4. The measured values should not only be accessible on the PC, but also on the Stevenson screen itself
  5. It should be compact

Next time, we will shift from having the Arduino connected to our PC to using batteries or a DC adapter as well as learn how to use the humidity sensor. We will be moving quickly towards completing our Stevenson screen!

Share This:

View more at: http://yoursmart.mobi

About Author

Advertisement

Post a Comment

 
Top