To use an NTC thermistor with the ESP32, you need to connect it in a voltage divider configuration. Here’s how you can do it:
Components Needed:
- NTC thermistor (e.g., 10kΩ thermistor)
- Fixed resistor (10kΩ, to form a voltage divider with the thermistor)
- ESP32
Circuit Connections:
- NTC Thermistor:
- One leg of the thermistor connects to the 3.3V (VCC) pin of the ESP32.
- The other leg of the thermistor connects to the ADC pin (e.g., GPIO34) on the ESP32.
- Resistor:
- The other leg of the fixed resistor connects to GND (ground).
- The other side of the fixed resistor connects to the same point as the thermistor that goes to the ADC pin.
This forms a simple voltage divider circuit, where the voltage at the junction of the thermistor and resistor can be read by the ADC pin.
Circuit Diagram:
flowchart LR 3.3V --> NTC --> GPIO34 --> Resistor --> GND
In this setup, as the temperature changes, the resistance of the NTC thermistor will change, which in turn changes the voltage at the ADC pin.
4. Arduino Code to Read NTC Sensor
Now that we have the hardware setup, let’s write the Arduino code to read the temperature from the NTC thermistor.