Thermistor Temperature Display

Aim

To display high or low-temperature values using Thermister.

Components required for the experiment

Arduino UNO Board, Breadboard, Thermister (10K), Resistor (220 Ohms) and Seven Segment Display (Common Cathod).

What is a Thermistor and where it is used?

A thermistor is a type of resistor whose resistance changes with temperature. Thermistors are used in temperature sensing applications such as in thermostats, temperature control circuits, and in monitoring the temperature of electronic devices. They can also be used in compensation circuits to adjust for temperature-related variations in other electronic components. Thermistors are often preferred over other temperature sensing devices like thermocouples and RTDs (Resistance Temperature Detectors) because they are small, inexpensive, and have a highly sensitive response to temperature changes.

A seven-segment display is an electronic display that consists of seven segments, arranged in a rectangular shape. Each of the segments can be turned on or off independently, and when certain combinations of segments are turned on, they can display different digits (0-9) and some letters. Seven-segment displays can be either a common cathode or a common anode, depending on how the LEDs are connected internally.

Seven-segment displays are commonly used as simple digital indicators for displaying numbers in a variety of applications, including calculators, digital clocks, digital meters, and other electronic devices that require numerical displays. They are also used in larger sizes for outdoor signs and displays.

 

 

Circuit Diagram

To practice, make the circuit diagram with the exact pin-to-pin connection as shown below. This will help you to complete the experiment successfully.

 

Code

int A = 2;  //pin A of 7-segment is connected to pin 2 of Arduino
int B = 3;  //pin B of 7-segment is connected to pin 3 of Arduino
int C = 4;  //pin C of 7-segment is connected to pin 4 of Arduino 
int D = 5;  //pin D of 7-segment is connected to pin 5 of Arduino
int E = 6;  //pin E of 7-segment is connected to pin 6 of Arduino
int F = 7;  //pin F of 7-segment is connected to pin 7 of Arduino
int G = 8;  //pin G of 7-segment is connected to pin 8 of Arduino

#include <math.h>  //<math.h> header file is used to solve the mathematical expressions in this code
const int thermistor_output = A0;  //Themistor pin is connected to pin A0 of Arduino and is named thermistor_output

void setup()
{
Serial.begin(9600);  //Initialise the Serial communication
pinMode(A,OUTPUT);   
pinMode(B,OUTPUT);
pinMode(C,OUTPUT);
pinMode(D,OUTPUT);
pinMode(E,OUTPUT);
pinMode(F,OUTPUT);
pinMode(G,OUTPUT);  //All seven segments of the LED pins are set as OUTPUT pins
}

void loop()
{
int thermistor_adc_val;   //Variable to store the ADC value of thermistor
double output_voltage, thermistor_resistance, therm_res_ln, temperature;  //floating point variables are created using double data type
thermistor_adc_val = analogRead(thermistor_output);  // Analog value of thermistor is stored in the variable
output_voltage = ( (thermistor_adc_val * 5.0) / 1023.0 );
thermistor_resistance = ( ( 5 * ( 10.0 / output_voltage ) ) - 10 ); //Resistance in kilo ohms
thermistor_resistance = thermistor_resistance * 1000 ;   //Resistance in ohms
therm_res_ln = log(thermistor_resistance);

//Steinhart-Hart Thermistor Equation:
//Temperature in Kelvin = 1 / (A + B[ln(R)] + C[ln(R)]^3)
//where A = 0.001129148, B = 0.000234125 and C = 8.76741*10^-8

temperature = ( 1 / ( 0.001129148 + ( 0.000234125 * therm_res_ln ) + ( 0.0000000876741 * therm_res_ln * therm_res_ln * therm_res_ln ) ) );  //Temperature in Kelvin

temperature = temperature - 273.15; //Temperature in Degree Celcius
Serial.print("Temp in Celcius = ");
Serial.print(temperature);
Serial.println("C");
Serial.print("Temp in Kelvin = ");
Serial.print(temperature + 273.15);  //Conversion in Kelvin
Serial.println("K");
delay(1000);


if (temperature<40)  //if temperature is less than 40 degree celcius, the LED will show "L" sign
{
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, LOW);
}
else
{
digitalWrite(A, LOW);  //if temperature is more than 40 degree celcius, the LED will show "H" sign
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, LOW);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, HIGH);
}
}

Code Explained

This code Display H for the High-temperature value or L for the Low-temperature value sensed by the Thermister.

int A = 2;  //pin A of 7-segment is connected to pin 2 of Arduino
int B = 3;  //pin B of 7-segment is connected to pin 3 of Arduino
int C = 4;  //pin C of 7-segment is connected to pin 4 of Arduino 
int D = 5;  //pin D of 7-segment is connected to pin 5 of Arduino
int E = 6;  //pin E of 7-segment is connected to pin 6 of Arduino
int F = 7;  //pin F of 7-segment is connected to pin 7 of Arduino
int G = 8;  //pin G of 7-segment is connected to pin 8 of Arduino

These line of codes explains the connection between 7-segment LED and Arduino Uno.

#include <math.h>  //<math.h> header file is used to solve the mathematical expressions in this code
const int thermistor_output = A0;  //Themistor pin is connected to pin A0 of Arduino and is named thermistor_output

There are a few mathematical equations to calculate the temperature in Degrees Celcius and Kelvin from the input received from pin A0 of Arduino where the Thermistor is connected.

Thus, we required the <math.h> header file to calculate the above-mentioned values from the input given by the thermistor.

void setup()
{
Serial.begin(9600);  //Initialise the Serial communication
pinMode(A,OUTPUT);   
pinMode(B,OUTPUT);
pinMode(C,OUTPUT);
pinMode(D,OUTPUT);
pinMode(E,OUTPUT);
pinMode(F,OUTPUT);
pinMode(G,OUTPUT);  //All seven segments of the LED pins are set as OUTPUT pins
}

The setup function initialises the serial communication between Arduino board and the computer at 9600 baud rate. Also, the Arduino pins connected to the 7-segment LED as set as OUTPUT pins.

void loop()
{
int thermistor_adc_val;   //Variable to store the ADC value of thermistor
double output_voltage, thermistor_resistance, therm_res_ln, temperature;  //floating point variables are created using double data type
thermistor_adc_val = analogRead(thermistor_output);  // Analog value of thermistor is stored in the variable
output_voltage = ( (thermistor_adc_val * 5.0) / 1023.0 );
thermistor_resistance = ( ( 5 * ( 10.0 / output_voltage ) ) - 10 ); //Resistance in kilo ohms
thermistor_resistance = thermistor_resistance * 1000 ;   //Resistance in ohms
therm_res_ln = log(thermistor_resistance);

The "loop" function is another built-in function that runs repeatedly as long as the Arduino board has power.

A variable thermistor_adc_val is created to store the value of the thermistor connected to ADC pin A0 of Arduino.

Floating point variables output_voltage, thermistor_resistance, therm_res_ln, and temperature are created.

The calculation values of respective floating variables are stored.

//Steinhart-Hart Thermistor Equation:
//Temperature in Kelvin = 1 / (A + B[ln(R)] + C[ln(R)]^3)
//where A = 0.001129148, B = 0.000234125 and C = 8.76741*10^-8

temperature = ( 1 / ( 0.001129148 + ( 0.000234125 * therm_res_ln ) + ( 0.0000000876741 * therm_res_ln * therm_res_ln * therm_res_ln ) ) );  //Temperature in Kelvin

temperature = temperature - 273.15; //Temperature in Degree Celcius
Serial.print("Temp in Celcius = ");
Serial.print(temperature);
Serial.println("C");
Serial.print("Temp in Kelvin = ");
Serial.print(temperature + 273.15);  //Conversion in Kelvin
Serial.println("K");
delay(1000);

The Steinhart-Hart thermistor equation is used with the constant values to calculate the temperature in kelvin units. 

For ease of the user, we will store the temperature value in degree Celsius units. To do that, we will subtract the value of kelvin at 0 degrees Celsius i.e. 273.15 from the temperature value we calculate using the Steinhart-Hart thermistor equation.

Now we have the temperature value in degrees Celsius and kelvin units.

We use the Serial.print functions to print the values of temperature in degrees Celsius and kelvin units and update the values after every 1 second.

if (temperature<40)  //if temperature is less than 40 degree celcius, the LED will show "L" sign
{
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, LOW);
}
else
{
digitalWrite(A, LOW);  //if temperature is more than 40 degree celcius, the LED will show "H" sign
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, LOW);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, HIGH);
}
}

We have given a condition to show the indication on the 7-segment LED when the temperature value changes.

For temperature values below 40 degrees Celsius,  the code is written to display "L" on a 7-segment display indicating the temperature value is low.

For temperature values above 40 degrees Celsius,  the code is written to display "H" on a 7-segment display indicating the temperature value is high.

 

Output

  1. Press the start simulation button in the interface.

  2. Move the mouse cursor to the Thermistor sensor.

  3. Click on the Thermistor sensor to activate it.

  4. Once activated, a slider will appear on top of the Thermistor.

  5. Adjust the slider to change the Thermistor value.

  6. Observe the seven segment display, which will show either 'H' or 'L' based on the value specified in the code.

 

Conclusion

When the temperature value detected by the thermistor rises above 40 degrees, the seven-segment display shows the letter "H". Conversely, when the temperature value falls below 40 degrees, the seven-segment display shows the letter "L".

Assignment

Change the code to display the letter "H" on the 7-segment LED when the temperature is above 80 degrees, otherwise, the 7-segment LED should show the letter "L".