/ arduino

Arduino thermostat for a 'passive' 24VAC HVAC system, Part 1

I brought this on myself

Like many families with an unfinished basement, the allure of all of the 'wasted' space was too great, and eventually we decided to finish our basement to be a place for entertainment, media and fun.

One issue we had to address was how best to keep the area comfortable. As it is a walk-out basement, underground on 3 sides, located in the Northeast of the United States, although there is some degree of temperature regulation and isolation brought on by the depth, that 4th wall -- exposed to the elements -- does permit the outside temperature to impact the inside to a greater degree than a fully surrounded basement.

The obvious solution to the heating problem is to simply go with some form of electric heat, but this is New England and our cost of electricity exceeds that of much of the rest of the country. Combine that with cold New England winters and you've got a formula for some significant on-going operating costs. Moreover, that does not address the impact of the summertime heat when cooling will be required.

Therefore, I looked into adding an additional 'zone' to my existing forced air HVAC system, in tandem with the first floor zone. Seemingly, this would be the most straightforward solution -- the basement would have its own thermostat and would call for heat or AC as needed. Easy, right?

You want to put this new zone where?!

Well, it turns out, it wasn't so easy. The main issue was the fact that the duct work to the registers for the first floor essentially left no room to duct in the additional zone for the basement. To reroute everything would have been a major undertaking.

Facing that, I came up with a new idea -- a passive system for the basement, at the mercy of the first floor zone. The idea is simple: if the first floor is receiving heat or AC, and if at that time the basement wants the same, it opens a damper in the ductwork and 'steals' a portion of the forced air destined for the first floor. Once the basement is satisfied, the damper is closed and the first floor receives the full blast of air. An important observational fact made this a sane solution -- generally speaking, because the basement is underground, it is closer to the ideal temperature than the first floor. In other words, in the winter the basement tends to be a few degrees warmer than the first floor and in the summer the basement tends to be a few degrees cooler. As such, the basement should demand less than the first floor and would make a good candidate to be a passive, 'child' zone to the first floor zone.

It turns out, this isn't that unusual of a design. Many commercial building operate this way -- they blast hot or cold air into one massive duct system for an entire floor (or even the whole building), and different sections of the building open and close dampers if that particular area is in need of that air to achieve the area's desired temperature. Because this wasn't some crazy idea, the necessary parts existed and my HVAC installer was able to create my passive zone.

How it works

Operationally, the model is very simple, primarily operating off of 3 inputs:

  • the desired temperature (i.e. the temperature to which you set the thermostat)
  • the current temperature of the room
  • the current temperature inside the main duct

Let's say the desired temperate is 70 degrees and the room is currently 65 degrees. The room is too cold and needs to be heated. However, as it is a passive system, it cannot simply call for heat. Instead, it needs to consider the current duct temperature.

If inside the duct it is, say, 68 degrees, then there isn't any heat flowing at the moment. The system will therefore close the damper which connects the basement registers to the main duct.

Once heat is detected in the main duct -- say, 140 degrees, which would not be unusual -- heat is clearly being blasted (because the first floor has requested it). The system opens the damper, and some of the air destined for the first floor begins to flow into the basement. Once the basement is heated to 70 degrees, the damper is closed and the first floor gets all of the hot air, likely becoming satisfied soon afterwards. The only real potential failure would occur if the first floor reached its desired temperature before the basement reached its desired temperature -- in that case, the air flow would cease and the basement would be left "wanting more."

Amazingly, in practice, it all basically worked. (More on what could have been better later.)

The magic box

At the heart of this solution was an electronic thermostat. The thermostat has a thermometer on it to measure the room temperature, a connection for a duct temperature sensor so as to measure the temperature in the duct, and a screen plus some buttons to set the desired temperature. And, by using essentially the same logic in reverse, the thermostat could detect when cold air was being blasted through the main duct and use that to cool down the basement when the basement was too hot. There isn't even a need to tell the system "hey, it's summer now, so switch to cooling mode," because the very fact that there was cold air being pushed through the duct work meant that the air conditioning was running, so it must be summer time. (In other words, once the first floor decided to start calling for cold air, the basement thermostat would realize 'okay, it's time to start cooling off rather than heat up', in a truly passive way.)

Where it all went horribly wrong

I am not going to mention the brand name of this thermostat because I do feel that the company behind it is pretty solid, and I get the sense that they deal far more with commercial customers and certified HVAC installers rather than overly ambitious home owners such as myself. That being said, we did run into some issues with the hardware. When we first installed it, it indicated a very low duct temperature -- like 53 degrees. They manufacturer said this indicated a short or a faulty temperature probe. Sadly, because my eager installer put the temperature probe in without testing it and we had since plastered over the ceiling, we had no choice but to cut open the ceiling, remove the probe, and replace it.

This solved nothing.

It turns out, the thermostat itself was faulty. If only they had sent us a temporary replacement, we could have tested that before cutting open the ceiling. In any event, we finally had a working system, patched the ceiling, and went about enjoying our new basement.

The problem returns

Fast-forward two years, and I noticed one day that I could hear the damper opening and closing repeatedly. It's super quiet, so it may have been doing so for weeks. It took a very quiet summer day, with me standing right below the point where it is installed, to even notice it. After some investigation, I noticed that the thermostat was again claiming a duct temperature of 53 degrees.

Here we go again.

I contacted the manufacture, and they again decided that it was a problem with the duct temperature sensor. Having been down that road before, I said it wasn't. Unfortunately, I didn't know how to prove it. They offered to sell me a new thermostat for $250.


I envisioned a world where every 2 years I had to send them a check for $250 to keep my system operating.

Necessity is the mother of invention

Okay, maybe it was not a necessity that I considered alternative solutions (it could just be cheapness), but I had wanted to explore the whole IoT world. I finally had a concrete reason to do so.

Sure enough, I found tons of articles about people building thermostats out of Raspberry Pis, Ardunios, et. al. My investigations led me to the conclusion that an microcontroller was my best option and the easiest way to enter that world was via Arduino.

I opted for the Arduino Starter Kit, which I was able to get for a good price on Amazon. Yes, it was more than I needed to build a thermostat, but I knew I had a lot to learn so I looked at it as an investment in my education.

I built several of the starter kit projects, and I was hooked. The pure excitement of building something electronic that did something was a feeling that I had not felt since I first started programming computers in the late 1970s. It was pure joy.

The starter kit has a thermometer project, and, combined with the included LCD display, in no time I had my own electronic room temperature sensor. About the time I finished it, I had to travel overseas, so I asked my wife to give me updates on it while I was gone. Sure enough, she said it tracked the room temperature well but, more importantly, worked flawlessly the entire time I was gone. When I returned, it was still sitting on an end table, dutifully reporting the remote temperature. It didn't crash; it didn't run out of memory; it didn't have a stack overflow. And when I unplugged it, moved it, and plugged it back in somewhere else, it nearly instantly went right back to telling me the room temperature. It didn't have to boot or load drivers -- it's very essence was to be a room thermometer. This is what sets microcontroller like Arduino apart from general-purpose computers running an operating system, like the Raspberry Pi.

Satisfied that I now knew enough to be dangerous, I ripped my precious device apart and tackled the project at hand.

Two different temperature sensors

The Arduino Starter Kit includes the TMP36 Temperature Sensor from Analog Devices. It's a great device -- inexpensive, accurate and easy to use. You just give it a voltage (and you've got a range of 2.7V to 5.5V), and on a magical 3rd Vout pin you get a voltage which is proportional to the temperature. You don't even have to calibrate it. The math to convert the output voltage to temperature is a crazy simple linear formula:

TempInCentigrade = 100 * Vout - 50

So, understandably, I was feeling pretty confident that I'd be able to get my duct temperature, add some code to control the damper, and I'd be done.

Not so fast...

The duct temperature sensor only has two wires. It's missing that magical 3rd wire.

As you can imagine, there are lots of different ways to create an electronic temperature sensor although many operate on a similar principle of acting as a resistor which varies with temperature. Internally, the TMP36 is a slightly complex circuit -- far more than just a resistor:

![TMP36 circuit diagram, copyright 2015 Analog Devices, Inc.] (/content/images/2016/03/TMP36-circuit-diagram.png)

The duct temperature sensor, on the other hand, is just a thermistor -- in other words, a resistor which varies with temperature. Converting the resistance into temperature takes a bit more work.

Without going into the gory details, the trick is to first create a voltage divider, using a fixed resistor that matches the maximum resistance of the thermistor as one of the resistors, and the thermistor itself as the other resistor. This makes it easy to determine the resistance of the thermistor based upon the observed voltage. The vast majority of "normal human temperature" thermistors vary up to 10k Ohms, so a 10k Ohm resistor is all that is needed to create the circuit.

voltage divider

Converting the resistance to temperature is, unfortunately, pretty complex. Unlike the trusty TMP36, a linear equation will not do (although a linear equation can act as a reasonable approximation over small temperature ranges). Instead, the generally accepted solution is to use a third-order approximation known as the Steinhart-Hart equation:

Steinhart-Hart equation

But to use this equation, you need to know the values of a, b and c. Often you can get those from the data sheets provided for the temperature sensor (provided you can decipher the data sheet). As I did not know much about my temperature sensor, and it was buried in my ceiling, anyway, I needed another solution. Well, it turns out that if you can get three different temperature readings over a reasonable temperature range, and you pair those readings with the resistance measurements, you can calculate the values of a, b and c. So, armed with a IR thermometer and a small program loaded into my Arduino spitting out the resistance of the thermistor, I turned on the heater and was able to find coefficient values that worked for me.

Three temperatures and some logic

I was now ready to focus on the Arduino side of things. I had the three temperatures I needed: (1) the desired room temperature (via my desires), (2) the current room temperature (via the TMP36) and (3) the current duct temperature (via the duct sensor). It was time to wire all of my experiments together and write some Arduino code.

Arduino thermostat for a 'passive' 24VAC HVAC system, Part 1
Share this
This is the official blog of Todd A. Mancini. All rights reserved. I'm a software guy who dabbles in IoT, music and fitness. I've done the startup thing and also worked for da man at places like Lotus, AltaVista, Microsoft and Red Hat.
Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.