Occu-pi: The Bathroom of the Future!
It’s not often that one is presented with an opportunity to innovate in the bathroom space, but just such an occasion arose earlier this year when the Hirepurpose team moved offices and our bathroom capacity was suddenly, tragically reduced by half.
Our previous office had long been plagued by unreasonably long bathroom lines. At several high-demand periods throughout the day we’d be forced to wait three, four, five people deep while complaining bitterly to each other until our turn to use the facilities arrived. With even fewer bathrooms in our new office concern about timely access was naturally high.
Believing there may be a technological solution to this problem, we decided to do what all good engineers do: find a way to make more efficient use of our limited resources. We figured that if we could find a way to better coordinate bathroom access and advertise availability we could avoid spikes in usage that make annoying lines. We needed a sensor that could determine and broadcast the bathroom’s availability.
This turned out to be not quite as straightforward as we originally thought. There is one notable wrinkle: it’s not enough to know the door is closed, you need to know if the bathroom is actually in use – that is, locked from the inside. After considering and discarding a variety of “creative” solutions (no thank you, motion sensors and facial recognition), we landed on a straightforward and reliable approach.
The Occu-pi
Our solution is to incorporate the sensor into the lock itself, basically like an airplane bathroom. The bathroom is considered to be in use only if the door is closed and locked from the inside so there are no false positives from a vacant room and there are no extra steps for the user.
We employ a Raspberry Pi, a magnetic switch, and a barrel bolt to both lock the door and detect the change in availability. The state change is updated via a REST endpoint running on an AWS Lambda function which in turn updates a Slack channel so the current availability is always a glance away.
We call this system the Occu-pi (pretty good, right?) and you can build your own for about $75 in components and a few hours of time. (Hey, maybe even try to get your office manager to pay for it?)
Here’s how to do it.
Components
You’ll need the following components to build your own Occu-pi. Everything can be found on Amazon at reasonable prices with Prime shipping.
If you live in New York City, you might want to check out Tinkersphere, a totally awesome neighborhood electronics shop in the East Village where you’ll find everything you need plus a million things you don’t but will be tempted to buy anyway.
- 1 Raspberry Pi v3 w/ micro USB power cable
- 1 GPIO breakout board (if you’re more experienced, feel free to improvise)
- 1 8MB Micro SD card
- 1 magnetic switch (well, half of it, actually)
- 1 sliding barrel bolt lock (the bolt itself should be about 6mm in diameter)
- 1 small, strong, cylindrical magnet (smaller/equal in diameter to the bolt)
- A bit of strong epoxy
If you’re new to this stuff, you may also need or want:
- An HDMI cable
- A breadboard for prototyping
- A breakout T-style ribbon cable
In addition to the hardware components, you’ll need some software. Feel free to write your own (it’s really not that complicated) or use our version as a starting point:
We also used a few other parts like plexiglas, screws, and standoffs to mount the Occu-pi on the wall. As mounting will be somewhat location-dependent, we’ll leave this part as an exercise for the reader.
Assembly
Assembly is pretty simple if you have any level of experience with Raspberry Pi and GPIO pins: there’s really just one component to wire. If you’re starting from zero, you might be interested in reading this introduction to GPIO before you get started.
First things first, set up your Raspberry Pi according to the instructions it comes with. This will take a little time. You’ll have to prepare a bootloader on your SD card, maybe stick some tiny heat sinks on the CPU, install an OS – stuff like that.
Once you’ve finished you’ll want to assemble the system and verify everything works before you start bolting things to the wall.
- Install your breakout board on the GPIO pins. The board we used has a port for it’s own power, separate from the Raspberry Pi itself. This may be necessary in some applications, but for our purposes it isn’t required, we can just use the power it gets from the GPIO pins.
- Wire up your magnetic switch. It doesn’t really matter which pins you use, as long as one is a GPIO input pin and the other is a ground pin. We recommend using the same pins as we did (see photo) so you don’t have to update the controller software to use different ones. We’re going to use the small cylinder magnet instead of the other half of the switch — it works the same way but it’s small enough to fit on the bolt.
At this point you’re going to need to install the controller software on your Raspberry Pi to interact with the GPIO pins. Here’s the source for the version we wrote, feel free to use it as a starting point. We wrote ours in Go because Go is the best language and I will fight anyone who claims otherwise. Most people seem to use Python for these sorts of projects, however, so you may find better documentation available for that.
However you decide to do it, the general approach is the same: when the lock state changes we simply POST an update describing the change to an AWS Lambda function. Then that function (or whatever service you want to send updates to) should take some action—this part is up to you.
- Now that your controller software is running on your Raspberry Pi we can test our switch out. Try moving your small magnet near the magnetic switch and then back away. If you’re using our software the LED lights should change to indicate the change in state and details will be printed to the Raspberry Pi’s console. Amazing!
- After verifying the system works, we’re going to mix up some of our epoxy and affix the small magnet to the end of our barrel bolt. Make sure that the magnet is smaller or equal in diameter to the bolt so that it can pass through the catch. It’s pretty easy to install since the magnet will hold itself in place against the metal bolt while the epoxy cures.
Now that our magnet is secure we’re going to arrange everything on a tabletop as it will be installed later and test the system by sliding the bolt closed and open through the catch to trigger the switch—basically we want to simulate locking the door.
While performing our simulation, we need to measure and note down the distance the bolt must pull away from the magnetic switch before the state changes. We’ll need to know this distance in order to mount the switch and bolt correctly: when the bolt is open it must be far enough away from the switch and when it’s closed it must be close enough to close the circuit.
For us, this was about 3/4", but the distance may vary depending on the strength of the magnet and the sensitivity of the switch. Aim to have the tip of the bolt about halfway into the trigger range when closed, this will give you a bit of budge room when mounting.
- Now everything is measured once, measured twice, the components are arranged and ready for installation, and we’re ready to screw everything into the wall. If your bathroom is like ours and you have some molding around the door you may need to cut out a section so the bolt can be mounted flush. We used a Dremel to slice out a chunk and that was pretty exciting.
- Alright, now run some power to your Raspberry Pi so you can try it out! Assuming you added it to your wifi network when you set it up you should be able to power it up, shell into it from your computer to start up the controller software, and then take it for a test run.
- And that’s it, you did it!
Your very own Occu-pi is built, installed, and running. You are a hero in the office, your co-workers have probably attempted to carry you on their shoulders to happy hour and pay for all your drinks. The transformative power of technology has never been more clear.
More where this came from
This story is published in Noteworthy, where thousands come every day to learn about the people & ideas shaping the products we love.
Follow our publication to see more stories featured by the Journal team.