- ✓ Why NTC thermistors need a voltage divider circuit
- ✓ The math behind voltage dividers and how to calculate resistance from voltage
- ✓ How to choose the correct series resistor (R_series) for your temperature range
- ✓ ADC resolution differences: ESP8266 (10-bit) vs ESP32/Pico W (12-bit)
- ✓ Optimizing your circuit for accuracy and noise reduction
- ✓ Common voltage divider mistakes and how to fix them
Why Does an NTC Need a Voltage Divider?
Microcontrollers like the ESP8266, ESP32, and Pico W can only measure voltage on their ADC (Analog-to-Digital Converter) pins. They cannot measure resistance directly.
An NTC thermistor changes its resistance with temperature. To convert this changing resistance into a measurable voltage, we need a voltage divider circuit.
Simple Explanation: NTC Thermistor → Changes Resistance → Voltage Divider → Changes Voltage → ADC Reads Voltage → Firmware Calculates Temperature Without a voltage divider, the ADC would just read 0V or 3.3V with no useful information!
If you connect an NTC directly between 3.3V and GND (without a series resistor), you create a short circuit when the NTC resistance is low (hot temperatures). This can damage your board and provides no usable voltage measurement.
The voltage divider creates a measurable voltage midpoint that changes predictably with temperature.
The Voltage Divider Circuit Explained
Here's the correct circuit that OceanRemote uses for NTC thermistors:
COMPLETE NTC VOLTAGE DIVIDER CIRCUIT
3.3V (Reference Voltage)
│
▼
┌───┐
│NTC│ ← NTC Thermistor (resistance varies with temperature)
└───┘
│
├──────► ADC Pin (Voltage measured here)
│
┌───┐
│R │ ← Fixed Series Resistor (R_series, typically 10kΩ)
│SER│
└───┘
│
GND
Vout = 3.3V × (R_series) / (R_NTC + R_series)
Where:
- Vout = Voltage at ADC pin (0 to 3.3V)
- R_NTC = Resistance of NTC (changes with temperature)
- R_series = Fixed resistor value (you choose this)
How It Works Step by Step:
- Cold Temperature (High Resistance): R_NTC is large (e.g., 100kΩ at -10°C). The voltage divider outputs a low voltage because most voltage drops across the NTC.
- Room Temperature (Medium Resistance): R_NTC ≈ 10kΩ at 25°C. The voltage divider outputs about 1.65V (half of 3.3V).
- Hot Temperature (Low Resistance): R_NTC is small (e.g., 1kΩ at 100°C). The voltage divider outputs a high voltage close to 3.3V.
Think of the voltage divider as a seesaw. The NTC and series resistor are fighting for voltage. When the NTC wins (high resistance), the ADC sees low voltage. When the series resistor wins (NTC low resistance), the ADC sees high voltage.
The Math: Calculating Resistance from Voltage
OceanRemote firmware uses this formula to calculate R_NTC from the measured voltage:
From the voltage divider formula: Vout = 3.3V × (R_series) / (R_NTC + R_series) Rearrange to solve for R_NTC: R_NTC = R_series × (3.3V / Vout - 1) Example calculation: - 3.3V reference - R_series = 10,000Ω - Measured Vout = 1.65V R_NTC = 10000 × (3.3 / 1.65 - 1) R_NTC = 10000 × (2 - 1) R_NTC = 10000 × 1 R_NTC = 10,000Ω (which matches 25°C, as expected!)
ADC Reading to Voltage Conversion
The ADC doesn't read voltage directly - it reads a digital number (counts). Different boards have different resolutions:
| Board | ADC Resolution | ADC Range | Voltage per Count |
|---|---|---|---|
| ESP8266 (D1 Mini/Large) | 10-bit | 0 - 1023 | 3.225 mV |
| ESP32 | 12-bit | 0 - 4095 | 0.805 mV |
| Raspberry Pi Pico W | 12-bit | 0 - 4095 | 0.805 mV |
Converting ADC reading to voltage: For ESP8266 (10-bit): Voltage = (ADC_reading × 3.3V) / 1023 For ESP32 and Pico W (12-bit): Voltage = (ADC_reading × 3.3V) / 4095 Example (ESP32 reading 2048): Voltage = (2048 × 3.3) / 4095 = 1.65V
Choosing the Right Series Resistor (R_series)
The choice of R_series is critical for measurement accuracy. It determines which temperature range gives the best resolution.
The Golden Rule:
For best accuracy, choose R_series equal to the NTC's resistance at the center of your target temperature range.
| Application | Temperature Range | NTC at Center | Recommended R_series |
|---|---|---|---|
| Room / Ambient | 15°C - 35°C | ~10kΩ (at 25°C) | 10kΩ |
| Refrigerator / Cold | -10°C - 10°C | ~25kΩ (at 0°C) | 22kΩ or 33kΩ |
| Hot / Advanced | 50°C - 100°C | ~3.5kΩ (at 75°C) | 3.3kΩ or 4.7kΩ |
| Body Temperature | 30°C - 40°C | ~7kΩ (at 37°C) | 6.8kΩ or 10kΩ |
| General Purpose | -20°C - 80°C | ~10kΩ | 10kΩ (best all-around) |
OceanRemote's device configuration defaults to R_series = 10,000Ω. This works well for most applications (0°C to 70°C). Change this value in the "Series Resistor" field when generating firmware for specialized temperature ranges.
ADC Resolution: 10-bit vs 12-bit Explained
The number of bits determines how finely the ADC can measure voltage. More bits = better temperature resolution.
ESP8266 (10-bit ADC):
- 1024 possible values (0 to 1023)
- Each step represents about 0.003225V (3.225mV)
- Temperature resolution: approximately 0.25°C to 0.5°C per step
- Good enough for most hobby projects
ESP32 and Pico W (12-bit ADC):
- 4096 possible values (0 to 4095)
- Each step represents about 0.000805V (0.805mV)
- Temperature resolution: approximately 0.06°C to 0.1°C per step
- 4x better resolution than ESP8266
Temperature Resolution Comparison (at 25°C, 10kΩ NTC, 10kΩ R_series): ESP8266 (10-bit): - ADC step size: 3.225mV - Temperature change per step: ~0.35°C - You'll see temperature changes in ~0.3-0.5°C increments ESP32 / Pico W (12-bit): - ADC step size: 0.805mV - Temperature change per step: ~0.09°C - You'll see temperature changes in ~0.1°C increments (much smoother!)
For room temperature monitoring, both work fine. For precise measurements (scientific, medical, fermentation), the ESP32 or Pico W's 12-bit ADC is noticeably better.
Optimizing Your Voltage Divider for Accuracy
1. Use 1% Precision Resistors
The series resistor's tolerance directly affects accuracy. A 5% carbon resistor can cause ±0.5°C error. Use 1% metal film resistors for better results.
Error Example: R_series labeled as 10,000Ω but actually 10,500Ω (+5% tolerance) Actual Vout at 25°C: 3.3V × 10500 / (10000 + 10500) = 1.69V Expected Vout at 25°C: 1.65V The 0.04V difference causes ~0.5°C temperature error!
2. Add a Capacitor for Noise Filtering
ADC readings can be noisy, especially with long wires. Add a 0.1μF ceramic capacitor between the ADC pin and GND.
Improved Circuit with Noise Filtering:
3.3V
│
▼
┌───┐
│NTC│
└───┘
│
├──────► ADC Pin
│
┌───┐ ┌───┐
│R │ │0.1│ ← Capacitor (filters high-frequency noise)
│SER│ │μF │
└───┘ └───┘
│ │
GND GND
3. Use Averaging in Firmware
OceanRemote firmware automatically averages 5 ADC readings to reduce noise. This gives more stable temperature readings.
4. Keep Wires Short
Long wires act as antennas and pick up electrical noise. Keep NTC wires under 50cm (20 inches) for best results. For longer runs, use shielded cable.
Common Voltage Divider Mistakes
Wrong: ADC pin → NTC → GND (missing R_series)
Problem: The ADC will always read 0V (short to GND). No temperature data.
Fix: Add the series resistor between ADC and GND as shown in the diagram.
Wrong: 3.3V → NTC → ADC (missing R_series to GND)
Problem: The ADC will always read 3.3V (connected directly to power). No temperature data.
Fix: Add the series resistor between ADC and GND.
Wrong: Using 5V as the voltage divider reference
Problem: ESP8266/ESP32/Pico W ADC pins are NOT 5V tolerant! You'll damage your board.
Fix: Always use 3.3V as the reference voltage.
Problem: Using 1kΩ when you need 10kΩ (or vice versa)
Symptom: ADC readings are near 0 or near maximum across your entire temperature range, giving poor resolution.
Fix: Calculate the expected voltage range. You want Vout to span most of the 0-3.3V range across your temperatures.
Calculating Optimal R_series for Your Application
Here's how to calculate the best R_series value for your specific temperature range:
Step 1: Find R_NTC at your minimum temperature (T_min) and maximum temperature (T_max)
Using the Beta equation: R(T) = R25 × exp(β × (1/T - 1/298.15))
Step 2: Calculate Vout at both extremes:
Vout_min = 3.3V × R_series / (R_NTC_max + R_series)
Vout_max = 3.3V × R_series / (R_NTC_min + R_series)
Step 3: Choose R_series so that Vout_min is close to 0V and Vout_max is close to 3.3V
The optimal R_series is the geometric mean: R_series = √(R_NTC_min × R_NTC_max)
Example for 0°C to 50°C range (NTC β=3950, R25=10kΩ):
- R_NTC at 0°C ≈ 32,000Ω
- R_NTC at 50°C ≈ 3,600Ω
- Optimal R_series = √(32000 × 3600) = √115,200,000 ≈ 10,700Ω
So 10kΩ is very close to optimal!
Testing Your Voltage Divider
Before connecting to your microcontroller, test the voltage divider with a multimeter:
- Build the circuit on a breadboard (3.3V → NTC → ADC point → R_series → GND)
- Power the circuit with 3.3V from your board or a bench supply
- Measure voltage between the ADC point and GND
- At room temperature (~25°C), you should read approximately 1.65V (half of 3.3V)
- Warm the NTC with your finger - voltage should increase (toward 3.3V)
- Cool the NTC with ice in a bag - voltage should decrease (toward 0V)
If you're not getting voltage changes when touching the NTC, your wiring is wrong. The voltage should change noticeably (0.1-0.5V) with body heat.
Board-Specific ADC Considerations
ESP8266 (D1 Mini / D1 Large)
- ADC Pin: A0 only (one analog input)
- Range: 0-1V default! (Yes, this is a common trap)
- Fix for 0-3.3V range: Use voltage divider or set ADC mode
ESP8266 ADC Voltage Range Note: By default, the ESP8266 ADC measures 0-1V (not 0-3.3V like other boards). To measure 0-3.3V, you need to: - Use a voltage divider on the input (not recommended, reduces accuracy) - Or use `analogRead(A0)` and multiply by a calibration factor OceanRemote firmware handles this automatically for ESP8266 boards!
ESP32
- ADC Pins: GPIO32-39 (but GPIO34-39 are input-only!)
- Best Pins for NTC: GPIO36 (VP) or GPIO39 (VN) - better linearity
- ADC Attenuation: Set to 11dB for 0-3.3V range (OceanRemote does this)
- Non-linearity: ESP32 ADC is slightly non-linear near extremes
Raspberry Pi Pico W
- ADC Pins: GP26 (ADC0), GP27 (ADC1), GP28 (ADC2)
- Best Pin for NTC: GP26 (ADC0) - default in OceanRemote
- ADC Quality: Excellent linearity, best among the three boards
- Internal Reference: 3.3V, very stable
| Board | Best ADC Pin | Notes |
|---|---|---|
| ESP8266 D1 Mini/Large | A0 | Only analog pin available |
| ESP32 | GPIO36 (VP) or GPIO39 (VN) | Better linearity than GPIO34-35 |
| Raspberry Pi Pico W | GP26 (ADC0) | Excellent linearity, 12-bit |
Complete Example: Calculating Temperature from Voltage Divider
Complete walkthrough from ADC reading to temperature: Given: - Board: ESP32 (12-bit ADC, 0-4095 range) - NTC: 10kΩ @ 25°C, β = 3950 - R_series = 10,000Ω - ADC reading = 2048 Step 1: Convert ADC to voltage Voltage = (2048 × 3.3V) / 4095 = 1.65V Step 2: Calculate NTC resistance R_NTC = R_series × (3.3V / Vout - 1) R_NTC = 10000 × (3.3 / 1.65 - 1) R_NTC = 10000 × (2 - 1) R_NTC = 10,000Ω Step 3: Convert resistance to temperature (Steinhart-Hart) logR = ln(10000) = 9.21034 kelvin = 1 / (0.001129241 + 0.0002341077 × 9.21034 + 0.0000000877541 × 9.21034³) kelvin = 1 / (0.001129241 + 0.002156 + 0.0000686) kelvin = 1 / 0.0033538 kelvin = 298.15K celsius = 298.15 - 273.15 = 25.0°C ✓
Next Steps
Now that you understand the voltage divider circuit, continue with:
- Tutorial 20: Calibrating Temperature Sensors with Offset
- Tutorial 18: NTC 10kΩ Thermistor Complete Guide (if you haven't read it)
- Return to Tutorial 02: Generate firmware with NTC support using your chosen R_series value
The voltage divider is essential for converting the NTC's changing resistance into a measurable voltage. Choose R_series = 10kΩ for general use, use 1% resistors for accuracy, and remember that ESP32/Pico W give 4x better resolution than ESP8266. Test your circuit with a multimeter before connecting to your board!