Automation cat toilet

Hello!
I want to do an automation of drawing water in the toilet when the cat uses it.
I want to:

  • the sensor is set so that when the cat is placed on the toilet it lights up the led, the led that activated your water pump.
    So, the ultrasonic sensor sees the cat, and must activate the pump after 120s, so that the cat has time to pee, not to be scared of water.
    In this code I have a problem, to trigger the pump, the sensor must see the cat 120s continuously. I want the sensor when it sees the cat to start a 120s stopwatch and finally start the pump for 5s! Where am I wrong?
    The time of 3600s is set to limit the flow of water to a maximum of 1 time per hour.

I use Arduino Nano with HC-SR04 Ultrasonic sensor

Code:

int set = 0;

int cm = 0;

int i = 0;

int j = 0;

long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
}

void setup()
{
pinMode(13, OUTPUT);
}

void loop()
{
digitalWrite(13, LOW);
delay(3600000); // Wait for 3600000 millisecond(s)
cm = 0.01723 * readUltrasonicDistance(11, 12);
if (cm <= 45) {
delay(120000); // Wait for 120000 millisecond(s)
digitalWrite(13, HIGH);
delay(5000); // Wait for 5000 millisecond(s)
}
}

Your code does nothing for an hour, then checks for a cat, if there is no cat it does nothing for another hour. So, unless your cat happens to use the toilet in the fraction of a second each hour that the program checks your program will never see your cat.

These will help you:
Using millis for timing
Demonstration for several things at the same time

Also, I posted some example code in here:

Understand that and you’re on your way to solving this.

Please use code tags </> when posting code. Thanks.

Your code is spending nearly all of its time in the 1 hour delay. It cannot detect the cat during this long delay period. So the cat must hop up onto the toilet only at precise 1 hour intervals. Do you have a very well-trained cat?
S.

Remove the hour delay entirely.

Add a counter to increment for each time the pump starts.

My cat does not use the litter box more than once an hour. More like three times in a day

Learn how to use millis() to make a timer.
Count durations betweeen pump cycles

I’m a beginner and so far I’ve only programmed with blocks! I’m trying to see if I can handle the lines of code. Anyway, thank you for your help!

That 1 hour delay its only for water economy! :smiley:

gabi_el:
That 1 hour delay its only for water economy! :smiley:

Sure, but I think you are missing the point, the thing spends about 99.999% of its time in the delay, so nothing else works.

Have a look at the "blink without delay" example. This allows you to detect the presence of the cat, while not flushing the toilet for more than once per hour.

The same technique can be used to make sure the cat stays for at least say 10 seconds (so probably actually does something there), waits for the cat to leave regardless of how long it stays there, and then waits some time before flushing - all the while checking the cat does not return for whatever reason.

By the way, does your ultrasound sensor work well with your cat? They're known to not detect soft fluffy objects like a fur ball very well.

"Take a look at the 'blink without delay' example."
Good idea, I will try this option too!

"By the way, does the ultrasound sensor work well with your cat? It is known that it does not detect fluffy soft objects like a fur ball very well."
I didn't try with the cat, but with my furry foot - it works! :-p

Unfortunately, I only have 2 weeks since I started playing with an Arduino board. Now I read information from all kinds of projects based on ultrasonic, led, timing, delay ... I thought that using block programming will be easier, but no ... I have to understand what I do and why! Even if I find it harder to respond to messages, I'm here!
Thank you for your support and help!

PS: until now I used a Sonoff wifi module with which I started the water pump, but I had to activate it manually or when it started to stink in the room.

first ERASE the wait 3600 !!! YOU MUST GET RID OF THIS

try the examples in the IDE you want to turn on an LED with a switch or button.

look at state change in digital.

you want to create an output pin say, pin 6

before sutup() add the line to say what pin and what name you want to use.

const int pump = 6 ; // set pump to pin 6

then, in setup()
pinMode(pump, output) ;

in loop()

change
if (cm <= 45) {
delay(120000); // Wait for 120000 millisecond(s)
digitalWrite(13, HIGH);
delay(5000); // Wait for 5000 millisecond(s)
}

to

if (cm <= 45) {
delay(120000); // Wait for 120000 millisecond(s)
digitalWrite(13, HIGH);
digitalWrite(pump, LOW); // turns pump on for the length of following delay
delay(5000); // Wait for 5000 millisecond(s)
digitalWrite(pump, HIGH); // turns pump OFF after the delay
}

PerryBebbington:

Quote from: gabi_el on Feb 21, 2021, 10:47 pm
That 1 hour delay its only for water economy!

Sure, but I think you are missing the point, the thing spends about 99.999% of its time in the delay, so nothing else works.

try this.
lock yourself in the closet., no lights, nothing
set a timer for 1 hour.
when the timer goes off, open the door, look to see if your cat is on the toilet, close the door
if, the cat was on the toilet when you looked. only then would you lite the LED
you are only allowed to look for 1 second at a time, and only 24 times a day.
that should sound silly.
but that is what your code is doing by using delay(3600000)
think about the cat.
how often does the cat go to the toilet ?
that is how many times a day the pump would run,

Okay, maybe it's a beta prototype, I didn't think about it too much.

You're right, I'm removing that time (3600000). I only thought about the water saving, that it can run there, as a result it still activates the pump.

I think he uses the toilet 5 maybe 6 times / 24 hours, but he(male) also marks his territory at the toilet, also several times a day.

Thanks for the code! When I get home, I'll try it!

You can still ‘hold off” multiple flushes within any single hour, just do it with millis(), so you can control the sequencing more closely.

If you really want to leave the pee in the bowl between short visits (i.e. max flush once per hour), that’s ok, keep track if the cat visited, then when the preceding hour has passed... flush it away... when the cat isn’t on the seat.

The only small issue is that maggie could be almost ready to jump up and restart the pee timer.... whoosh, will scare it away while it’s getting ready.
To fix that - you’d want a second sensor with a wider view, to ensure kitty isn’t nearby before a flush cycle is triggered.

No one it seems has remarked on the remarkable: a cat that uses the toilet.

Why don't you try a little further training and add flushing to the trick?

Also I wonder if the ultrasonic thing mightn't be annoying. To cat or human. You could try an RF proximity detector:

I've used the RCWL-0516 features in the video. Inexpensive, works well.

a7

alto777:
No one it seems has remarked on the remarkable: a cat that uses the toilet.

Yeah, I can't imagine Simba doing that!

How do you train a cat to use a toilet?

PerryBebbington:
Yeah, I can't imagine Simba doing that!

How do you train a cat to use a toilet?

I don't know how it's done ... but I have seen a cat trained to use the toilet. Most cats are indifferent to humans (except at feeding time) and utterly contemptuous of any attempt at training...
S.

Food is the key!

(Not sure how that works here though!)

Normally I’d ask the same questions, but my daughter informed me a couple of weeks ago, that her cat was teaching itself!
Apparently it only took about ten days until they were both happy how it was working!

Please, tell me how you get a cat to use a toilet! I assume you have to teach it while it's still a kitten.

There is no shortage of on-line guides.

You start by putting the litter tray on the toilet ...

...apparently not.
Our cat is four years old, and just decided that it needed a change!