Build it step by step
0 of 7 doneTest the PIR
Print its output.
Test the level sensor
Fix it outside the tank and watch the pin.
Wire the pump switch
MOSFET and flyback diode.
Write the visit logic
Two minutes of pumping.
Add the low-water guard
Pump off and LED on.
Add the refill alert
Optional webhook.
Fit it
Keep electronics above the water line.
How do you build a smart cat fountain?
A fountain pump runs only when your cat is near and warns when the water is low. You need ESP32 DevKit V1, PIR Motion Sensor HC-SR501, Water level sensor (non-contact, XKC-Y25), Mini submersible water pump (3 to 6 V), MOSFET IRLZ44N, Rectifier Diode 1N4007, 5 V 2 A USB adapter, Resistor 10 kΩ × 2, LED 5 mm red and Resistor 220 Ω. It takes 7 steps and about 120 minutes.
- Level
- Intermediate
- Time
- About 120 min
- Parts
- 10
Parts list
- Development BoardsBuyESP32 DevKit V1 × 1
- SensorsBuy
- SensorsBuy
- Motors & ActuatorsBuy
- SemiconductorsBuyMOSFET IRLZ44N × 1
- SemiconductorsBuy
- PowerBuy
- PassivesBuyResistor 10 kΩ × 2
- SemiconductorsBuyLED 5 mm red × 1
- PassivesBuyResistor 220 Ω × 1
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| PIR OUT | ESP32 GPIO27 | Cat nearby |
| XKC-Y25 OUT | 10 kΩ to GPIO26, with 20 kΩ (two 10 kΩ) to ground | Level signal, scaled to 3.3 V |
| XKC-Y25 and PIR VCC and GND | 5 V and GND | Power |
| ESP32 GPIO25 | IRLZ44N gate, with 10 kΩ to ground | Pump switch |
| 5 V adapter plus | Pump plus | Pump supply |
| Pump minus | IRLZ44N drain | Switched ground |
| 1N4007 | Across the pump, stripe to plus | Flyback protection |
| Low-water LED | GPIO23 through 220 Ω | Refill warning |
| IRLZ44N source, adapter minus, ESP32 GND | Joined | Common ground |
Code
The pump runs for two minutes after the PIR sees the cat, which saves power and noise, and never runs when the non-contact sensor, stuck to the outside of the tank, says the water is low; a pump running dry can burn out in minutes. The sensor outputs the supply voltage, about 5 V, so a 10 kΩ and 20 kΩ divider brings it down to 3.3 V for the ESP32. Put your own Wi-Fi name and password in the placeholders, and keep them out of anything you share. The optional refill alert uses an encrypted web call with certificate checking turned off, a trade-off that is fine for a harmless message but not for private data. Use a food-safe pump and tubing, wash the fountain weekly, keep the 5 V adapter and every connector out of splashes, and run the cable in a drip loop. Arduino IDE with the ESP32 boards package 2.0.x, board "ESP32 Dev Module".
Runs on a virtual ESP32 Dev Module 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).
// Cat fountain: pump runs for 2 minutes when the PIR sees the cat, never when the water is low. Board: ESP32 Dev Module.
#include <WiFi.h>
#include <HTTPClient.h>
#include <WiFiClientSecure.h>
const char* SSID = "YOUR_WIFI_NAME";
const char* PASS = "YOUR_WIFI_PASSWORD";
const char* HOOK = "https://example.com/YOUR_WEBHOOK_PATH"; // optional refill alert; leave as is to skip
const int PIR = 27, LEVEL = 26, PUMP = 25, LED = 23;
unsigned long pumpUntil = 0, lastAlert = 0;
int drinks = 0;
bool pumpOn = false;
void notify() {
if (String(HOOK).indexOf("YOUR_WEBHOOK") >= 0 || WiFi.status() != WL_CONNECTED) return;
WiFiClientSecure c;
c.setInsecure(); // trade-off: skips certificate checking; fine for a harmless alert, avoid for private data
HTTPClient http;
if (http.begin(c, HOOK)) { http.GET(); http.end(); }
}
void setup() {
pinMode(PIR, INPUT); pinMode(LEVEL, INPUT); pinMode(PUMP, OUTPUT); pinMode(LED, OUTPUT);
digitalWrite(PUMP, LOW);
Serial.begin(115200);
WiFi.begin(SSID, PASS);
}
void loop() {
bool water = digitalRead(LEVEL) == HIGH; // sensor output high when water is present
digitalWrite(LED, !water);
if (!water) { // dry-run guard: never run the pump on an empty tank
digitalWrite(PUMP, LOW); pumpOn = false;
if (millis() - lastAlert > 3600000UL || lastAlert == 0) { notify(); lastAlert = millis(); }
} else if (digitalRead(PIR) == HIGH && !pumpOn) {
pumpOn = true; pumpUntil = millis() + 120000UL; drinks++;
digitalWrite(PUMP, HIGH);
Serial.print("Visit "); Serial.println(drinks);
}
if (pumpOn && millis() > pumpUntil) { pumpOn = false; digitalWrite(PUMP, LOW); }
delay(100);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Cat approaches | Pump runs for 2 minutes |
| Water level low | Pump stays off and the LED lights |
| Refill | Normal behaviour resumes |
| Visit count | Increases by one per visit |
If it does not work
Pump never starts
Check the MOSFET orientation and the level sensor output.
Always low water
Move the sensor to the right height on the tank wall.
False visits
Aim the PIR away from windows.
No alert
Check the Wi-Fi details and webhook address.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the smart cat fountain?
ESP32 DevKit V1, PIR Motion Sensor HC-SR501, Water level sensor (non-contact, XKC-Y25), Mini submersible water pump (3 to 6 V), MOSFET IRLZ44N, Rectifier Diode 1N4007, 5 V 2 A USB adapter, Resistor 10 kΩ × 2, LED 5 mm red and Resistor 220 Ω.
How long does the smart cat fountain take to build?
About 120 minutes for a intermediate maker, in 7 steps.
How do I know the smart cat fountain works?
Cat approaches: Pump runs for 2 minutes. Water level low: Pump stays off and the LED lights. Refill: Normal behaviour resumes.
Pump never starts: what should I check?
Check the MOSFET orientation and the level sensor output.
Always low water: what should I check?
Move the sensor to the right height on the tank wall.
False visits: what should I check?
Aim the PIR away from windows.
No alert: what should I check?
Check the Wi-Fi details and webhook address.
