The men's room at our office has one stall for 50 people. Something had to be done

The thing is occupied about 50% of the time during the work day. That adds up to a lot of time lost as people get up, walk to the bathroom, see the stall is occupied, go meander around for a while, re-check, rinse, repeat. I decided to take action. This was my first imp project. Actually, my first electronics project at all.

It’s pretty simple: A tilt sensor on the stall lock lets the imp know if the door is locked or unlocked. The imp tells the agent. The agent tells an endpoint on Firebase, which is watched by clients via a web page and/or a Chrome extension. So, now you can check the status of the stall before getting up.

The whole thing is on GitHub here. The circuit diagram is outdated as the original version used a green LED when the stall was unoccupied in addition to the red one that indicates it’s occupied. It also just stayed connected all the time. The result was that I could only get a couple of days out of the three AAA batteries powering it. I refactored it to go in to deep sleep when the door was unlocked and to wake up and check itself when the door gets locked. That version had a small bug where the device would tell the agent the status every five seconds until the door was unlocked again, and the batteries lasted about eight days. I’ve since refactored so it just updates the agent twice (once when the door is locked, and then again five seconds later after a debounce expires) and I’m on the same batteries for five days now. Hoping to see at least ten days out of the current set. After that, I’m changing out the battery box to three AA batteries, which have over twice the capacity of the AAAs. I’m also switching to rechargeable batteries so that our receptionist doesn’t get sick of giving me new batteries every couple of weeks. Although at this point I think my Apple keyboard is burning them faster.

Here are some shots of the device in place, before I changed the circuit and ditched the green LED.

Response at the office has been mostly positive. A couple of people are a bit weirded out by an odd-looking device attached to the bathroom stall door, but most people are stoked about it and people are asking me to build more for their floors.

Parts from Sparkfun and adafruit.

I love it, especially the use of Firebase and Chrome extensions. Nice work!

A few things…

  • The imp inside a metal box isn’t going to be great for wifi range, but I guess it’s working well enough!

  • Running the LED obviously takes a non-zero amount of power. Sounds like you’re not running this now; if you wanted to keep an indicator but reduce power you could always do a shallow sleep (imp.deepsleepfor) and then wake to blink the LED for maybe 50ms every second or so.

  • Remember you can do shallow sleeps, without waking wifi, to check an input regularly, and then only fire up wifi when you have real data to send. This will also help hugely with battery life.

Is the LED bright enough? Maybe you can increase the resistor size to reduce current. Find out where the brightness is a “no-go”.

@Hugo - Thanks for the tips! Yeah, the metal box is fine. We have a wi-fi access point right outside the bathroom door, so that helps. The constant LED was a decision I made when I thought I’d end up powering off of USB. I’ve since decided to run on batteries, so the green LED is out of the equation and the red one is only on when the door is locked. I’m deep-sleeping after the door gets unlocked, waking up when it gets locked again, or every two hours (whichever comes first). Whenever it wakes up, it pings the Agent, and I’m working on a bit of code on the Agent that will realize when it hasn’t heard from the Imp in a few hours and will alert me somehow that it thinks the batteries have died. I think this is probably the most efficient battery usage.

@mlseim - it seems bright enough. I’m only writing 0.1 to the PWM pin when I want it on and that’s plenty bright. I’m new to all this, so forgive me if my understanding is pretty remedial, but are you suggesting increasing resistance until writing 1.0 is about the right brightness? Is that much more efficient than writing 0.1 with more current? I would guess that writing 1.0 with 1/10th of the current would be the same as writing 0.1 with the amount of current I going to the LED now, but again, I have no idea what I’m doing :slight_smile:

Thanks, all, for the feedback! This is a fun product and a great community.

Generally, PWM is more efficient than changing the resistor. This is why laptop backlights tend to be PWM’ed to set the brightness level.

Hey vespa59,

Have you considered logging and graphing the bathroom duty cycle on Xively? Just send a 1 for occupied and 0 for unoccupied. You only need to send the number when it changes. This only requires an update to the Agent code, so aboslutely no impact on your battery performance.

The Xively graphs will remain a constant 1 or 0 over time until it changes. I use just this very method for graphing a motion sensor in a vault.

Xively integration is really easy in the Agent thanks a really handy class you can find in the Forums (search “Class Xively.client”). I don’t remember who came up with it (bad on me) but I really appreciate the class.

Cheers, rledwa2

I think, here it would be against law to log how long a co-worker is pooping :wink:

btw: great project!

Great project! Necessity is the mother of all inventions.