My Raspberry Pi Powered Garage Monitor

Update #1: Garage Monitor Memory Leak: Part 1.

Update #2: I should point out that the arm on the switch I ended up using bent so it stopped working after about a month of use. I really need to figure out a way to mount the magnetic switch instead. I added a rough parts list to the end of this article.

This project uses a switch and temperature sensor connected to a Raspberry Pi (revision 2 board) to provide the state of the garage to a personal web server. This allows my wife and I to check the status of the garage via a bookmark on our smartphones.

This is the first circuit I have created a circuit board for. I am proud of the results. 🙂

My 1st Circuit

Adafruit Occidentalis

At the time of this writing my Raspberry Pi is running Adafruit’s Educational Linux Distro Occidentalis v0.2. Occidentalis is based on Raspbian Wheezy “but comes with hardware SPI, I2C, one wire, and WiFi support for our wifi adapters. It also has some things to make overall hacking easier such sshd on startup (with key generation on first boot) and Bonjour (so you can simply ssh raspberrypi.local from any computer on the local network)”

Python Script

The software running on my Raspberry Pi is coded in Python. The script runs at startup and checks every second (or so) for current status of the Closed/Open switches. When a change in state is detected, the current temperature is taken and the status is sent to a web service.

Web Service

I created a simplified “web service” in PHP which accepts the current door status (closed, open, or between) and the current temperature. The service logs the status and a timestamp to a file on the server.

Status Page

The current status is displayed by a PHP page which reads the last status from the server file and displays them. The background color of the entire page is changed to represent the current status (so the status can be known by a quick glance at my phone.

Status Page

Custom Circuit Board

After getting the expansion circuit working on a breadboard, I picked up an Experimenter Printed Circuit Board at Radio Shack (Part 276-0170). I choose this board because is closely mimics the layout of a breadboard, so it made it easier for me to build a duplicate copy without worrying about making extra connections.

My 1st Circuit (solder side)

The Switch was Switched

I have had planned for months on using magnetic switches, but when I stuck the magnet on the door, I realized there wasn’t a clear place to mount the open and closed switches that didn’t interfere with the door track. Then I remembered the microswitches I had on hand as replacements for my pinball machine repair hobby!

Pinball switch

I nailed this to a board and screwed that board into the wall at the bottom of the garage door edge. The extra long bar gets pressed down when the door hits the ground.

Switch installed at base of garage door

Circuit Features

The LEDs and buttons on the board are for use during testing/troubleshooting. Green = closed while Red = open. The door switches are connected to the headers next to the buttons (the are hooked up in parallel).

Since the Raspberry Pi’s GPIO pins only accept digital input and output. I used a tutorial from the Adafruit Learning System Analog Inputs for Raspberry Pi Using the MCP3008 to add a TMP36 temperature sensor. The temperature sensor was totally superfluous, but it was a fun challenge.

Parts List

Here is a rough list of parts:

  • Raspberry Pi Model B (revision 2)
  • Experimenter Printed Circuit Board from Radio Shack
  • MCP3008 Analog Digital Converter
  • TMP36 Temperature Sensor
  • 2 x LEDs
  • 2 x Pushbuttons (for testing without the door switches installed)
  • 4 x 560 ohm resistors (ignore the colors on the diagram)
  • 2 x Door Switches
  • Hookup wire
  • Male Header Pins
  • Female to Female Jumpers

Future Additions

  1. A closed position switch when I can figure out where/how to mount it.
  2. Webcam that takes timestamped snapshots. (Maybe I can use my old Android phone for this?)
  3. Status webpage button which would allow the user to manually force a status update. (To refresh the temp reading.)
  4. Status webpage button which would allow the user to close an opened garage door, but not open a closed garage door. (I could write to a file on the web server, which the Python script, then send a button press to the button, and then clear the contents of the file.)

Source Code

The source for this project is available on GitHub.

Circuit Diagram

13 Replies to “My Raspberry Pi Powered Garage Monitor”

  1. Hi Brain,

    I think I can add e-mail alert scrip include your python code and make this project more efficiency.


    if(GPIO.input(26) == False):
    print(‘Mail alert sending….n’)
    server = smtplib.SMTP(SMTP_SERVER,SMTP_PORT)
    server.sendmail(sender,recipient,headers + “rnrn” + body)
    LOOP = False
    print(‘Program terminatednn’)
    print(‘program is running ‘ + time.ctime() )

    BTW, Thanks for your information

    1. Interesting, though I have a worm drive motor so I don’t have chains. Although today my dad suggested I could sense the position of the piece that attaches the worm drive to the door. Maybe I could use infrared sensors like newer pinball machines use to sense pinballs.

      Although, the single microswitch is working quite well for now.

      1. I’m going to use magnetic switches on my “up and over” garage doors. I’ve got the switches just need time to attach them to the frame and run the wires to my Pi. The cheap £1 5V PIR I got off eBay is working great!

  2. The script ran for about 16 hours then stopped for some reason today. For troubleshooting I have remarked out the temperature reading, and ledFlashes(). I will write a follow up when I get it sorted.

    1. I’ve got an issue with Python dropping my script after a number of hours. Everything works but I suspect something is “leaking”. No idea if it is the OS, Python or the GPIO library? My “free” memory gradually drops from 120MB to 80MB for some reason. To me this seems as if something is building up in the background which drags Python down. Linux stays up as I can SSH into it fine. I plan to create a version of my script and remove all the web and file operations to see if I can isolate the bits that are chipping away at the memory.

      1. Let me know if you discover what is causing it. I will post a followup on my blog if I find a solution. At worst I suppose we could schedule a reboot every so often. At least in my case a reboot wouldn’t be a problem for my purposes.

    1. The parts costs are not fresh in my mind, but looking over the parts list I would guess the parts are between $30 – $40, not including the cost of the Raspberry Pi.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.