Automatic water bowl

I have recently been trying to make a automated dog water feeder, but didn’t know what script to use for:

When a water sensor at the bottom of the bowl senses no water, a motor is activated (well peristaltic pump)

When a sensor at the top of the bowl senses water, disable the pump

I’m fairly new to this code and need a slight bit of guidance, appreciate a reply!

The sensors would typically be connected to input pins. The pump motor would be connected to an output pin. The sketch would read the input pins and set the output pin. In this case it also helps to know if the pump is currently running.

const byte FullSensorPin = 2;
const byte EmptySensorPin = 3;
const byte PumpPin = 4;

boolean FillingTheBowl = false;

void setup() 
  pinMode(FullSensorPin, INPUT);
  pinMode(EmptySensorPin, INPUT);
  digitalWrite(PumpPin, LOW);  // Default to Pump OFF
  pinMode(PumpPin, OUTPUT);

void loop()
  if (FillingTheBowl)  // The pump is running
    if (digitalRead(FullSensorPin))  // The bowl has reached full
      digitalWrite(PumpPin, LOW);  // Turn off the pump
      FillingTheBowl = false;
  else  // The pump is not running
    if (digitalRead(EmptySensorPin))  // The bowl has reached empty
      digitalWrite(PumpPin, HIGH);  // Start filling the bowl
      FillingTheBowl = true;

Thanks, going to try this out :slight_smile:

I suspect you do not actually have a dog nor have spent much time with one.

When a water sensor at the bottom of the bowl senses no water...

That only works if a dog is able to remove all the water from the bowl. For the sake of the dog, I am hoping you can guess where this conversation is going.

The sensor is not at the very bottom, it’s on the side and a small gap allows water to trigger the sensor. It’s not every last drop that triggers it.