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 allelectronics.com) 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.


3 comments:

  1. A question for you if you don't mind? I've got a CAI Webcontrol board running as a thermostat with the furnace wires attached to one of those YWRobot 5v relay boards with optical isolation (like http://www.amazon.com/gp/product/B0057OC5WK but not exactly). Anyway, i am getting EMI such that often when the furnace kicks on or off, the control board resets. Any ideas as to how to further isolate the control board? I thought such a relay board would be enough. The board gets its power separately from a wall wart. Thanks in advance, will be following your blog.

    ReplyDelete
  2. I haven't seen any of those specific boards but many isolated systems still manage to connect the grounds together and can let the spikes from the relays affect the computer. I know with arduino boards it's quite easy to get them to reset themselves due to power noise. i'd start by adding another cap across the power input to the controller, at least 100uf and maybe another one on the relay board too. I did find this discussion where they are talking about the YwRobot cards. This specific entry the fellow is discussing how to cut a jumper to fully isolate the relay power from the logic grounds. Perhaps that is also a good place to start if it's the same board as you've got. http://arduino.cc/forum/index.php?PHPSESSID=bcc4e07809fb8308a625e3ce5a3a905a&topic=72507.msg807352#msg807352

    ReplyDelete
  3. thanks so much for your response. i have lots of programming experience but little in electronics design (but i'm a quick learner and making good progress). i have already implemented those isolation techniques described in the link you provided. i have been researching techniques/circuits for suppression such as the caps you suggested and that's my next step, as well as perhaps a MOV. thanks again!

    ReplyDelete