Making Things Interactive

March 27, 2008

wash your hands v2

Filed under: 8: State Machine,Gaku Sato — ponkotsu @ 12:38 am

This is my bathroom rig.  It annoyingly advocates sanitation by locking the door when it senses a flush until it determines that the occupant has washed his/her hands.

wyh-circuit.jpg

The black button on the right is the flush button.  Once that is pressed, the “wash your hands” LED blinks and the door locks via a solenoid deadbolt (behind protodoor).  The occupant’s intent to leave is signified by the doorknob switch (optimally a proximity sensor so no touching is necessary).  Initially it would re-remind the occupant to “wash your hands.”  If the water, which is represented by the potentiometer faucet, is turned more than a specified min threshold, the system registers that the occupant has rinsed his/her hands, but not washed them.  Pushing the which soap button tells the system that soap has been dispensed, but unless the water is running after that, it determines that the occupant is trying to trick the system!  Once the occupant has properly washed, the door unlocks and the “Thanks” LED blinks.

wash your hands!

wyh-statediagram-v2.jpg

int flushpin = 12;
int soappin = 11;
int waterpin = 5;
int lockpin = 8;
int doorpin = 2;
int thankspin = 7;
int washpin = 6;
int rinsepin = 4;
int fakepin = 3;
int state = 0; // 0=off, 1=on, 2=rinse, 3=soap

void setup()
{
Serial.begin(9600);
pinMode(flushpin, INPUT);
pinMode(soappin, INPUT);
pinMode(waterpin, INPUT);
pinMode(lockpin, OUTPUT);
pinMode(doorpin, INPUT);
pinMode(thankspin, OUTPUT);
pinMode(washpin, OUTPUT);
pinMode(rinsepin, OUTPUT);
pinMode(fakepin, OUTPUT);
digitalWrite(lockpin, LOW);
digitalWrite(thankspin, LOW);
digitalWrite(washpin, LOW);
digitalWrite(rinsepin, LOW);
digitalWrite(fakepin, LOW);
}

void loop()
{
if(digitalRead(flushpin)==HIGH) {blink(washpin); state=1;}
if(state>0) {digitalWrite(lockpin, HIGH);}
if(state==1 && digitalRead(doorpin)==HIGH) {blink(washpin);}
if(state==1 && analogRead(waterpin)<800) {state=2;} if(state==1 && digitalRead(soappin)==HIGH) {state=3;} if(state==2 && digitalRead(doorpin)==HIGH) {blink(rinsepin); state=1;} if(state==2 && digitalRead(soappin)==HIGH) {state=3;} if(state==3 && digitalRead(doorpin)==HIGH) {blink(fakepin); state=1;} if(state==3 && analogRead(waterpin)<800) { digitalWrite(lockpin, LOW); blink(thankspin); state=0; } } void blink(int pin) { digitalWrite(pin, HIGH); delay(100); digitalWrite(pin, LOW); delay(100); digitalWrite(pin, HIGH); delay(100); digitalWrite(pin, LOW); delay(100); digitalWrite(pin, HIGH); delay(100); digitalWrite(pin, LOW); } [/sourcecode]

Advertisements

1 Comment »

  1. My friend and colleague, a professor at Georgia Tech, is working on a system to monitor and remind doctors in hospitals to wash their hands before seeing each patient. Apparently doctors are the least compliant and therefore the largest vector for spreading disease through contact. So – no joke, this could be a real product.

    Comment by mdgross — March 27, 2008 @ 10:21 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: