📜 ⬆️ ⬇️

Automate toilet flush on Arduino + Z-Wave

What can be common between these two objects?



Idea


Once I decided to teach a cat to the toilet, in order to get rid of the unpleasant smell emanating from its tray. But to teach him to walk is one thing, but to descend behind him is almost an impossible task. Therefore, I decided to put it on the electronic shoulders, in the role of which is the Arduino Nano.

The script was thought like this:
Kote (the one on the first picture), through the mini-door at the bathroom door, gets inside, forcing the opening sensor to work, does its business as much as it pleases it, and exits. After the second actuation of the sensor, the hood is activated, the water in the toilet bowl is lowered and the freshener is sprayed.
')

Equipment and tests


Towerpro MG996R , Z-Wave Fibaro FGS221 servo and LED button were connected to the board. Added a button as a bonus parallel to the relay and brought it to the wall.



In fact, the servomotor is powered by BP 5V 2A. From it is powered by USB.

Connection diagram and code:


Code for Arduino
#include <Servo.h> //   Servo Servo flush; //      const int buttonPin = 2; //    const int led = 4; //    int buttonState = 0; //      int flag = 0; //     unsigned long holdTime = 0; //    unsigned long blinkTime = 0; //    unsigned long loadTime = 0; //    void setup() { pinMode(led, OUTPUT); //      pinMode(buttonPin, INPUT); //      flush.attach(3, 8, 140); //     3   /  flush.write(8); //       } void loop(){ buttonState = digitalRead(buttonPin); //    if (buttonState == LOW && flag == 0) { //         flush.write(8); //       digitalWrite(led, LOW); //   } if (buttonState == HIGH && flag == 0) { //        delay(100); //      flush.write(140); //      flag = 1; //   holdTime = millis(); //     } if (buttonState == HIGH && flag == 1 && millis()-holdTime > 200) { //      X  flag = 0; //   blinkTime = millis(); //     do { digitalWrite(led, LOW); //   delay(200); digitalWrite(led, HIGH); //   delay(200); } while (millis()-blinkTime < 5000); //   X  flush.write(8); //       loadTime = millis(); //      do { digitalWrite(led, LOW); //   delay(200); digitalWrite(led, HIGH); //   delay(200); } while (millis()-loadTime < 54000); //   X  (   ) } if (buttonState == LOW && flag == 1 && millis()-holdTime <= 200) { //      X  flag = 0; //   blinkTime = millis(); //     do { digitalWrite(led, LOW); //   delay(200); digitalWrite(led, HIGH); //   delay(200); } while (millis()-blinkTime < 2000); //   X  flush.write(8); //       loadTime = millis(); //      do { digitalWrite(led, LOW); //   delay(200); digitalWrite(led, HIGH); //   delay(200); } while (millis()-loadTime < 30000); //   X  } } 



Video of the first version of the algorithm with Z-Wave


This version differs from the final one only by the delay before the button can be pressed again.

The delay is equal to the period of complete recharge of the tank with water.



Implementation


Since the installation from Geberit was installed during the repair, connecting the traction was not a big deal. The servomotor is installed between the tank and the aluminum profile, screwed and filled with hot glue. As the traction cable was used with clips, which is passed through the hole in the tank. Flexible traction was needed so as not to lose the possibility of water descending with a button on the tank.



The electronic part is located in the junction boxes for the installation.



Manual control can be carried out either by a button or through an application for the Fibaro HomeCenter.



Two descent modes are used:
  1. With a short press (<200 ms) half the water goes down.
  2. If you hold the button for more than 200 ms, the tank is emptied entirely.

Z-Wave relay is configured for the second mode.

Demonstration of the device

The delay is triggered by the fact that the application was working remotely through the fibaro server.



Conclusion


Unfortunately, the kote on the video will not be, as he moved out, and I have a desire to realize my plans.

Well, a bonus :)

Source: https://habr.com/ru/post/223125/


All Articles