Introduction: Simple Seven Segment Temperature Display Using Arduino

This is a project that has been implemented in the simplest way possible with just an Arduino UNO and a simple temperature sensor (LM35). No ICs are used to control the seven segment displays (The Arduino does everything ).

Applications

  • This can be used as a simple home ambient temperature device.It can also measure and display temperatures up to 99°C.
  • The temperature of liquids can be measured after waterproofing the sensor ( Check out this instructable on how to do it )
  • It can be used to monitor equipment that gets easily damaged due to over-heating.

Step 1: Components List

  1. Arduino Uno (1)
  2. LM35 Temperature Sensor (1)
  3. Seven Segment Display (2)
  4. Resistors - 470 ῼ (14)
  5. Jumper wires with male connectors on both ends
  6. Breadboard
  7. 5V source - USB charger or battery (6V pack)

Step 2: Components Explained

Users who are familiar with an Arduino and the IC can skip this step


Arduino

If you aren't familiar with an Arduino check out this guide: https://www.arduino.cc/en/Guide/HomePage

Seven segment display

A Seven-segment display is a form of electronic display device for displaying decimal numerals. It is usually made up of a number of LEDs and they have 10 pins that can be used to turn these LEDs on/off to display the various numerals.

There are two types of Seven segment displays

Common cathode displays and Common anode displays. Their difference in pin configuration is as indicated in the above figure.

The only difference in the connections is that Common cathode uses GND at 2 pins (as shown in fig.) and a HIGH to turn the respective LEDs on while common anode displays use VCC at 2 pins (as shown in fig.) and a LOW to turn the respective LEDs on.

For this experiment, I will be using common anode displays.

LM35 [ Datasheet ]

The LM35 series are precision IC temperature devices with an output voltage linearly- proportional to the Centigrade temperature. It will show an increase in 10mV with 1°C rise in temperature. So at 25°C its output voltage will be about 250mV.

It is preferred over a thermistor as it is more accurate and draws only 60 μA from the supply, it also has very low self-heating of less than 0.1°C in still air.

Step 3: Making the Connections

Ensure that you've got Common anode displays to make the connections as shown in the fig.

For common cathode displays, provide GND instead of VCC at the respective pins and make necessary changes in the code (will be discussed in the code explanation step)

Step 4: Code

int temp;
int tempPin = A2;
int x,y;
int bcd_array[10][7] = {  { 0,0,0,0,0,0,1 },    // 0
                          { 1,0,0,1,1,1,1 },    // 1
                          { 0,0,1,0,0,1,0 },    // 2
                          { 0,0,0,0,1,1,0 },    // 3
                          { 1,0,0,1,1,0,0 },    // 4
                          { 0,1,0,0,1,0,0 },    // 5
                          { 0,1,0,0,0,0,0 },    // 6
                          { 0,0,0,1,1,1,1 },    // 7
                          { 0,0,0,0,0,0,0 },    // 8
                          { 0,0,0,1,1,0,0 }};   // 9
                                       
void BCD0(int);
void BCD1(int);

void setup()
{
  pinMode(2, OUTPUT);   
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(A2, INPUT);  
  pinMode(9, OUTPUT);   
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(14, OUTPUT);
  pinMode(15, OUTPUT);
}


void loop()
{
temp = analogRead(tempPin);
temp = temp * 0.48828125;
x = (temp/10);
y = (temp -((temp / 10) * 10));
delay(1000)
BCD0(x);
BCD1(y);
}

void BCD0(int number) 
{
  int pin= 2;
  for (int j=0; j < 7; j++) {
   digitalWrite(pin, bcd_array[number][j]);
   pin++;
  }
}


void BCD1(int number) 
{
  int pin= 9;
  for (int j=0; j < 7; j++) {
   digitalWrite(pin, bcd_array[number][j]);
   pin++;
  }
}

Step 5: Code Explained

int temp;
int tempPin = A2;
int x,y;

This declares the variables and assigns pin A2 ( analog pin) on the Arduino as the data output from the LM35 sensor.

Variable 'x' refers to the first digit of the temperature reading(the value that will show up on the first 7 segment display) and 'y' refers to the second digit of the temperature reading(the value that will show up on the second 7 segment display)

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


The above array is used to turn the respective LEDs on/off as needed for each digit. Check out the images given above to understand how different combinations give us different numerals.The above-given code is for common anode displays.

For common cathode displays, to turn the displays on a logic High is needed, so replace the 1s in the array with 0s and vice versa.

void BCD0(int);

void BCD1(int);

BCD0 and BCD1 are two functions which when given a single digit integer turns on the corresponding LEDs to show the integer on the display. BCD0 is used for the first integer of the temperature reading and BCD1 is used for the second integer of the temperature reading.


void setup()
{
  pinMode(2, OUTPUT);   
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(A2, INPUT);  
  pinMode(9, OUTPUT);   
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(14, OUTPUT);
  pinMode(15, OUTPUT);
}

All pins are set as output pins and the sensor input at pin A2 is set as input.

You might have noticed that even though an Arduino UNO has just 12 digital I/O pins (That is pins 2-13 not including TX and RX) I have set pins 14 and 15 as output in the code. This is because we can use the analog pins as digital output pins by referring to them as pins 14-19 (6 analog pins). Check this out!



void loop()
{
temp = analogRead(tempPin);
temp = temp * 0.48828125;

The Arduino board contains a 10-bit analog to digital converter. This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. This yields a resolution between readings of: 5 volts / 1024 units or, 0.0048828125 volts (~4.9 mV) per unit.

As given in the LM35 datasheet,
Vout=10mV/°C

Vout=0.01V/°C

To get the temperature reading from the Vout value :

°C = Vout / 0.01

°C = 100*Vout (e.g 340mv*100

= 0.34V*100

= 34°C)


So in the code the no. 0.0048828125 is in fact [ 100*5/1024 ]

Thus the value of the variable temp will be the reading in °C

x = (temp/10);
y = (temp -((temp / 10) * 10));
BCD0(x);
BCD1(y);

Now we have to split the digits of the temperature reading to display it on two seven segment displays.

Since x & y were declared as an integers earlier, dividing it by 10 would only give the non-decimal part,

e.g :- x= 34/10 = 3

Also to find out y, consider this example :

y = (34 - (( 34/10)*10))

=(34 - (3*10)

=(34 - 30)

= 4

Thus the two digits of the temperature reading are extracted and stored in the variables x and y.

Then these two variables are given as inputs to the function BCD0 and BCD1.



void BCD0(int number) 
{
  int pin= 2;
  for (int j=0; j < 7; j++) {
   digitalWrite(pin, bcd_array[number][j]);
   pin++;
  }
}


void BCD1(int number) 
{
  int pin= 9;
  for (int j=0; j < 7; j++) {
   digitalWrite(pin, bcd_array[number][j]);
   pin++;
  }
}



The above lines of code are used to display the numerals on the 7 segment displays.

Consider this case : temp value = 34°C then x=3 and y=4

digitalWrite(pin, bcd_array[number][j]); looks into the array we defined earlier and takes the corresponding values of 0 and 1 and sets each pin accordingly using a 'for loop'.

From the array this is the set of values corresponding to the numeral 3 - { 0,0,0,0,1,1,0 },

In the first iteration of the 'for loop' it sets pin 2 as 0 (LOW) so the corresponding LED glows ( for common anode displays)

2nd iteration its sets pin 3 as 0 ......this continues until it sets all pins.

Similarly, the same thing happens to the the variable y as it enters the function BCD1.

Thus both the digits get displayed.




Step 6: Taking It Further

After uploading the code this circuit can be run off a simple USB charger or one can even use a 6V battery source to run it by connecting the source to the 'Vin' pin on an Arduino.


This project was done with simplicity in mind and using minimum hardware.There is another way to control more than one seven segment display without using up all your input-output pins by a method called multiplexing (using ICs)

Individual display elements are multiplexed, that is, driven one at a time, but the electronics and the persistence of vision combine to make the viewer believe the entire display is continuously active thus requiring far fewer pins and wires to run them.

Comments

author
Swansong (author)2017-07-21

That's a neat setup :)

author
glenzac (author)Swansong2017-07-21

Thanks! :)

About This Instructable

567views

9favorites

License:

More by glenzac:Simple Seven Segment Temperature Display Using Arduino
Add instructable to: