Go Down

Topic: Automatic Toilet Flusher (Read 4843 times) previous topic - next topic

Big Oil

Oct 18, 2010, 08:01 pm Last Edit: Oct 18, 2010, 08:05 pm by Big_Oil Reason: 1
I've made another adjustment to the code.  If you're not using a capacitor to smooth out the data from the IR sensor it might randomly falsely trigger it, so now it will take 4 data samples and average them to make sure someone is actually standing there.  Right now there is a 1 second delay, then a 1 second sample time.  If the toilet is next to a bathtub you might want to make that triggering delay longer, because someone might stand there for 5 seconds before getting into the tub.  
If you haven't seen the pictures of the non-wooden apparatus at the bottom of page 1 check that out.
Wortlesoft- no misses yet.  Andy R, let me know how it goes.  You could also make a fun button with lights for the kids, or a clapper (clap twice).
Code: [Select]
#include <ServoTimer1.h>
ServoTimer1 servo1;

int sensor=0;
int sensorPin=5; //distance sensor on analog pin 5

int PreparingToFlush=0;
int sample1;
int sample2;
int sample3;
int sample4;

void setup() {
 servo1.attach(10); //servo data line on pin 10
// digitalWrite(3,HIGH);

void loop() {


if (PreparingToFlush==0){  
if (sensor > 90){ //if distance sensor detects someone
 delay(1000);  // wait
 sample1=analogRead(sensorPin); //take a sample of the data
 sensor= (sample1 + sample2 + sample3 + sample4)/4;
 if (sensor > 90){ // check again to make sure someone is actually there
 digitalWrite(13, HIGH);

if (PreparingToFlush==1){ //if a person has been detected
 if (sensor < 60){ // if the person has now left
 if (sensor < 60){
 servo1.write(175); //FLUSH
 digitalWrite(13, LOW);
 PreparingToFlush=0;  //reset the trigger


Oct 19, 2010, 04:28 pm Last Edit: Oct 19, 2010, 04:28 pm by wortelsoft Reason: 1
I saw the picture but didn't realise this was a new situation. That sure is a lot better.
I'm surprised that such a servo is powerfull enough.


LOL that is awesome... it made my day haha

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131