The idea was to make a key holder allowing up to four different (sets of) keys, serving two purposes: a fixed place to hang the keys and assuming proper use, it could be used as a kind of presence check.
For the key holders, I decided to use stereo jacks and panel mount connectors. By shorting the left and right channel in the jack, a loop is created. On the connector, the left channel connects to ground, the right channel connects to a GPIO pin with internal pull-up resistor. When the jack is not inserted the GPIO is HIGH, when inserted, LOW. There is no differentiator per key at the moment, but could be achieved in a future version in different ways:
- Rather than just pulling to GND, resistors could be used, resulting in different analog values, each unique per key This will require the use of an ADC.
- Use a different connector set per key, making it impossible to connect in any other slot.
To have everything removable/replaceable, I used male header pins on the connectors and Dupont wires. The ground wire is daisy-chained across all four connectors. This results in a total of five connections to the Raspberry Pi’s GPIO header: four GPIO pins and one ground. As a visual aid and indication, every connector is associated to an LED of a certain colour. When the jack is plugged in, the LED is turned off, when removed, turned on. The LEDs are located on a small board which fits straight on the GPIO header, called Blinkt!. Using the python library, the individual LEDs can easily be controlled.
A custom milled acrylic plate holds the different connectors in place and aligns with the Blink! LEDs. The Pi Zero connects to the Blinkt! using a right angle GPIO header.
Finally, to turn this key holder in an IoT device, whenever a jack is inserted or removed, an MQTT message is published another Pi running OpenHAB. From there, OpenHAB rules can be associated to these events. What if the door was opened while the key was still in place??
Like every project, this one also required an enclosure to fit everything in. By glueing different rectangular pieces of wood together with the center drilled out, a hollow box was created. Using a router, the edges were rounded and after sanding, a smooth enclosure is the result. The acrylic plate holding the connectors could slide in from the back and be glued in place. A set of rubber feet provide the finishing touch.
The code is straightforward, and using the GPIOZero library for the first time, made it even more simple! But basically, the four GPIO pins are checked in an infinite loop. Depending on the state, the matching LED is set or cleared, and an MQTT message is sent.
Alternatively, you could get rid of the MQTT part in the code, and have an “offline” version of this project. Have fun!