|All News -> Projects|
|Written by Nicholas McClanahan|
|Tuesday, 08 November 2011 09:58|
Say goodbye to embarrassing bathroom sounds, leaving the seat up, or forgetting to turn off the light with Toilet Buddy!
Toilet Buddy was inspired by Japanese toilets that play a 'Courtesy Flush' sound instead of actually flushing in order to save water. It also improves on the idea by reminding you to put the seat down and when you left the lights on.
First, I'll go over the design and show you how to make it. Then, I'll show you how Toilet Buddy can be adapted to projects that could use event-driven audio playback.
How does it work?
Because there usually isn't a power outlet around the toilet, Toilet Buddy is battery powered.
How long do the batteries last?
Toilet Buddy is a low power audio playback device that can be triggered by external events. We're selecting playback files based on object detection (IR sensor) and ambient light (photoresistor). We can change the logic and samples to use Toilet Buddy with different projects and add sensors.
The Propeller Platform controls the logic and audio playback - we just need to add the sensors, speaker, and power.
PowerMost bathrooms don't have an outlet right next to the toilet, so Toilet Buddy runs on 3xAA rechargeable batteries. It's also designed to maximize battery life by staying in low power mode until more performance is needed.
First, we'll connect the batteries straight to the 5V pin on the Propeller Platform. This skips the 5V voltage regulator, reducing standby current consumption. We also take advantage of the Ultra LDO Voltage Regulators, so we can squeeze every drop out of the batteries.
Second, we can minimize power consumption on the Propeller with our program. Toilet Buddy will sit in low power mode 99% of the time. It runs a single core when checking the sensors, and only fires up a second core during audio playback.
Keeping power consumption to a minimum will get us at least 1,000 hours on a single set of batteries, or about 40 days.
Light SensorWe use a photoresistor to measure ambient light. Its resistance changes based on how much light it's exposed to.
First, our circuit first charges up the capacitor. Then discharges it, counting how long it takes to discharge to 1.8V. The amount of time the capacitor takes to discharge is proportional to the resistance of the photoresistor. More resistance = longer discharge.
IR DetectorHere's the IR Detector circuit;
The IR LED blasts light modulating at 38kHz and the IR receiver tells us if it sees any IR light modulating at 38kHz. Any nearby objects will reflect the light from the LED, bouncing it to the receiver. Further, we can change the transmit power of the LED to get a rough idea of how far away the object is. This technique works well for short distances and when presence is more important than distance.
PartsYou'll need a few parts to assemble Toilet Buddy;
ToolsAssembly takes about 20 minutes. If you're building it on a Protoboard, take your time with the instructions. If you've never soldered before, there are a bunch of great instructables to guide you, like this one. You'll need a few tools:
I recommend leaded solder, especially if you're just starting out. Leaded solder is easier to work with, melts at lower temperatures, and results in better connections, particularly when you're inexperienced. Leaded solder is also poison, so don't put it in your mouth and wash your hands after soldering. The smoke isn't nearly as toxic, but it irritates my nose, so I try to avoid breathing it in.
I'm building my Toilet Buddy with a protoboard - the same one that comes with our project pack. It's handy because there's a letter / number grid for identifying every hole on the board. Once your iron is warmed up, let's start with the headers;
An easy way to add these is to first put the pins in the Propeller Platform sockets (the group of four connects Vin, V50, V33, and GND; The group of six connects P15-P10), then put the protoboard on top, as shown in the photo above.
Using a spare bit of hookup wire, connect;
The Ambient light detector uses a photoresistor to measure light. Connect;
The Lid sensor blasts IR light - any nearby objects will reflect the light and bounce it back to the IR receiver. First the IR LED;
Toilet Buddy is capable of playing back 48kHz, 16-bit stereo, which is a little higher than CD quality. Samples are stored on the microSD card, and played back on the connected speakers.
You can grab the binary here, or the full source right here. Instructions on how to program your Propeller Platform in Windows, Linux, or Mac are here. You can also use the audio samples I've created right here. Download them and copy to the root of your microSD card. Here's an overview of how the program works, which you'll find especially useful if you want to customize it;
Main Loopthe main program runs through this code, checking for a reason to play a sample;
First, it runs the method seatposition and stores the value returned in the variable seatstatus. Then it does the same thing with checklight, storing the returned value in lightstatus.
If lightstatus == 1 and seatstatus == 1, the seat is up and the light is on. Toilet buddy goes ahead and plays cover.wav. If the light is off and the seat is up, seat.wav is played.
If lightstatus == 3, that means the light timeout has been reached. Then it plays the light.wav file.
checklightThis method checks if the bathroom light is on. It uses the rctime object (part of the Propeller Tool download) to accomplish that. It charges up the capacitor connected to the photoresistor and counts how long it takes to discharge with a single line;
The variable RCValue will store the discharge time. If it's greater than the limit we set, that means not very much light is hitting the photoresistor, and we return 0. If more light is hitting it, we increment the light timer and return 1, until we reach the light timer limit.
seatpositionWe check the status of the seat with this method. We use ir object to accomplish this, which is also part of the Propeller Tool download. First, we have to tell the ir method what pins the IR LED and receiver are connected to - we do this at the beginning of the program with;
Then, when we call ir.distance, it will return the measured distance of an object in front of the sensor.
This method actually takes care of the audio playback. It's a simplified version of rayman's wav player. First, it opens up the file we requested. Then it reads the header to see if the wav file is 44khz or 48khz. Then it starts up the wav player in a second core. Our first core then fills the audio buffer for the second core.
With a few changes to the code and/or circuit, we can use Toilet Buddy in a bunch of different projects. Here's how to use it as a Grandfather Clock. Grab the the full source and follow the code below;
Be sure to enter the starting time in the first lines of the program. timestamp and timestamp store the minute value of the clock. timestamp and timestamp store the seconds. When minutes and seconds are both equal to 0, we know we're just starting a new hour, and it's time to make an announcement.
Using Toilet Buddy to notify you when people are at the door doesn't require any changes to the circuit, just a few changes to the code.