Pages: 1 [2]   Go Down
Author Topic: Automatic Toilet Flusher  (Read 2919 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 4
Posts: 310
Posts: 40382
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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() {
  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 (PreparingToFlush==0){  
 if (sensor > 90){ //if distance sensor detects someone
  delay(1000);  // wait
  sample1=analogRead(sensorPin); //take a sample of the data
  Serial.println("Sensing");
  delay(300);
  sample2=analogRead(sensorPin);
  delay(300);
  sample3=analogRead(sensorPin);
  delay(400);
  sample4=analogRead(sensorPin);
  
  sensor= (sample1 + sample2 + sample3 + sample4)/4;
  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){
  Serial.println("Flushing");
  servo1.write(175); //FLUSH
  digitalWrite(13, LOW);
  delay(9000);
  servo1.write(3);
  delay(1000);
  
  PreparingToFlush=0;  //reset the trigger
}
}  
}  
  
  
  delay(10);
}
« Last Edit: October 18, 2010, 01:05:26 pm by Big_Oil » Logged

Netherlands
Offline Offline
Sr. Member
****
Karma: 1
Posts: 290
(:-)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: October 19, 2010, 09:28:23 am by wortelsoft » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: 1 [2]   Go Up
Jump to: