I think I've made this project as simple as possible. There is no apparatus needed to flush it. I mounted the servo inside the toilet tank by just tying a knot in the servo wire.
The knot is outside the porcelain lid so that the servo does not fall into the tank.
The fishing line is connected to a hook, which you can use to hook onto the chain inside the toilet tank. If you need the line to be tighter you can just hook lower down on the chain.
I wrapped the servo wire around the servo and taped it so that the wire wouldn't pull out or damage something internally, but maybe that part is not even necessary.
I have had the servo inside the tank for about a week now and so far it is still working fine, despite the moisture.
Here it is hanging in the tank:
I have also made some adjustments to the code:
#include <ServoTimer1.h>
ServoTimer1 servo1;
int sensor=0;
int sensorPin=5; //distance sensor on pin 5
int PreparingToFlush=0;
void setup() {
Serial.begin(9600);
servo1.attach(10); //servo data line on pin 10
servo1.write(3);
// digitalWrite(3,HIGH);
}
void loop() {
sensor=analogRead(sensorPin);
Serial.println(sensor);
if (sensor > 90){ //if distance sensor detects someone
delay(2000); // wait
sensor=analogRead(sensorPin);
Serial.println("Sensing");
if (sensor > 90){ // check again to make sure someone is actually there
PreparingToFlush=1;
digitalWrite(13, HIGH);
Serial.println(sensor);
}
}
if (PreparingToFlush==1){ //if a person has been detected
if (sensor < 60){ // if the person has now left
delay(1000);
sensor=analogRead(sensorPin);
if (sensor < 60){
servo1.write(175); //FLUSH
digitalWrite(13, LOW);
delay(9000);
servo1.write(3);
delay(1000);
PreparingToFlush=0; //reset the trigger
}
}
}
delay(10);
}