Projects / Smart cat fountain

Smart cat fountain

Intermediate2 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32motion

    Test the PIR

    Print its output.

  2. ESP32Y25

    Test the level sensor

    Fix it outside the tank and watch the pin.

  3. ESP32IRLZ4424.0°C

    Wire the pump switch

    MOSFET and flyback diode.

  4. ESP3224.0°C

    Write the visit logic

    Two minutes of pumping.

  5. ESP32Y2524.0°C

    Add the low-water guard

    Pump off and LED on.

  6. ESP32

    Add the refill alert

    Optional webhook.

  7. ESP32Y2524.0°C

    Fit it

    Keep electronics above the water line.

In short

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

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

Wiring

FromToWhy
PIR OUTESP32 GPIO27Cat nearby
XKC-Y25 OUT10 kΩ to GPIO26, with 20 kΩ (two 10 kΩ) to groundLevel signal, scaled to 3.3 V
XKC-Y25 and PIR VCC and GND5 V and GNDPower
ESP32 GPIO25IRLZ44N gate, with 10 kΩ to groundPump switch
5 V adapter plusPump plusPump supply
Pump minusIRLZ44N drainSwitched ground
1N4007Across the pump, stripe to plusFlyback protection
Low-water LEDGPIO23 through 220 ΩRefill warning
IRLZ44N source, adapter minus, ESP32 GNDJoinedCommon 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.

CheckExpected
Cat approachesPump runs for 2 minutes
Water level lowPump stays off and the LED lights
RefillNormal behaviour resumes
Visit countIncreases 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 →

Ask Lark AI

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.