Garage Door Monitor

Garage

Since my last posting, Synoptic Labs has been transplanted to new, larger digs in Sacramento, CA. As a feature of the new location, we now find ourselves with a full garage which has substantially increased our storage and work area. However, this garage opens up onto a busy downtown street with a lot of foot-traffic and a bit of that traffic is from scavengers — people who routinely comb the neighborhood (usually early in the morning) looking for recyclables or, frankly, anything that isn’t nailed down.

The door is opened by remote control and, as we’ve found on numerous occasions already, it’s all too easy to inadvertently hit the remote and open the door without realizing or just forget to close it. More than once we’ve woken up and found that the door has been wide open all night long; the fact that we haven’t lost any tools or equipment because of this astounds me.

Knowing that our luck wasn’t going to hold out forever if we keep leaving the door open, I decided something had to be done. So I hacked together a internet/mobile-phone enabled garage door monitoring system which will notify us if the door is left open during the night.

Garage door sensorTapping garage sensor into parallel port

Using a simple push-switch from my electronics junk box and the parallel port on my FreeBSD server, I was able to wire the switch into the parallel port and write a very simple program to check whether or not the switch was closed. This was the first time I’ve ever hacked with the parallel port so it took me a little bit to figure out the pinouts. However, I was delighted to find that FreeBSD had the awesome ppi(4) interface for the parallel port and that it was already installed and running on my server. It only took me a couple minutes to write a simple program which could check the status of my switch and thus report on the state of the garage door.

Once that was done I whipped up a simple shell script which would run out of cron every minute and log the status of the garage door. I also whipped up a simple CGI script to so the status could be queried on the web and incorporated that into a live-status page on our private wiki. This makes it easy to check on the garage door from our mobile phones.

The final touch was setting up a Twitter account for the garage door and posting updates to that account. Now we’re able to get SMS notifications whenever the garage opens or closes. To minimize the chatter, the SMS notifications are generated only if the door is opened at night.

And thus with about $0.05 worth of parts and an afternoon’s worth of work, we now have a mobile phone/internet-enabled garage status monitoring system to alert us if we ever leave the door open again.

garagelog.sh — run out of cron every minute

#!/bin/sh

./garageis > status/garage.now

# Hour past which we'll report updates to twitter
twitstart=22
# Hour before which we'll report updates to twitter
twitstop=6

username='yourtwitteruser'
password='yourtwitterpass'

hour=`date +%H`
minute=`date +%M`

if [ ! -f status/garage.then ] || ! cmp -s status/garage.then status/garage.now; then
	if [ $hour -ge $twitstart -o $hour -lt $twitstop ]; then
		/usr/local/bin/curl -u $username:$password \
			  -d status="`cat status/garage.now`" \
			  http://twitter.com/statuses/update.xml > /dev/null 2>&1
		echo `date "+%G-%m-%d %R:%S garage: "` `cat status/garage.now` "(twittered)" >> garage.log
	else
		echo `date "+%G-%m-%d %R:%S garage: "` `cat status/garage.now` >> garage.log
	fi

	mv status/garage.now status/garage.then
elif [ $hour -eq $twitstart -a $minute -eq 0 ] && grep -q open status/garage.now; then
	# make sure we send a twitter if the garage is open when our
	# sensitivity window starts
	/usr/local/bin/curl -u $username:$password \
		  -d status="`cat status/garage.now`" \
		  http://twitter.com/statuses/update.xml > /dev/null 2>&1
fi

garageis.c — report status of garage door

#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <dev/ppbus/ppi.h>
#include <dev/ppbus/ppbconf.h>

int fd;

int
main()
{
	uint8_t  val;

	fd = open("/dev/ppi0", O_RDONLY);

	if(!fd) {
		perror(NULL);
		return(1);
	}

	// turn on data bits
	val = 0xff;
	ioctl(fd, PPISDATA, &val);

 	// read status flags.  if nBusy is 1, then garage is closed.
	ioctl(fd, PPIGSTATUS, &val);

	if ( val & nBUSY )
		printf("Garage is closed.\n");
	else
		printf("Garage is open.\n");

	// turn off data bits
	val = 0x00;
	ioctl(fd, PPISDATA, &val);

	return(0);
}

10 Responses to “Garage Door Monitor”

  1. Andy Isaacson says:

    I thought of rigging up something very similar when I was accidentally leaving the garage door open all night too. Mine was just going to automatically close it if it sensed it was open for >20 min. You’ve clearly taken the geek factor to the next level!

    –Andy

    P.S. I was always amazed that nobody stole anything out of my garage either!

  2. xander says:

    I’ve thought about having my computer automatically close the door if it’s open at night too. There’s a garage button on the wall and all I’d have to do is wire up something to close that circuit in order to close the door.

    The thing that stopped me from doing that was the problem of isolating the computer from the garage door circuit. I’d feel pretty stupid if some random voltage spike on the garage door button took out my server. An optoisolator would have been great for that but I didn’t have any on hand.

  3. Bonnie says:

    The garage door manufacturer Chamberlain Liftmaster already sells a garage door monitor.
    I am not sure how to differs to the one you created.

    See here:
    http://www.liftmaster.com/consumerweb/pages/accessoriesmodeldetail.aspx?modelId=746

    Just thought I would share….

    Bonnie Massey
    Entry Systems
    http://www.entry-systems.com
    Laguna Niguel, CA

  4. Rob says:

    Great project! Can you share how to connect the switch to the LTP port?

  5. Ian Hanschen says:

    Hello Sir,
    I am from a led company in Shenzhen, China. We are interested in selling you a batch of bright beautiful LEDs. You can go to….
    INTERFERENCE
    INTERRUPTION
    BZZRTHGKCHK

    UPDATE YOUR BLOG! Have the projects seriously stopped?
    -Ian

  6. CJP says:

    Hello Sir. I am interested in selling you a batch of accolades for your most wonderful door project, because you continue to be my hero. Please to teach the phenomena of awesome. (well done).

    -cjp

  7. Arthur says:

    that was quite useful, has given me some ideas.

  8. jason says:

    I know this post is a bit old but here are two ideas for opening/closing the door automtically.

    Depending on your spare parts you could either rig up a simple motor to physically press the garage door switch or if you have a spare remote (if this is a remote-able door anyway) you could use that.

  9. You could use the same parallel port to open/close the garage door. Just use one of the bit outputs and set it to high then use a relay to complete the circuit on the garage door opener. Given the parallel port output puts out 5 volts if that happens to be the same voltage as what is going through the switch you could get away with soldering a single wire to the other side of the switch to simulate the click. Though would strongly recommend testing with a voltmeter. I did something similar to turn on/off power outlets with the same concept for my computerized grow box.

  10. This is such a great idea! My roommate messes around alot with Microcontrollers and he often talks about connecting his cell phone to be able to read the temperature at the house. Would that be similar to what you are doing?

    Also, I noticed you are using a Shell Script? What is that? I’m pretty familiar with PHP and the syntax seemed very similar. What’s the difference?

Leave a Reply