Boiler thermostat

Holds the temperature of a boiler or heating loop with DS18B20 probes and a relay on the boiler's thermostat input.

Climate & heating Board: ESP32 DevKit V1 (WROOM-32) Level: ●●○ ⏱ 2–3 h

⛔ High risk

Never replace the boiler's own safety thermostat or overheat protection. The ESP32 is only an extra controller; use a certified relay and a fuse.

🛒 Ready kit in the shop

Ask the boiler for heat, do not take its place

The safest way to automate a gas or electric boiler is to wire the relay in parallel with its room-thermostat input. Then the ESP32 can only request heat; if it hangs, the boiler’s own limiter and thermostat keep working. Before anything else, read the boiler manual: some inputs are a dry contact, some carry 24 V or even 230 V, and some boilers use OpenTherm instead, which a plain relay cannot drive.

Control logic

DS18B20 probes need a 4.7 kΩ pull-up and a waterproof housing. Strap one to the supply pipe with insulation on top, and keep in mind that the pipe wall lags the water by a minute or two. Use a hysteresis of about half a degree and a minimum on-time and off-time of several minutes, so the boiler does not short-cycle.

  • Log the room and the supply temperature. A graph shows in a week whether the boiler is oversized.
  • If a probe fails, the sketch should fall back to "no request" and send a message.
  • This is a comfort controller. Safety devices of the boiler must stay exactly as the manufacturer made them.

Components

  • ESP32 DevKit V1 (30 pin, WROOM-32)
  • DS18B20 waterproof probe × 2
  • Relay module 1-channel 5V (opto-isolated)
  • Resistor kit 1/4W (1k, 2k, 4.7k, 10k, 22k, 100k)
  • USB charger 5V 2A

Wiring

Module Module pin ESP32 pin Note
DS18B20 DATA 1-Wire GPIO4 4.7 kΩ pull-up to 3V3
DS18B20 VCC / GND 3V3 / GND
Relay IN signal GPIO26 dry contact to the boiler thermostat input

Libraries

  • OneWire
  • DallasTemperature

Code

#include <WiFi.h>

const char* WIFI_SSID = "YOUR_WIFI";
const char* WIFI_PASS = "YOUR_PASSWORD";

bool connectWiFi(uint32_t timeoutMs = 20000) {
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  uint32_t t0 = millis();
  while (WiFi.status() != WL_CONNECTED && millis() - t0 < timeoutMs) {
    delay(250);
    Serial.print(".");
  }
  Serial.println();
  if (WiFi.status() == WL_CONNECTED) {
    Serial.print("IP: ");
    Serial.println(WiFi.localIP());
    return true;
  }
  return false;
}
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire ow(4);
DallasTemperature ds(&ow);
#include <WebServer.h>

WebServer server(80);
String buildJson();   // implemented in the project below

String num(float v, int d = 1) { return isnan(v) ? String("null") : String(v, d); }

const char PAGE_HTML[] PROGMEM = R"rawliteral(
<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>ESP32</title>
<style>body{font-family:system-ui;background:#0b0f14;color:#e6edf3;margin:20px}table{border-collapse:collapse}td{padding:6px 14px;border-bottom:1px solid #223}button,input{font-size:16px;padding:8px 14px;margin:4px;border-radius:6px;border:1px solid #345;background:#16202b;color:#e6edf3}</style>
</head><body><h2>ESP32</h2><table id="t"></table>
float setpoint = 21.0, hyst = 0.5, temp = NAN;
bool heat = false;
String buildJson() { return String("{"temp":") + num(temp) + ","setpoint":" + num(setpoint) + ","heating":" + (heat ? "true" : "false") + "}"; }
<script>
function load(){fetch('/json').then(r=>r.json()).then(d=>{let h='';for(const k in d){h+='<tr><td>'+k+'</td><td>'+d[k]+'</td></tr>';}document.getElementById('t').innerHTML=h;});}
load();setInterval(load,2000);
</script></body></html>
)rawliteral";

void startWeb() {
  server.on("/", []() { server.send_P(200, "text/html", PAGE_HTML); });
  server.on("/json", []() { server.send(200, "application/json", buildJson()); });
  server.begin();
}
const int PIN_RELAY = 26;  // active LOW
void setup() {
  pinMode(PIN_RELAY, OUTPUT); digitalWrite(PIN_RELAY, HIGH);
  Serial.begin(115200);
  ds.begin();
  connectWiFi();
  server.on("/set", []() { if (server.hasArg("t")) setpoint = constrain(server.arg("t").toFloat(), 5, 30); server.send(200, "text/plain", "ok"); });
  startWeb();
}
void loop() {
  server.handleClient();
  static uint32_t t = 0;
  if (millis() - t > 5000) {
    t = millis(); ds.requestTemperatures(); float v = ds.getTempCByIndex(0);
    if (v > -100) { temp = v; if (!heat && temp < setpoint - hyst) heat = true; if (heat && temp > setpoint + hyst) heat = false; }
    else heat = false;                       // sensor fault → heating request off, the boiler's own safety stays in charge
    digitalWrite(PIN_RELAY, heat ? LOW : HIGH);
  }
}

Build tips

  • Mount the probe at 1.5 m height, away from radiators and sunlight.
  • The relay contacts must go to the boiler’s low-voltage thermostat terminals (dry contact).

What you need

Buy the parts kit · Estimated total: $14.00

ESP32 DevKit V1 (30 pin, WROOM-32) × 1
$4.00
Buy at AliExpress Buy at Amazon.com
DS18B20 waterproof probe × 2
$3.00
Buy at AliExpress Buy at Amazon.com
Relay module 1-channel 5V (opto-isolated) × 1
$1.50
Buy at AliExpress Buy at Amazon.com
Resistor kit 1/4W (1k, 2k, 4.7k, 10k, 22k, 100k) × 1
$1.50
Buy at AliExpress Buy at Amazon.com
USB charger 5V 2A × 1
$4.00
Buy at AliExpress Buy at Amazon.com
🇺🇦 Ukraine🌍 Other countries

Other countries: order these parts on AliExpress with the links below.

Some links are affiliate links: we may earn a commission at no extra cost to you.

Related ideas

⛔ High risk

Mains 220–230 V can kill. Work with the power off, use certified isolated modules in an enclosure, fuse the line, and ask a qualified electrician if you are not sure.

Floor heating controller

Controls an electric floor or heater with a solid-state relay, floor and room probes and a schedule.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●● Advanced
  • Build time 3–5 h
Pick parts / kit
⛔ High risk

Never replace the boiler's own safety thermostat or overheat protection. The ESP32 is only an extra controller; use a certified relay and a fuse.

Solid-fuel boiler controller

Controls the draft fan and circulation pump by flue-gas and water temperature, with overheat and CO warnings.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●● Advanced
  • Build time 4–6 h
Pick parts / kit
⚠ Caution

Switch only low-voltage loads yourself. For mains loads use a certified isolated module in a box or call an electrician.

Greenhouse vent and irrigation controller

Opens the vent or starts the fan by temperature and humidity, checks the soil moisture, and keeps a daily log for the whole season.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●○ Intermediate
  • Build time 2–3 h
Pick parts / kit

← All module ideas →

Comments

No comments yet. Share your experience or ask a question.

Comments are moderated.