Garage Door Monitor

I live in an older house with an automatic garage door opener. I'm not sure how old the garage door opener is, but it has been around for a long time. The door has a remote control for use in a car. Once in a while I come home to find the garage door is open. I don't know why this happens, but the old remote control is not very sophisticated, and possibly a taxi transmitter or a neighbor with a similar system causes it to open. (Update: the opener has finally been replaced, but the project remains in service to account for "human error" (forgetting to close the door).

Anyway I was thinking about what to do about it. A remote alarm inside the house isn't much use if you are out. What would do the job just fine is a microcontroller inside the garage, watching if the door was open too long and then closing it.

First of all, you need to know when the door is open. Fortunately I had installed a switch years ago to turn on a light when the door was open. All I had to do was put a small 12V transformer in the utility box connected to the light, and bring the low voltage AC down to the controller. A simple diode and 78L05 convert the AC to a nice logic level.

On the output side, the controller has to be able to close the garage door. I used a small 5V SPST reed relay, driven directly from the microcontroller, wired to the nearby pushbutton used to close the door manually. (I used the same relay as in my Thermostat project, but any suitable relay can be used.)


Since the project was going to be run by a microcontroller, I could do some interesting things. For one thing, I keep a count of the number of times the controller closes the door, so I can know what's been going on, using a 2 digit LED display. I use a piezo beeper to issue a warning before closing the door. And I have a hold button to use in case you want to keep the door open for awhile.

circuit board

front and topInside view

The program is written as a state machine, rather than the event-driven mainline I generally use. The state machine is implemented in a large switch statement inside a do forever loop. At any point in the program the state can be changed depending on an input or an elapsed timer. The first state simply monitors the door and waits for it to open. When the door opens, other states are entered as required. If the door remains open past its allowed time, a series of states are run to sound the beeper 5 times, then close the door and return to monitoring state. The beauty of the state machine is that you can create a state for every possible set of circumstances you wish, each state being relatively small and simple.

The final state, the FAULT state, requires some explanation. It is very nice to implement a program that handles all the expected conditions, but you have to think about the unexpected conditions too. When it is closing, my garage door is designed to stop and reopen if it meets a certain amount of resistance. (Newer doors have photocells too.) Awhile ago a few bearings on the door wore out, causing it to close partway, jam and reopen. If an automated system were attempting to close the door, it would not understand such a problem and may keep trying to close the door indefinitely. I use a 24 hour timer and a limit on the number of times to close the door in each period. If the count reaches the limit, fault state is entered, and remains there (in effect disabling the device) until the clear button is pressed, or power recycled.

There are a few defines in main.c that you might want to consider customizing:

� NUMBER_WARNING_BEEPS Number of times the beeper sounds before closing the door (5).
� DOOR_OPEN_DELAY_MIN Number of minutes the door is open before closing it (10).
� MAX_CLOSINGS_TODAY Numer of times controller closes the door in a 24 hour period before FAULTing (10).

On the top of the case is a pushbutton (Hold), a green LED for power, and a yellow LED. The yellow LED normally indicates that hold state is active. Pushing the Hold button again cancels the hold. However in the Fault state, the hold LED will flash on and off rapidly. There is another pushbutton on the bottom of the case, for Clear. In the monitoring state pressing the clear button zeroes the count on the display. In the Fault state, pressing the Clear button clears the fault (but does not zero the count).

Download C source code for the garage door montitor

Back to VE3LNY's AVR Project Page