/*
MSJ Researchers World
Date - 22nd OCT 2024
Mentor - Mr. Siranjeevi M
Contact - 7373771991
*/
// Thermistor configuration
const int thermistorPin = A0; // Analog pin connected to thermistor
const float seriesResistor = 10000.0; // Value of fixed resistor (10kΩ)
const float nominalResistance = 10000.0; // Resistance of thermistor at 25°C
const float nominalTemperature = 25.0; // Nominal temperature (in °C)
const float bCoefficient = 3950.0; // Beta coefficient of the thermistor
const int adcResolution = 1023; // ADC resolution for Arduino Uno (0-1023)
// Function to read temperature
float getTemperature()
{
int adcValue = analogRead(thermistorPin); // Read raw ADC value
float resistance = seriesResistor / ((adcResolution / (float)adcValue) - 1);
float steinhart; // Variable to store temperature calculation
steinhart = resistance / nominalResistance; // R/Ro
steinhart = log(steinhart); // ln(R/Ro)
steinhart /= bCoefficient; // 1/B * ln(R/Ro)
steinhart += 1.0 / (nominalTemperature + 273.15); // + (1/To)
steinhart = 1.0 / steinhart; // Invert value
steinhart -= 273.15; // Convert from Kelvin to °C
return steinhart;
}
void setup()
{
Serial.begin(9600); // Initialize serial communication
}
void loop()
{
float temperature = getTemperature(); // Get the temperature value
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
delay(1000); // Wait 1 second between readings
}