I wanted to get my 3 kids into the habbit of remembering to flush the toilet, so I built this device. It's pretty simple, code wise.. When the door opens, the system arms. If the door opens again without the toilet flushing, the alarm goes off.
Some details on the components:
I used a power cord with the plug end stuck in the water in the back of the toilet to sense the water. The electrodes are stainless steel, near as I can tell. So they won't rust. They'd still collect deposits if I used DC to detect the water, so I used a Schmidt hex inverter to generate a 1MHz AC signal, which is then picked up through a 1N4148 diode and triggers a 2n2222 transistor to pull one of the interrupt pins on the Arduino low. The door uses a magnetic reed switch, Harbor Freight sells this little door/window alarm that makes a horrible racket when the door/window is open. It's only $2, so it's about the cheapest magnetic reed switch I could find, by a fair margin. I took it apart and desoldered everything except the reed switch from it, and ran wires out the side of it from that reed switch to the other interrupt on the Arduino (using an Uno).
The whole thing is stuck inside a toy robot head that I picked up at the mall last year really really cheap. It was originally a toy that you would wind up (3 phase alternator on the back of it that charged a button cell Li-Ion battery), it had a little wand with a loop on it and you'd try to weave it back and forth over the robot's curly antenna on it's head, if you touched the wand to the antenna, it'd make a warbling sound and blink his eyes/mouth LED's.. I kept that circuitry, but tied it into the Arduino. It runs off the 3.3v of the Arduino, and one of the output pins low will make it "go off". I was half tempted to just completely replace the original circuitry, but for the time being, I haven't. I could have put RGB LEDs in and really had fun with it (throbbing red eyes while armed, etc..) Maybe in the future?
The alarm talks.. It initially welcomes you to the bathroom, and it'll thank you for flushing, or it'll remind you to flush, or even to shut the door. I looked into several ways of making it talk, and in the end, chose the Adafruit wave shield, simply because it was the cheapest option. I used a pair of G4 iMac internal speakers as "ears" on the robot head. I found that the waveshield just wasn't very loud, so I took apart a worthless set of computer speakers that just couldn't be used for anything because they would distort so badly, and put the amplifier board from that inside the robot head. It runs off the 9v Vin line just fine, it's 1watt at best. And finally, I wanted a way to disarm the thing manually, short of unplugging it completely. I was about ready to drill a hole in the top of it and put in a push button. Then I remembered the capsense Library. So I was able to repurpose the antenna on the top of the robot head as a touch sensor. Using a 1Mega ohm resistor, it works perfectly to detect an actual touch.
The sketch (it's still a bit buggy, tends to be dead as a doornail in the morning, requiring a reset) is here: http://paste.org/pastebin/view/28255
If anyone notices a glaring mistake that might be causing that, I'd love to know. I know at one point it crashed when the door was opened and the toilet immediately flushed before the door had even shut. I've also had trouble with it crashing after the 8 minute disarm timer, though I have a return; added immediately after the disarm that might help with that..
And here's some video of it in action..