Projects / ESP32-C3 water bath thermometer

ESP32-C3 water bath thermometer

Intermediate2.5 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32NTC10

    Build the divider

    10 kilo-ohm from 3V3 to GPIO2, probe from GPIO2 to GND.

  2. ESP32

    Edit the sketch

    Put your Wi-Fi name and password in the placeholders.

  3. ESP32

    Upload it

    The Serial Monitor prints an address like http://192.168.1.45.

  4. ESP32

    Open the address

    On a phone on the same network.

  5. ESP32NTC10

    Put the probe in a cup of warm water

    The temperature rises.

  6. ESP32

    Leave it for a few minutes

    The graph starts to draw.

  7. ESP32

    Keep the board dry

    Well away from the cup.

In short

How do you build an ESP32-C3 water bath thermometer?

An ESP32-C3 reads a waterproof NTC probe in a water bath and serves the temperature and a graph of the last hour on a local page. You need ESP32-C3 SuperMini, NTC 10 kΩ waterproof probe, Resistor 10 kΩ and Breadboard 830 Tie Points. It takes 7 steps and about 150 minutes.

Level
Intermediate
Time
About 150 min
Parts
4

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
10 kilo-ohm resistorESP32-C3 SuperMini 3V3 to GPIO2Top of the divider
NTC probe lead 1ESP32-C3 SuperMini GPIO2Middle of the divider
NTC probe lead 2ESP32-C3 SuperMini GNDBottom of the divider

Code

A waterproof NTC probe is a thermistor sealed in a stainless tube on a cable, so it can sit in water. As in the other thermistor builds, it forms a voltage divider with a fixed 10 kilo-ohm resistor, and the ESP32 reads the voltage in the middle. The program uses analogReadMilliVolts, which applies the chip's factory calibration, because the ESP32's raw converter is not very linear. The beta equation turns the resistance into degrees. Every thirty seconds it stores a reading in a ring of 120 values, which is the last hour, and when the page is opened it draws them as a graph in an SVG image, with the range printed below. This is a watching tool. Do not use it to switch mains heaters, which needs proper certified controllers. Keep the electronics and the USB lead well away from the water, put the probe only as deep as its rating allows, and keep the page on your home network.

Runs on a virtual ESP32-C3 in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <WiFi.h>
#include <WebServer.h>
#include <math.h>

const char* WIFI_NAME = "YOUR_WIFI_NAME";          // placeholders: use your own network
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";

const int NTC_PIN = 2;
const float R_FIXED = 10000.0, R0 = 10000.0, BETA = 3950.0, T0 = 298.15;

const int POINTS = 120;                            // one point every 30 seconds is the last hour
float history[POINTS];
int count = 0, head = 0;
unsigned long lastSample = 0;

WebServer server(80);

float readTemperature() {
  long sum = 0;
  for (int i = 0; i < 32; i++) { sum += analogReadMilliVolts(NTC_PIN); delay(2); }
  float ratio = (sum / 32.0) / 3300.0;             // the divider ratio, with the supply taken as 3.3 V
  if (ratio <= 0.001 || ratio >= 0.999) return NAN;
  float r = R_FIXED * ratio / (1.0 - ratio);
  float invT = 1.0 / T0 + log(r / R0) / BETA;
  return 1.0 / invT - 273.15;
}

String graph() {
  if (count < 2) return "";
  float lo = 1000, hi = -1000;
  for (int i = 0; i < count; i++) {
    int idx = (head - count + i + POINTS) % POINTS;
    lo = min(lo, history[idx]); hi = max(hi, history[idx]);
  }
  if (hi - lo < 1.0) { hi += 0.5; lo -= 0.5; }
  String pts = "";
  for (int i = 0; i < count; i++) {
    int idx = (head - count + i + POINTS) % POINTS;
    float x = 300.0 * i / (POINTS - 1);
    float y = 100.0 - 100.0 * (history[idx] - lo) / (hi - lo);
    pts += String(x, 1) + "," + String(y, 1) + " ";
  }
  return "<svg viewBox='0 0 300 100' width='90%' style='border:1px solid #888'><polyline fill='none' stroke='blue' stroke-width='1.5' points='" + pts + "'/></svg>"
         "<p>Graph range " + String(lo, 1) + " to " + String(hi, 1) + " &deg;C</p>";
}

void handleRoot() {
  float t = readTemperature();
  String page = "<!DOCTYPE html><html><head><meta charset='utf-8'>";
  page += "<meta name='viewport' content='width=device-width, initial-scale=1'>";
  page += "<meta http-equiv='refresh' content='30'><title>Water bath</title></head>";
  page += "<body style='font-family:sans-serif;text-align:center;margin-top:2em'>";
  page += "<h1>Water bath</h1><p style='font-size:3em'>" + (isnan(t) ? String("--") : String(t, 1)) + " &deg;C</p>";
  page += graph() + "<p>Last hour, one point every 30 seconds</p></body></html>";
  server.send(200, "text/html", page);
}

void setup() {
  Serial.begin(115200);
  analogReadResolution(12);
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_NAME, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print('.'); }
  Serial.println();
  Serial.print("Open http://");
  Serial.println(WiFi.localIP());
  server.on("/", handleRoot);
  server.begin();
}

void loop() {
  server.handleClient();
  if (millis() - lastSample >= 30000UL) {
    lastSample = millis();
    float t = readTemperature();
    if (!isnan(t)) {
      history[head] = t;
      head = (head + 1) % POINTS;
      if (count < POINTS) count++;
    }
  }
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual ESP32-C3 DevKitM-1 with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

....
Open http://192.168.1.42

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Probe in room airRoom temperature
Probe in warm waterRises quickly then settles
Probe in cool waterFalls
After five minutesA line appears on the graph
ReadingWithin a degree or two of a good thermometer

If it does not work

Shows two dashes

The ratio is out of range, check the wiring of the divider.

Reads high or low

Check the fixed resistor value and the probe's beta number.

Dots never stop

Check the Wi-Fi name and password, and that the network is 2.4 GHz.

Graph is blank

Wait for two samples, one minute.

Noisy readings

Keep the probe leads away from the Wi-Fi antenna and from the USB lead.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the ESP32-C3 water bath thermometer?

ESP32-C3 SuperMini, NTC 10 kΩ waterproof probe, Resistor 10 kΩ and Breadboard 830 Tie Points.

How long does the ESP32-C3 water bath thermometer take to build?

About 150 minutes for a intermediate maker, in 7 steps.

How do I know the ESP32-C3 water bath thermometer works?

Probe in room air: Room temperature. Probe in warm water: Rises quickly then settles. Probe in cool water: Falls.

Shows two dashes: what should I check?

The ratio is out of range, check the wiring of the divider.

Reads high or low: what should I check?

Check the fixed resistor value and the probe's beta number.

Dots never stop: what should I check?

Check the Wi-Fi name and password, and that the network is 2.4 GHz.

Graph is blank: what should I check?

Wait for two samples, one minute.