Friday, August 10, 2012

Garage Controller - New Device at My House

I have a nice big garage that I use a lot, but I constantly leave the doors open. Seems about half the time I get part way down the dirt road away from home and have to try and remember if I closed the doors. This means coming back and checking so OCD doesn't set in and drive me nuts wondering if the doors are open. Be nice if I could look on my smart phone and see if the doors are open from anywhere and close them if necessary. Looks like a job for another little computer. I had an Arduino handy, a couple of Xbees and a little relay board set aside for this so the project shouldn't be too much trouble, All I need is an enclosure of some kind. I found my very most favorite enclosure for this kind of thing on Amazon:
I already had one of these installed by the phone company on the side of the house and just happened to stumble across it on Amazon.  They're 9x6x3 and weather resistant.  The one I have has been there for years and nothing inside has been damaged, so this should be fine.  
Here it is with the Arduino, one of the newer XBee shields and a four relay board mounted inside.  There's lots of room left for other devices and various wires from things around the garage.  For example, the beige box next to it is the differential temperature controller for my solar water heater.  Here in the desert, I only pay to heat water in the middle of winter on heavily overcast days.  I don't even allow power to get to the heating element for 8 months of the year.  In the future, control of that power and monitoring the temperature of the water will be handled by this new device.  The little XBee shield is a relatively new device and works really well.
I chose this particular board because it would allow me to put the XBee tx and rx pin on something other than 0 and 1 and it was relatively inexpensive; around $7 with shipping.  It also has a protoype area for mounting some screws to get inputs into the system.  I've found using the arduino serial port for an XBee leads to massive problems when I try to debug various things.  Without a serial port, you just can't find problems. So, I mounted some screw terminals on the XBee board to take inputs and hooked up some magnetic sensors on the garage doors.
Sorry, it's a little out of focus, I must have moved a bit, but you can see the terminals for the magnetic switch inputs and the relay outputs for the door switches.  I just ran wires to the regular garage door switches to control them, they were relatively close.  I use a two second pulse to open and close the doors and monitor closure for the door sensors.    

There was an unexpected side benefit of this, I can now tell the door to close.  That may not sound like much, but remember, garage doors are a toggle.  If they're closed and you push the button, they open.  You always have to go check to see if they are already closed before pushing the button because you may be opening them instead.  The idiocy of toggle buttons drives me nuts.

Currently, the Xbee simply transmits the status of the doors every few seconds and my House Controller displays the status on its LCD display.  It also provides the status on the Controller web page along with buttons to take care of closing or opening the doors.  Now, I can pull out my phone, look at the web page and close the darn doors if I left them open.  I've been wanting that for years.

One nice thing about my home automation, it gets easier over time.  I already have the XBee network set up, adding a new device is easy.  I have the code already written and available in several devices for copying to a new one.  I have code for watchdog timers, parsing inputs for commands and formatting status updates ready in several versions.  Adding a few lines to the House Controller to put it up on the web is pretty painless and the Controller has lots of memory left for this kind of thing.

Plus, the discovery of the enclosure I mentioned above.  This thing keeps the weather out, is easy to get into to debug or make changes, holds a lot of stuff, can be locked (keep kids out), and can survive the weather, especially if you paint it.  This will become the default enclosure for all my outside projects from now on since I can get it pretty easily and it works so well.  I may even get a few of them and retrofit some of the devices I already have.  I get really tired of unscrewing a lid to check an led when I could just open a door.  It's annoying that I didn't think of it before.  It would have saved me hours when I was working on the Pool Controller.  I was constantly opening that thing up and changing something as I decoded the protocol and worked out control strings.


Thursday, August 2, 2012

Swimming Pool Controller

I have an entire page devoted to my swimming pool controller and other devices related to the pool here.  The device works pretty well, but since there are two protocols, (Goldline and my own) and they are real devices, there have been some annoying problems over the period I have been using it.  The problems all stem from the fact that there is no 'on' or 'off' command for the various functions.  They all work like a garage door, you push a button and something changes state.  Push a button, the valve opens, push it again, it closes.  This makes things like turning off the pool light a bit of a problem if you don't know if it is already on.  About a year ago a nice person gave me the command string he was using to turn his pool off, unfortunately it didn't work for my controller, but when I tried it I got an idea I should have come up with a year ago.  Simply look to see if the light is already off, and don't do anything if it is.

Obviously this was too simple an approach for me to come up with when I was developing the controller.  I was getting into loops where I would turn on the light, the delay before the various devices recorded that the light was on was erratic (real devices, remember) and I would issue the command again, thinking it got lost somewhere.  That would make the light turn on, wait a few seconds, turn off, wait a few seconds, turn on, etc.  Annoying at times.  Most of the time everything worked perfectly, but when it got into one of these loops, it might take 10 minutes or so to get out of it.  So simple code like: if (light already on) don't do anything, should fix the problem

Guess what?  It did.

I modified all my pool commands to work this way and the pool controller is very reliable now.  I got the idea when I started working on a controller for my garage doors.  I hate getting a few miles from home and suddenly starting to worry that I left the garage door open.  There is little risk of theft out here in the desert, but I hate having a squirrel move into the garage and a dozen or two cactus wrens deciding it's a nice place to live.  I had a squirrel cause some damage once and I don't want to repeat that.  So, I need to know if the door is open and close it.  I came up with a design where I'll put a magnetic switch on the door and that way I'll know when the door is open and can close it from far, far away.  This made me realize that I have the status of the various controls on the pool already, why not just use them.

There was also the problem of ambition, it worked mostly OK, why fix it?  This lethargy went away when my new, variable speed, permanent magnet, super motor died.  Yes, it died.  It developed some kind of fault and declared, "Emergency Stop in Effect."  Nice informative message.  I called Hayward and they said they'd have to send out a repairman.  The first comment out of my mouth was, "How much is that going to cost?"

"Nothing." was the reply.

Sure enough a nice guy came out, looked the problem over, and REPLACED THE ENTIRE PUMP.  Yes, I got an entirely new pump with zero hours on it as a warranty replacement.  How cool is that?  I hooked my controller up and was annoyed immediately by the toggle action.  That's how I came up with the idea and implementation.  While I was making the changes to the code, a couple of bugs turned up that I didn't encounter before and they got fixed as well; nice side benefit.

I'm waiting for parts to come in for the garage project, but thinking about it, there's a few lessons to learn here.  1. Never give up on an idea, let it percolate a while and a solution might appear.  2.  Don't be afraid to call the manufacturer for advice; you may get a really good response.  3.  some other project may suggest a better way to do something; don't ignore it.  4.  DIY projects are never really done, they just settle down for a while.