====== Thermistor ======
====== Temperature Measurement Using Thermistor ======
This scenario demonstrates how to measure temperature using a thermistor (temperature-sensitive resistor) connected to an Arduino Uno. The temperature is calculated using the Steinhart-Hart equation.
===== Prerequisites =====
* Familiarize yourself with Arduino hardware reference.
* Basic understanding of analog sensor readings and voltage dividers.
* Install LiquidCrystal library for LCD display.
===== Hardware Connections =====
| Component | Arduino Pin |
|------------|-------------|
| Thermistor | A5 (Analog) |
| LCD | RS=8, EN=9, D4=4, D5=5, D6=6, D7=7 |
===== Suggested Knowledge Resources =====
* Arduino programming fundamentals
* [[taltech:arduino:hardware|Arduino Uno Hardware Reference]]
===== Task =====
Measure temperature using a thermistor and display the results (ADC reading, voltage, resistance, and temperature in Celsius) on the LCD.
===== Steps =====
=== Step 1: Include Libraries ===
#include
#include
=== Step 2: Initialize LCD ===
Declare LCD pins and initialize:
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
const int sensorPin = A5;
=== Step 3: Setup ===
Set LCD dimensions and initial message:
void setup() {
lcd.begin(16, 2);
lcd.print("Temperature");
delay(1000);
}
=== Step 4: Main Loop ===
Read sensor value, calculate temperature, and display on LCD:
void loop() {
readThermistor(analogRead(sensorPin));
delay(1000);
lcd.clear();
}
void readThermistor(int RawADC) {
double Temp;
long Resistance;
// Calculate resistance
Resistance = ((10240000 / RawADC) - 10000);
// Display ADC and voltage
lcd.setCursor(0, 0);
lcd.print("AD=");
lcd.print(RawADC);
lcd.setCursor(8, 0);
lcd.print("U=");
lcd.print(((RawADC * 5.0) / 1024.0), 3);
// Display resistance
lcd.setCursor(0, 1);
lcd.print("R=");
lcd.print(Resistance);
// Calculate temperature (Steinhart-Hart)
Temp = log(Resistance);
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp)) * Temp);
Temp = Temp - 273.15; // Convert Kelvin to Celsius
// Display temperature
lcd.setCursor(8, 1);
lcd.print("T=");
lcd.print(Temp);
}
===== Validation =====
LCD displays accurate ADC values, voltage readings, resistance, and temperature in Celsius. Typical room temperature should range between 19-24 °C.
===== Troubleshooting =====
If temperature readings are incorrect or unstable:
* Check wiring and verify analog input connection (A5).
* Verify correct resistor value in voltage divider.
* Ensure accurate Steinhart-Hart constants are used.