Note

Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.

Why Join?

  • Expert Support: Solve post-sale issues and technical challenges with help from our community and team.

  • Learn & Share: Exchange tips and tutorials to enhance your skills.

  • Exclusive Previews: Get early access to new product announcements and sneak peeks.

  • Special Discounts: Enjoy exclusive discounts on our newest products.

  • Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.

👉 Ready to explore and create with us? Click [here] and join today!

Thermistor

Overview

In this lesson, you will learn how to use thermistor. Thermistor can be used as electronic circuit components for temperature compensation of instrument circuits. In the current meter, flowmeter, gas analyzer, and other devices. It can also be used for overheating protection, contactless relay, constant temperature, automatic gain control, motor start, time delay, color TV automatic degaussing, fire alarm and temperature compensation.

Required Components

In this project, we need the following components.

It’s definitely convenient to buy a whole kit, here’s the link:

Name

ITEMS IN THIS KIT

LINK

Elite Explorer Kit

300+

Elite Explorer Kit

You can also buy them separately from the links below.

COMPONENT INTRODUCTION

PURCHASE LINK

Arduino Uno R4 WiFi

-

Breadboard

BUY

Jumper Wires

BUY

Resistor

BUY

Thermistor

BUY

Wiring

In this example, we use the analog pin A0 to get the value of Thermistor. One pin of thermistor is connected to 5V, and the other is wired up to A0. At the same time, a 10kΩ resistor is connected with the other pin before connecting to GND.

../_images/02-thermistor_bb.png

Schematic Diagram

../_images/02_thermistor_schematic.png

Code

Note

  • You can open the file 02-thermistor.ino under the path of elite-explorer-kit-main\basic_project\02-thermistor directly.

  • Or copy this code into Arduino IDE.

02-thermistor.ino
 1/*
 2  The code reads temperature data from a thermistor connected to analog pin A0 on an Arduino board. 
 3  It calculates the temperature in both Celsius and Fahrenheit using the Steinhart-Hart equation and 
 4  prints the results to the Serial Monitor. The code uses a pull-up resistor and the thermistor's 
 5  beta value for the calculations.
 6
 7  Board: Arduino Uno R4 
 8  Component: Thermistor
 9*/
10
11const int analogPin = A0;   // Analog pin where the thermistor is connected
12const int beta = 3950;      // Beta value of the thermistor
13const int resistance = 10;  // Value of the pull-up resistor in kΩ
14
15void setup() {
16  Serial.begin(9600);  // Initialize Serial communication at 9600 baud rate
17}
18
19void loop() {
20  // Read the analog value from the thermistor
21  int analogValue = analogRead(analogPin);
22
23  // Calculate temperature in Celsius using the Steinhart-Hart equation
24  float tempC = beta / (log((1025.0 * resistance / analogValue - resistance) / resistance) + beta / 298.0) - 273.0;
25
26  // Convert the temperature to Fahrenheit
27  float tempF = 1.8 * tempC + 32.0;
28
29  // Print temperature in Celsius to the Serial Monitor
30  Serial.print("Temp: ");
31  Serial.print(tempC);
32  Serial.println(" degree Celsius");
33
34  // Print temperature in Fahrenheit to the Serial Monitor
35  Serial.print("Temp: ");
36  Serial.print(tempF);
37  Serial.println(" degree Fahrenheit");
38
39  delay(200);  // Pause for 200 milliseconds before the next reading
40}

After uploading the code to the uno r4 board, you can open the serial monitor to check the current temperature.

The Kelvin temperature is calculated using the formula TK=1/(ln(RT/RN)/B+1/TN). This equation is derived from the Steinhart-Hart equation and simplifies calculations. You can also find more information about this formula on the detailed introduction page of the Thermistor.