Wednesday, March 20, 2013

Arduino Thermostat part 1

We took a very close lightning hit here a month ago. I didn't lose anything plugged into the wall, I have good surge protection on each electric panel, but I lost several things connected to long serial cables including my very fancy RS485 serial thermostat from HAI. I've replaced the other components and added surge protection to their long serial lines to prevent future problems from induced current but I've decided to roll my own thermostat.

I've been supporting communicating thermostats in XTension for some years now. There are 4 models that I've implemented the protocols to and there are more lined up should they ever choose to document what those protocols are. (and if you have one, or have a favorite you think should be supported please let me know) so it's not like I have a lack of good thermostats laying around here that I could install. But I'm drawn to dangerous DIY like this.

I've decided that it should not do very much in the thermostat at all. Since it's going to be connected to XTension through an xBee radio link I really have no need of schedules or setbacks or anything, I can do that all in the logic of the computer. Since I've basically disabled that functionality of every thermostat I've ever installed and just run it from the computer anyway it seems like a lot of added complexity in them that I never use. I've been using those xBee radios for some time in lots of projects around the house and they are just awesome. XTension lets you control their pins, or read their analog inputs or use their remote serial ports for just about anything.

This device I"m making wont be a one size fits all for everyone, but then anybody considering doing this should have some info on what they are doing since getting this wrong could potentially ruin your house in the form of frozen pipes or destroy thousands of dollars worth of compressors in your AC or worse. So I'm not going to sell a kit or anything, but it's been interesting me for some time.

Here's the power board completed. It has the connections for the thermostat wiring, 3 solid state relays and the half wave bridge rectifier and smoothing capacitor to make the DC prior to feeding it into the arduino power supply. Since the furnace here is simple, only single stage only 3 are necessary. The fan relay, call for heat and call for cooling.

I debated how to switch the lines to the furnace. I could have used cheap relays, but they use not insignificant power that can cause heating inside the case and false readings (but you can get around this like more commercial thermostats do by putting the relays at the top of the case and the sensor at the bottom and using the heat to create a chimney effect of room air past the sensor making it read actually better) but it can also cause problems with voltage fluctuations causing false readings from analog temp sensors and other things. (this wont be a problem since I've decided to go with a digital temp sensor) Plus you can hear them click and that is just so last decade... The problem is that you're switching AC power, so just a single mosfet isn't going to work. You can use 2 wired in opposite directions to do it or an SCR or any number of other ways, but these SSR's are not expensive (I think I paid around $5 each for them from and I had them around. Additionally they provide complete isolation between the logic and the current being switched.

The capacitor is overkill by 3 or 4 times, but it's what I had around and it mostly fit on the board there. There are 2 diodes on the board wired in series. I used what I had, those are fancy fast acting low voltage drop schottky diodes which are totally overkill for this power supply too, but I had a bunch of them left over from switching LED power supply experiments. They are rated for an amp of power which is good, but only for 20 volts, so 2 in series are necessary to safely rectify the 24v from the furnace. I used a simple half wave bridge here because the output from a full wave bridge would have been more DC voltage than the switching regulator I've ordered for the arduino side is rated for on input.

Apart from just following good coding practices when I start writing the code, and making it as simple as possible I will be implementing a ping and response system between this and XTension so I can tell if it goes away or gets hung up. I've done a lot of smaller projects with Arduinos and I know they can run for extended periods without problems. Even so, this being a one off project I need a way to reset the thing automatically if it goes down. My first thought was to use one of the many unused pins on the xBee connected through a transistor to the arduinos reset pin. Then I can reset it from the XTension computer if I lose the ping. Though I am beginning to think a local circuit with some timer or capacitor that needs to be regularly restarted by a pulse from the arduino and will cause a reset if it doesn't get that pulse might be good too. A kind of local watchdog timer too. We shall see what happens.

Shortly I'll be connecting this board to the power from the furnace and measuring the output and making sure that all works even though there is no control logic yet.

Today I'll be putting together the arduino and hopefully the fancy temp/humidity sensor I ordered will arrive and I can begin that side of the project.

.code { background:#f5f8fa; background-repeat:no-repeat; border: solid #5C7B90; border-width: 1px 1px 1px 20px; color: #000000; font: 13px 'Courier New', Courier, monospace; line-height: 16px; margin: 10px 0 10px 10px; max-height: 200px; min-height: 16px; overflow: auto; padding: 28px 10px 10px; width: 90%; } .code:hover { background-repeat:no-repeat; }