Level: Intermediate Board: ESP32-C3 SuperMini Water & garden
⚠ Safety Low-voltage project, but check the supply polarity and the 3.3 V logic levels before connecting anything.
What you need Buy the parts kit · Estimated total: $14.00
ESP32-C3 SuperMini × 1
$2.50
Water pressure transducer 0.5-4.5 V (G1/4, 0-1.2 MPa) × 1
$6.00
Resistor kit 1/4W (1k, 2k, 4.7k, 10k, 22k, 100k) × 1
$1.50
USB charger 5V 2A × 1
$4.00
Some links are affiliate links: we may earn a commission at no extra cost to you.
Code water-outage.ino Copy Download .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;
}
const int PIN_P = 3;
const float BAR_FULL = 6.0; // 0-0.6 MPa transducer; use 12.0 for 1.2 MPa
const float LOW_BAR = 0.3;
const uint32_t CONFIRM_MS = 60000;
bool waterOff = false; uint32_t changeMs = 0, offSince = 0;
float readBar() {
long s = 0; for (int i = 0; i < 32; i++) { s += analogRead(PIN_P); delay(2); }
float vSensor = (s / 32.0) * 3.3 / 4095.0 * 1.5;
return max(0.0f, (vSensor - 0.5f) / 4.0f * BAR_FULL);
}
void setup() { Serial.begin(115200); analogReadResolution(12); connectWiFi(); }
void loop() {
if (WiFi.status() != WL_CONNECTED) connectWiFi(8000);
bool low = readBar() < LOW_BAR;
if (low != waterOff) {
if (changeMs == 0) changeMs = millis();
if (millis() - changeMs > CONFIRM_MS) {
waterOff = low; changeMs = 0;
if (waterOff) { offSince = millis(); telegramSend("Water supply is OFF"); }
else telegramSend(String("Water is back after ") + (millis() - offSince) / 60000 + " min");
}
} else changeMs = 0;
delay(2000);
}Flash a ready firmware from the browser Paste your error into the AI Error Doctor
Build tips Install the sensor on a tee after the shutoff valve and use a transducer rated for your pressure. Set CONFIRM_MS higher if pressure dips briefly during normal use. ← ← 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.
Watches the pit for water, tells you when the mains is gone and the backup is running, and rings an alarm before the pit overflows.
Probes under the washing machine or sink; a siren and a Telegram message the moment water appears.
⚠ Caution Batteries: watch polarity, use protected cells and a charger with protection, never charge damaged cells unattended.
A battery logger with display and alerts for fridges, freezers and cold storage, keeps recording through blackouts.
Comments
No comments yet. Share your experience or ask a question.