This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| en:iot-open:practical:hardware:taltech:arduino:scenarios:thermistor [2025/06/25 08:57] – created raivo.sell | en:iot-open:practical:hardware:taltech:arduino:scenarios:thermistor [2025/09/02 11:38] (current) – raivo.sell | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== 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 the Arduino hardware reference. | ||
| + | * Basic understanding of analog sensor readings and voltage dividers. | ||
| + | * Install LiquidCrystal library for LCD display. | ||
| + | |||
| + | ===== Hardware Connections ===== | ||
| + | ^ Component | ||
| + | | Thermistor | ||
| + | | LCD | RS=8, EN=9, D4=4, D5=5, D6=6, D7=7 | | ||
| + | |||
| + | |||
| + | ===== 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 === | ||
| + | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | </ | ||
| + | |||
| + | === Step 2: Initialize LCD === | ||
| + | Declare LCD pins and initialize: | ||
| + | <code c> | ||
| + | LiquidCrystal lcd(8, 9, 4, 5, 6, 7); | ||
| + | const int sensorPin = A5; | ||
| + | </ | ||
| + | |||
| + | === Step 3: Setup === | ||
| + | Set LCD dimensions and initial message: | ||
| + | <code c> | ||
| + | void setup() { | ||
| + | lcd.begin(16, | ||
| + | lcd.print(" | ||
| + | delay(1000); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | === Step 4: Main Loop === | ||
| + | Read sensor value, calculate temperature, | ||
| + | <code c> | ||
| + | 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, | ||
| + | lcd.print(" | ||
| + | lcd.print(RawADC); | ||
| + | lcd.setCursor(8, | ||
| + | lcd.print(" | ||
| + | lcd.print(((RawADC * 5.0) / 1024.0), 3); | ||
| + | |||
| + | // Display resistance | ||
| + | lcd.setCursor(0, | ||
| + | lcd.print(" | ||
| + | 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, | ||
| + | lcd.print(" | ||
| + | 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 the correct resistor value in the voltage divider. | ||
| + | * Ensure accurate Steinhart-Hart constants are used. | ||