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 few mathematical equations to calculate the temperature in Degree celcius and Kelvin from the input recieved from pin A0 of Arduino where Thermistor is connected.
Thus, we required the <math.h> header file to calculate the above mentioned values from the input given by 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 thermistor connected to ADC pin A0 of Arduino.
Floating point variables output_voltage, thermistor_resistance, therm_res_ln, 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 celcius units. To do that, we will subtract the value of kelvin at 0 degree celcius i.e. 273.15 from the temperature value we calculate using the Steinhart-Hart thermistor equation.
Now we have the temperature value in degree celcius and kelvin units.
We use the Serial.print functions to print the values of temperature in degree celcius 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 7-segment LED when temperature value changes.
For temperature value below 40 degree celcius, the code is written to display "L" on 7-segment display indicating the temperature value is low.
For temperature value above 40 degree celcius, the code is written to display "H" on 7-segment display indicating the temperature value is high.