Water pump dry-run and pressure guard

Acts as a pressure switch with dry-run, burst pipe and maximum run-time protection and sends alerts to Telegram.

Level: Advanced Board: ESP32 DevKit V1 (WROOM-32) Water & garden

⚠ Safety

Mains voltage can kill. Use certified isolated modules in an enclosure, fuse and RCD the circuit, switch the power off before wiring, and ask a qualified electrician if you are unsure. Check the rules for your country.

What you need

Buy the parts kit · Estimated total: $28.00

ESP32 DevKit V1 (30 pin, WROOM-32) × 1
$4.00
Buy at AliExpress Buy at Amazon.com
Water pressure transducer 0.5-4.5 V (G1/4, 0-1.2 MPa) × 1
$6.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
DIN contactor 25A with 230V coil × 1
$12.00
Buy at AliExpress Buy at Amazon.com
Inline fuse holder + fuses × 1
$1.50
Buy at AliExpress Buy at Amazon.com
Plastic project enclosure × 1
$3.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.

Wiring

ModuleModule pinESP32 pinNote
Pressure sensor + / GND5V / GND0.5-4.5 V output type
Pressure sensor OUT via 10k/20k divideranalogGPIO34 (ADC1)4.5 V becomes 3.0 V
Relay INsignalGPIO26relay drives the contactor COIL, not the pump directly
Contactorpowerpump 230 Vqualified person, fuse and RCD, enclosure

Code

pump-protect.ino
#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 <WiFiClientSecure.h>
#include <HTTPClient.h>

const char* TG_TOKEN = "123456:ABC-YOUR-BOT-TOKEN";   // from @BotFather
const char* TG_CHAT  = "YOUR_CHAT_ID";

// Keep the text free of double quotes and line breaks (it is inserted into JSON).
bool telegramSend(const String& text) {
  if (WiFi.status() != WL_CONNECTED) return false;
  WiFiClientSecure client;
  client.setInsecure();   // simple; pin the certificate for production
  HTTPClient http;
  String url = String("https://api.telegram.org/bot") + TG_TOKEN + "/sendMessage";
  if (!http.begin(client, url)) return false;
  http.addHeader("Content-Type", "application/json");
  String body = String("{\"chat_id\":\"") + TG_CHAT + "\",\"text\":\"" + text + "\"}";
  int code = http.POST(body);
  http.end();
  return code == 200;
}
#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>
<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_P = 34, PIN_RELAY = 26;
const float BAR_FULL = 12.0;               // 1.2 MPa transducer = 12 bar at 4.5 V
const float P_ON = 2.0, P_OFF = 3.5;       // switch-on / switch-off pressure, bar
const float MIN_RISE = 0.3;                // required pressure rise within CHECK_MS
const uint32_t CHECK_MS = 20000, MAX_RUN_MS = 600000;
bool pumpOn = false, lockout = false; float bar = 0, barAtStart = 0; uint32_t startMs = 0;

float readBar() {
  long s = 0; for (int i = 0; i < 32; i++) { s += analogRead(PIN_P); delay(2); }
  float vAdc = (s / 32.0) * 3.3 / 4095.0, vSensor = vAdc * 1.5;   // divider 10k/20k
  return max(0.0f, (vSensor - 0.5f) / 4.0f * BAR_FULL);
}
void setPump(bool on) { pumpOn = on; digitalWrite(PIN_RELAY, on ? HIGH : LOW); if (on) { startMs = millis(); barAtStart = bar; } }
String buildJson() { return String("{\"bar\":") + num(bar, 2) + ",\"pump\":" + (pumpOn ? 1 : 0) + ",\"lockout\":" + (lockout ? 1 : 0) + "}"; }

void setup() {
  Serial.begin(115200); pinMode(PIN_RELAY, OUTPUT); analogReadResolution(12);
  connectWiFi(); startWeb();
  server.on("/reset", []() { lockout = false; server.send(200, "text/plain", "lockout cleared"); });
}
void loop() {
  server.handleClient(); bar = readBar();
  if (!lockout) {
    if (!pumpOn && bar < P_ON) setPump(true);
    if (pumpOn && bar > P_OFF) setPump(false);
    if (pumpOn && millis() - startMs > CHECK_MS && bar - barAtStart < MIN_RISE) { setPump(false); lockout = true; telegramSend("Pump stopped: dry run or burst pipe suspected"); }
    if (pumpOn && millis() - startMs > MAX_RUN_MS) { setPump(false); lockout = true; telegramSend("Pump stopped: maximum run time exceeded"); }
  }
  delay(200);
}

Flash a ready firmware from the browser Paste your error into the AI Error Doctor

Build tips

  • Fit a mechanical pressure switch or relief valve in parallel as a second line of protection.
  • Calibrate the pressure scale against a mechanical gauge.

← ← All projects

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.

3D printer enclosure guard

Temperature probe and smoke sensor inside the enclosure with an alarm, a message and an optional power cut for the printer.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●● Advanced
  • Build time 3–4 h
Pick parts / kit
⛔ 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.

Inverter load manager

Watches the inverter / battery current and switches off non-critical loads with a relay when the battery runs low.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●● Advanced
  • Build time 3–5 h
Pick parts / kit
⛔ 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.

Generator start and runtime controller

Starts and stops a generator through a relay, counts engine hours, watches the load with a current clamp and warns about carbon monoxide.

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

Comments

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

Comments are moderated.