NTC thermistor/Reading it/05. The first reading
Reading it · 05 of 12

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

Three wires
Your board
Wires
3
VCC to
5V
SIGNAL to
A0
GND to GND, VCC to 5V, SIGNAL to A0. A0 is the first of the Uno's six analog inputs. Its ADC measures against the same 5 V that feeds the block, which is why the Uno is the easy case.

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 470

The 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_first_reading.ino
/*
  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.

When it does not work

It prints 0 all the time.

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.

It prints the maximum all the time.

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.

The number goes up when I touch it.

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.

The serial monitor stays empty on my ESP32-S3.

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.

Where this goes next

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

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

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.

Browse Modules and blocks on the forum