ESP32-S3 Lab · Day 18 of 30

Turn heat into
a number

Today you build a thermometer. A thermistor changes its resistance as the air around it warms or cools, and the ESP32-S3 reads that change and prints the temperature once a second. Its resistance follows a curve rather than a straight rule, so the sketch carries a short formula to read it honestly. Pinch the little bead and watch the number climb — the same sensing that tells a skipper the engine room is running warm.

About 25 minutesArduino firstMicroPython optionalNo electronics assumed
Agent assist code TSK-DAY18-THERMOMETER

Hand this to an agent so it can pull the lesson packet and coach you step by step.

01 First, know the pieces

What you need

Six things, nothing more. Tap Define on any part you haven't met — the answer opens as a field note you can read and dismiss without losing your place.

Official manual photo of the ESP32-S3 development board.
Manual photo

ESP32-S3 board

The brain that runs your uploaded sketch.

Official manual image of the ESP32-S3 GPIO extension board.
Manual photo

GPIO extension board

Spreads the pins into rows you can reach and label.

Official manual photo of a bead thermistor with two long legs.
Manual photo

Thermistor

A small bead whose resistance falls as it warms — today's sensor.

Official manual photo of a resistor with coloured value bands.
Manual photo

10 kΩ resistor

The steady half of the divider that turns resistance into voltage.

Official manual image of a jumper wire.
Manual photo

3 jumper wires

Temporary, solder-free connections.

Official manual screenshot of the Arduino IDE interface.
Manual screenshot

Arduino IDE

Uploads code and opens Serial Monitor.

02 Make the physical circuit

Chart the circuit

The official Freenove diagram is your chart — schematic on top, the same circuit built on a breadboard below. Click it to enlarge. Two parts in a line make the divider; one wire taps its midpoint.

Official Freenove circuit — C Tutorial, Chapter 12 (Thermistor), page 123.
10 kΩ resistor leg 3.3V Feeds the divider from a steady 3.3 volts.
Divider midpoint GPIO 1 The ADC pin reads the voltage where resistor meets thermistor.
Thermistor far leg GND Completes the divider's path back to zero volts.

Check before power. The thermistor has no polarity — either leg can face either way — but the midpoint wire must land on GPIO 1. Unplug USB before you move any wire.

03 One action at a time

Build it

This is the main path — you can finish the day without opening a single field note. Tap each step as you go to keep your place.

0 / 10 done
  1. Seat the ESP32-S3 on the GPIO extension board and keep USB unplugged while you wire.

  2. Push the thermistor into the breadboard with its two legs in separate rows.

  3. Place the 10 kΩ resistor so one leg shares a row with one thermistor leg — that shared row is the divider's midpoint.

  4. Run a jumper from 3.3V to the resistor's free leg.

  5. Run a jumper from the midpoint row to GPIO 1.

  6. Run a jumper from the thermistor's free leg to GND.

  7. Compare every wire to the chart, then plug in USB.

  8. Open Sketch_12.1_Thermometer.ino in Arduino IDE and upload it.

  9. Open Serial Monitor and set the baud rate to 115200.

  10. Pinch the thermistor's bead between two fingers and watch the temperature climb.

Degrees on deck.

Your board is reading real temperature once a second. Head to Test & debug to confirm the numbers make sense.

04 Read just enough code

Read the code

The whole loop is four working lines — a chain that walks from a raw ADC count to volts, to ohms, to degrees. Switch to MicroPython if you'd rather see the same chain in Python; the wiring never changes.

Sketch_12.1_Thermometer.ino
#define PIN_ANALOG_IN   1
void setup() {
  Serial.begin(115200);
}

void loop() {
  int adcValue = analogRead(PIN_ANALOG_IN);                       //read ADC pin
  double voltage = (float)adcValue / 4095.0 * 3.3;                // calculate voltage
  double Rt = 10 * voltage / (3.3 - voltage);                     //calculate resistance value of thermistor
  double tempK = 1 / (1 / (273.15 + 25) + log(Rt / 10) / 3950.0); //calculate temperature (Kelvin)
  double tempC = tempK - 273.15;                                  //calculate temperature (Celsius)
  Serial.printf("ADC value : %d,\tVoltage : %.2fV, \tTemperature : %.2fC\n", adcValue, voltage, tempC);
  delay(1000);
}
analogRead(PIN_ANALOG_IN)Reads the divider midpoint on GPIO 1 as a number from 0 to 4095.
double Rt = 10 * voltage / (3.3 - voltage)Works the divider maths backwards to recover the thermistor's resistance in kilo-ohms.
log(Rt / 10) / 3950.0The B-equation — B is 3950 for this bead — maps that resistance onto temperature in Kelvin; subtracting 273.15 lands it in Celsius.

05 Understand, don't memorise

One curved sensor, four honest lines

Every analog sensor so far handed the ADC a signal you could rescale with a straight line: map() stretched one range onto another and the job was done. The thermistor asks for more. Its resistance follows a curve against temperature, where the potentiometer and photoresistor tracked something close to a straight line — so a plain rescale would land the right degrees at one point and drift away on either side. The sketch walks one reading through four steps instead, and the last step uses a logarithm to follow that curve.

Read

Count from the pin

analogRead samples the divider midpoint on GPIO 1 and returns a count from 0 to 4095. That single number is the whole input.

Volts

Count to voltage

Dividing the count by 4095 and scaling by 3.3 recovers the real voltage sitting at the midpoint, in volts.

Ohms

Voltage to resistance

Running the divider maths backwards, Rt = 10 * V / (3.3 - V) recovers the thermistor's own resistance in kilo-ohms from that voltage.

Degrees

Resistance to degrees

The B-equation feeds that resistance through a logarithm to reach Kelvin, then subtracting 273.15 lands it in Celsius. This curved step is the one the logarithm exists to handle.

The chain ADC count → voltsohmsdegrees — and the last arrow follows a curve, so it takes a logarithm

Why this one needs a formula

map() draws a straight line between two points, ideal when a sensor rises evenly across its range. A thermistor's resistance follows a curve as it heats, so a straight rescale would match the real temperature at a single point and wander off on either side. The B-equation carries a logarithm that follows the curve, keeping the reading honest from cold to warm.

Why resistance moves with heat

A thermistor is made of a material whose electrons flow more freely as it warms, so its resistance drops as temperature rises. At 25 °C this bead sits near 10 kΩ, which is why the sketch's reference values are built around 10 and 25.

What the 10 kΩ partner does

The ADC measures voltage, and the thermistor only offers a changing resistance. Stacking the fixed 10 kΩ resistor above it makes a divider whose midpoint voltage tracks that resistance — the one form the pin can actually read.

06 Know it worked

Test & debug

Success and recovery sit side by side, so you never have to go hunting when something looks off.

What you should see
Serial Monitor115200 baud
ADC value : 2185, Voltage : 1.76V, Temperature : 22.00CADC value : 2100, Voltage : 1.69V, Temperature : 23.85CADC value : 2048, Voltage : 1.65V, Temperature : 24.99C

A steady room line first — somewhere around 20 to 26 °C. Pinch the bead and the temperature climbs a few degrees; let go and it eases back down.

If it doesn't
  • Temperature wildly wrong — near -273 or nan? Check the midpoint wire on GPIO 1 and that the 10 kΩ resistor is in the divider.
  • Values frozen while you pinch? Reseat the thermistor's legs — one has likely lifted out of its row.
  • Garbled text? Set Serial Monitor to 115200 baud to match the sketch.
  • Upload fails? Swap in a data-capable USB cable.

07 Make the idea yours

Try this: watch the whole chain move

The printout already shows all three links at once — the raw ADC count, the voltage, and the temperature. Warming the bead lets you watch them move together and trace why. It fits inside today's 25 minutes.

Warm it and watch three numbers

Let the reading settle at room temperature, then pinch the bead between two fingers. Watch the ADC value and the voltage drop while the temperature rises, and let go to see them ease back. Every printed line carries all three at once.

Trace it back through resistance

A warmer bead means lower resistance, which pulls the divider midpoint down — fewer volts, fewer ADC counts. The formula reads that lower resistance as a higher temperature, so the count falling and the degrees rising are one event seen at two ends of the chain.

08 Learn it with a hand on the tiller

Coach me through it

Every lesson ships with a code and a machine-readable packet, so an agent can guide you with full context.

Lesson code

TSK-DAY18-THERMOMETER

How the agent should behave: guide one physical connection at a time, wait for you to confirm, and use the printed ADC, voltage, and temperature fields to teach the count-to-resistance-to-degrees chain — including why a thermistor's curve takes a formula where earlier sensors used map(). Always check wiring, board, port, and USB before changing code.

Keep your place

Finished Day 18?

Mark it complete — it shows on your course map, and your place is saved on this device.

Field note

Shortcut

Prompt copied