Temperature Measurement

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:

  1. 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.
  1. 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.

Arduino Code:

const int thermistorPin = 34;  // ADC Pin connected to the NTC Thermistor
const float referenceVoltage = 3.3;  // Reference voltage (3.3V)
const int seriesResistor = 10000;  // Series resistor value (10kΩ)
const float beta = 3950;  // Beta value for the thermistor (depends on the thermistor used)
const float tempNominal = 25.0;  // Nominal temperature at 25°C
const int resistanceNominal = 10000;  // Nominal resistance at 25°C (10kΩ)

void setup() {
  Serial.begin(115200);
  pinMode(thermistorPin, INPUT);
}

void loop() {
  int adcValue = analogRead(thermistorPin);  // Read the ADC value (0-4095)
  float voltage = adcValue * (referenceVoltage / 4095.0);  // Convert ADC value to voltage
  float resistance = (seriesResistor * (referenceVoltage / voltage - 1));  // Calculate the resistance of the thermistor

  // Calculate temperature using the Steinhart-Hart equation or an approximation
  float temperature = 1.0 / (log(resistance / resistanceNominal) / beta + 1.0 / (tempNominal + 273.15)) - 273.15;

  // Print the temperature in Celsius
  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" C");

  delay(1000);  // Wait for a second before taking another reading
}
C++

RELATED ARTICLES

Overview of DHT Sensors

Leave a comment

Your email address will not be published. Required fields are marked *

Please note, comments must be approved before they are published