Measuring Temperature with PT100 and ESP32: A Step-by-By Step Guide
Temperature measurement is a fundamental aspect of many projects in the fields of electronics, IoT, and process control. One of the most precise ways to measure temperature is by using a PT100 sensor. In this tutorial, we will guide you through the process of setting up a PT100 temperature sensor with an ESP32 to build a high-precision temperature monitoring system.
What is PT100?
PT100 is a type of platinum resistance temperature sensor. It follows the characteristic that the resistance of platinum increases with temperature. A standard PT100 will have a resistance of 100 ohms at 0°C.
Components Required:
- ESP32 development board
- PT100 temperature sensor
- 2x 10k ohm resistors
- Breadboard and jumper wires
- Soldering iron and solder (optional)
Circuit Setup:
Connecting the PT100 Sensor:
- The PT100 sensor has three wires: two for the connection to the resistance and one for the ground.
- Connect one end of the PT100 to 3.3V (or 5V, depending on your supply) and the other end to one end of the first 10k resistor.
- Connect the other end of the 10k resistor to an analog input pin (e.g., A0) on the ESP32.
- Connect the ground wire from the PT100 to the GND pin on the ESP32.
Creating a Voltage Divider:
- Place the second 10k resistor in parallel with the PT100 sensor.
- This setup creates a voltage divider, which allows the ESP32 to read an analog value proportional to the temperature.
Programming the ESP32:
Initialize the Analog Pin:
- Set the analog pin as an input and initialize the Serial communication to display the temperature values on your computer.
Read the Voltage:
- Use the ESP32’s analogRead() function to get the voltage value from the PT100 circuit.
Convert Voltage to Temperature:
- The voltage across the PT100 is proportional to the temperature.
- You can use the following formula to convert the voltage to temperature:
[
\text{Temperature (°C)} = \left(\frac{\text{AnalogRead}}{1023} \times 5\right) - (RT / (R1 + RT))
] - Where
RT
is the resistance of the PT100 at the measured voltage andR1
is the resistance value of the 10k resistor.
Iterate and Display:
- Continuously read the temperature and update the display every few seconds.
Sample Code:
#include <Arduino.h>
const int analogPin = A0; // PT100 connected to A0
const int refVoltage = 5000; // Reference voltage (mV)
void setup() {
Serial.begin(9600);
pinMode(analogPin, INPUT);
}
void loop() {
int reading = analogRead(analogPin);
float voltage = reading / 1023.0 * refVoltage;
float temperature = voltage / (10000/2) * 100.0; // 10k ohm resistor
temperature = (temperature / 100.0) * 100.0; // Convert to Celsius
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
delay(2000);
}
Calibration:
To ensure accuracy, calibrate your PT100 sensor at a known temperature, such as an ice-water mixture (0°C) or a boiling water (100°C), and adjust the readings accordingly.
Conclusion:
Using a PT100 sensor with an ESP32 allows for highly accurate temperature measurements. This setup is ideal for applications requiring precise temperature monitoring, such as weather stations, industrial processes, or home automation systems.
By following these steps, you can easily integrate a PT100 sensor into your ESP32 projects and unlock the potential of precise temperature sensing.