The first reading
Three wires, no library and a sketch that prints the raw count twice a second. At room temperature an Uno prints a little over 512; put a fingertip on the thermistor and the number falls, because warmer means a lower voltage.
Three wires
GND to GND. VCC to your board's logic supply: 5V on an Uno, 3V3 on the three 3.3 V boards. SIGNAL to an analog pin. NC stays unconnected.
The analog pin is the same in every sketch in this book: A0 on an Uno, GPIO 34 on an ESP32, GPIO 4 on an ESP32-S3, GP26 on a Pico. The two ESP32 pins are on ADC1, the converter that keeps working when Wi-Fi is on. Any other analog pin works too, as long as on an ESP32 it is an ADC1 pin.
The sketch
One call does the work. analogRead(SENSOR_PIN) measures the voltage on the
pin and returns it as a count. On an Uno and a Pico that is 0 to 1023; on an
ESP32 and ESP32-S3, 0 to 4095.
There is no pinMode. An analog pin does not need one to be read, and there
is nothing for the chip to pull up or down: the block drives SIGNAL itself.
What you should see
On an Uno, at room temperature, the serial monitor at 115200 prints a count a little above 512, because a room is usually a little under 25 °C. Put a fingertip on the thermistor, the part in the box at the top, and watch:
count 534
count 534
count 521
count 498
count 481
count 470The number falls, and keeps falling for several seconds after you touch it. Take the finger away and it climbs back, more slowly. Your numbers will differ; the direction will not.
On an ESP32 the numbers are bigger, out of 4095, and they are not a fraction of VCC. That difference is the subject of reading it on an ESP32. The direction is the same everywhere: warmer, lower.
The code
No library. analogRead returns SIGNAL as a count: 0 to 1023 on an Uno and a Pico, 0 to 4095 on an ESP32. Change SENSOR_PIN to the pin you wired SIGNAL to.
/*
NTC Thermistor - first reading TK12 / /p/tk12
Wiring. Count from the square pad on the TinkerBlock board, parts
up, header at the bottom:
GND -> GND
VCC -> 5V on an Uno; 3V3 on an ESP32, ESP32-S3 or Pico
(SIGNAL is a fraction of VCC, so it stays in range)
NC -> nothing (unconnected on the board)
SIGNAL -> A0 on an Uno, GPIO 34 on an ESP32, GPIO 4 on an
ESP32-S3, GP26 on a Raspberry Pi Pico
Arduino IDE
Tools > Board your board, e.g. Arduino Uno
Tools > Port the one that appears when you plug in
Tools > USB CDC On Boot Enabled (ESP32-S3 only)
No library needed.
*/
// The analog pin SIGNAL is wired to.
// Uno: A0. ESP32: 34. ESP32-S3: 4. Pico: 26.
const int SENSOR_PIN = A0;
void setup() {
Serial.begin(115200);
}
void loop() {
int count = analogRead(SENSOR_PIN); // warmer means lower
Serial.print("count ");
Serial.println(count);
delay(500); // twice a second
}The count is not a temperature yet, and on an ESP32 it is not even a fraction of VCC. It is here to show the direction: warm the thermistor and it falls. The next article turns it into degrees.
The same reading in MicroPython, for an ESP32, an ESP32-S3 or a Pico. read_u16 returns SIGNAL as a count from 0 to 65535 on all three.
"""
NTC Thermistor - first reading, MicroPython TK12 / /p/tk12
Wiring. Count from the square pad on the TinkerBlock board, parts
up, header at the bottom:
GND -> GND
VCC -> 3V3 (SIGNAL is a fraction of VCC)
NC -> nothing (unconnected on the board)
SIGNAL -> GPIO 34 on an ESP32, GPIO 4 on an ESP32-S3,
GP26 on a Raspberry Pi Pico
Thonny
Run > Configure interpreter MicroPython (ESP32) or
MicroPython (Raspberry Pi Pico)
Save it to the board as main.py to run it on every power-up.
Nothing to install: machine, sys and time are built in.
"""
import sys
import time
from machine import ADC, Pin
# The GPIO number SIGNAL is wired to. ESP32: 34. ESP32-S3: 4. Pico: 26.
SENSOR_PIN = 4
adc = ADC(Pin(SENSOR_PIN))
if sys.platform == "esp32": # ESP32 and ESP32-S3
adc.atten(ADC.ATTN_11DB) # the full range, to about 3.1 V
while True:
print("count", adc.read_u16()) # warmer means lower
time.sleep_ms(500)There is no Uno here: an Uno cannot run MicroPython. On an ESP32 the atten line widens the ADC's range to about 3.1 V, without which it stops near 1 V and a room-temperature SIGNAL is off the top. The Pico's ADC has no such setting. Stop it with Ctrl-C.
When it does not work
SIGNAL is at 0 V, which means the divider has no supply. VCC is not connected, or the cable is one pin over. Count from the square pad: GND, VCC, NC, SIGNAL. A pin number that names an unused analog pin can also read near 0.
1023 on an Uno, 4095 on an ESP32. SIGNAL is at VCC, which means the thermistor has nothing to pull against: GND is not connected. On an ESP32 a very cold block reads the maximum too, but a room is nowhere near cold enough.
Then SIGNAL is not what the sketch is reading. On this block a warm finger always lowers it. Check that SENSOR_PIN is the pin SIGNAL is on, and that the wire has not landed on VCC's pin.
Set Tools > USB CDC On Boot to Enabled and upload again. Without it the S3's USB port does not bring up a serial port at boot, so the sketch runs with nowhere to print.
The two lines of arithmetic between a count and a temperature.
Counts to degrees →Edit this page — content/books/ntc-thermistor/the-first-reading.mdx
Questions about this product
See what other owners have asked, and read their solutions.
NTC Thermistor
Loading discussions…
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.