DIY Automation – The Garage – Part 2

The Garage Door Interface Electronics

For the garage door state detection I decided to go old school with a magnetic contact switch. I chose these for their simple implementation and ease in interfacing them to the RPI. Two per door will be used to detect when the door has reached its fully open and closed positions. The design includes the ability to actuate the existing garage door opener with a relay.

RPI interface to double door garage

P1 is the HAT header of the RPI. P2 & P3 are the door actuator relay outputs. P4-P7 are the door position switch inputs. When the magnet closes the switch on one of the inputs its corresponding RPI GPIO is pulled low to a logical 0. TOP corresponds to the top of the garage door and indicates that the door is in its full open position. Likewise BOT is the bottom of the door and indicates the door is in its full closed position.

The Input Circuit

Studying the input circuit surrounding P4, the diode D9 allows for the use of a door sensor that outputs voltage instead of a switch closure. If you use the magnetic switches it isn’t necessary. The resistor R9 act as a pull-up for the input to define a logical 1 since the magnetic switch does not provide a voltage. The LED D5 is strictly a visual indicator for the user to see when the input is being actuated. The resistor R5 is used to limit the amount of current that is sourced/sinked from the RPI’s gpio pin. It is primarily used as a buffer should the RPI gpio pin ever be accidentally put into output mode it won’t short against a closed external switch and damage the RPI.

The Actuation Circuit

Studying the output circuit surrounding P2, the relay K1 can be any general purpose 5 volt relay. The diode D3 is needed if the relay doesn’t come with one. It is used to short out the fly-back current produced by the relay coil when it is switched off. The fly-back current can at minimum cause the RPI to reset and at worst damage it. The resistor LED pair R3 & D1 are purely for visual indication that the relay is being actuated. Transistor Q1 is used to gate the relay since it cannot be driven directly from the RPI gpio without damaging the RPI. The transistor used can be any general purpose NPN or N channel FET. I used 2N3904 transistors because I had an ample supply of them in my personal inventory. The transistor needs to be sized to handle the current draw of the selected relay. In the case of a NPN type transistor the series resistor R1 is needed. In the case of an N channel FET, R1 would instead be attached to ground to bias the FET in the off state when the RPI gpio is an input. The RPI gpio’s are generally set to inputs whenever the RPI is reset. The last thing you want is the door inadvertently opening/closing in the case the RPI is power-cycled or reboot.

The Board So Far

Here we see the current board in all its glory. This is build with an original RPI Zero without the built in wifi, hence the TrendNet wifi adapter. Pay no attention to the ATTINY26. That was an experimental expansion that later proved to be unnecessary. I’ll discuss it more in an installment about the choice of temperature measurement and the radon abatement detection that was ultimately chosen but not yet added to the board.

Conclusion

The door interface is quite simple and easy to build. In the next part I’ll cover the code I wrote to turn the inputs into an MQTT message for the HAB system to digest.

DIY Automation – The Garage – Part 1

As an EE by degree and a Software Engineer by trade, I’ve always tinkered with making my own devices. With the rise of surface mount devices in the 1990s, my hobby became increasingly more difficult. You either had to create your own circuit boards or purchase surface mount adapters for the parts you wanted to use. Both avenues had a prohibitive cost involved for the hobbyist. With the advent of devices like the Arduino and Raspberry Pi the hobby of make it yourself electronics is once again thriving.

Having a desire to tinker and a penchant for laziness, I have embarked upon automating certain aspects of my home. First up is the garage. I want to know, at any given moment, the state of the garage doors, the temperature outside, and the state of our Radon abatement fan. I begin by breaking the problem into several areas. How to sense the position of the door. How to measure the outside temperature. How to know if the Radon abatement system is functional. What embedded device will this run on. How will the data be conveyed to the user.

Because of their widespread support and high-level capabilities, I decided to use Raspberry Pi Zero(s) as the embedded devices at the heart of each automation device. I intend to use its built-in wifi and wealth of gpio. There is also the cost. At $10 each, it has a phenomenal cost to benefit ratio. As it runs linux, I can also leverage my existing knowledge. This will also give me an opportunity to expand my understanding of python. I intend to write most of the code in python given the great amount of support the raspberry pi and IOT community has to offer.

For the front-end of the system I intend to use openHAB. The devices will communicate through an MQTT broker specifically mosquitto. More about them later.

In the next installment I’ll cover the basic device and the approach to detect the position and transition of the garage door.