Too Lazy To Flush — Design Problem

Om Rastogi
4 min readApr 4, 2020

Designing an automatic flushing solutions.

My grandfather kept forgetting to flush the toilet after using it, which highly affects his hygiene.

This is how the automatic flushing and cleaning systems, must be working in malls. Even though, it was a very trivial problem, but in solving it, I got to learn a few crucial things. Product design experience is the one crucial experience, which I will share here.

Clearly, the solution consists of an

  1. Ultrasonic Sensor
  2. Arduino
  3. Servo

The idea is simple — the ultrasonic sensor will be able to calculate the distance of person in front of it. After a threshold on the distance, the servo will be triggered accordingly — but the execution is not so simple.

The challenges were:

  1. The sensor was giving a lot of garbage value, due to poor connectivity.
  2. Fixing of servo on existing system, without any damage.
  3. Timing the servo trigger, to make it after use and only once per session.

Let us see how I have tried to solve the aforementioned problems.

The Programming

Here is the full code:

#include <Servo.h> 
int servoPin0 = 7;
int cnt=0;
const int trigPin = 9;
const int echoPin = 10;
const int N = 5;
Servo Servo0;
int distance;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Servo0.attach(servoPin0);
Servo0.write(90);
Serial.begin(9600);
}
int dist_cal() {
long duration;
long dist;
int avgd = 0;
int n = 0;
while (n!=N){
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(100);
duration = pulseIn(echoPin, HIGH);
dist= duration*0.034/2;
if (dist>2000) continue;
if (dist==0) continue;
avgd = avgd + dist/N;
n = n+1;
delay(20);
}
return avgd;
}
void flushmech(){
Serial.println("Flushing");
Servo0.attach(servoPin0);
Servo0.write(0);
delay(2000);
Servo0.write(90);
cnt = 0;
delay(20000);
}
void alarmup(){
pinMode(13,HIGH);
int avgd = 0;
int n = 0;
Serial.print("avgd: ");
while(n<10){
avgd = dist_cal();
Serial.print(avgd);
Serial.print(" ");
if (avgd>100) break;
n = n+1;
}
if (n>9) cnt=1;
delay(100);
pinMode(13,LOW);
}
void alarmdown(){
pinMode(13,HIGH);
int avgd = 0;
int n = 0;
Serial.print("avgd: ");
while(n<10){
avgd = dist_cal();
Serial.print(avgd);
Serial.print(" ");
if (avgd<100) break;
n = n+1;
}
if (n>9) cnt=0;
delay(100);
pinMode(13,LOW);
}
void loop() {
distance = dist_cal();
Serial.print("Distance: ");
Serial.println(distance);
if (cnt == 0) if (distance<100) alarmup();
delay(400);

if (cnt==1){
Serial.println("alarms up");
delay(2000);

if (distance>100) alarmdown();

if (cnt == 0)
{
flushmech();
}
}
}

dist_cal() method, calculate the distance from sensor to object in front. It also filters the extreme value that the sensor was producing at intervals, hence avoiding unexpected results.

alarmup() method is used to notify that the a person is using the toilet. As someone comes to the toilet and is under 100cm to the sensor, the program enters to check the persistence, if the person was there to use or just to pass by or just a wrong detection was made. So this method checks for other 10 readings, and if all are less then 100cm, flag cnt is assigned the value one.

alarmdown() method is used to notify, that if a person was using the facility, then he is done and left. If cnt has value 1, and distance is more than 100cm, than the program will enter this method, which will check for persistency of readings. If true, cnt will be assigned value zero again, than flushmec() method will be called, by the loop.

Hardware

Looking at the codes you will clearly understand the that the servo is connected to pin 7 while the sensor uses pin 9 and 10.

To build the flush mechanism, I inspected the insides of a flush and found the right part to connect the servo using cotton thread.

Now whenever servo is rotated, this pump is pulled up and the water is flushed. (This was difficult to actually take my hand in there)

Shortcomings

And after all this the solution was working just fine and I also made a video on a testing.

However, the user needs to be in front of sensor, else the sensor won’t trigger. Also the programs waits for some time to check if the users absence is persistence, hence confuses the user if it will work or not.

The testing of the solution

--

--

Om Rastogi

I believe in an altruistic world, where creativity and imagination replace repetitive work