Building A Thermostat Using Arduino

I’ve completed the first pass of what seems to be a popular electronics self-education project: a home thermostat. I’ve already written about some of the software, and now I’d like to share some of the hardware details.

Arduino Thermostat

Detecting the Temperature
The brains of the project is an arduino nano (a digital microcontroller). It has an input connected to a temperature sensor from Adafruit, and it does a little math to convert the analog reading from the sensor into the ambient temperature.

Controlled the HVAC
As the acronym suggests, my HVAC unit has three functions: heating, fan (“ventilation”), and A/C. Each of these is controlled by closing a circuit from a common 24VAC line. If you take the faceplate off my old thermostat, you can see which terminals are used for these functions:
RH: The common 24VAC source
W: Heat
Y: A/C
G: Fan

Connecting RH to W/Y/G will tell the HVAC to kick that function on, so putting a relay between those lines allows me to programmatically flip the switch. I only have two relays (heat and A/C) because I never actually use the fan, but adding that would be trivial. The relays I use can switch 12-240VAC, and require 4-10VDC as digital input, which means 1) it can handle 24VAC on the HVAC side, and 2) it can be toggled directly by the output of my arduino (5VDC).

Setting the Temperature
The arduino is connected via USB to a computer, which sends data to set the desired temperature. The computer runs a program (written in nodeJS) which periodically polls a public Google calendar to fetch the scheduled temperature.

Fun With Logs
The arduino sends logging info back over the cable to the computer, which logs and graphs the data.

Not Pretty, But It Works!
Here is the completed setup. You can see the thermostat sitting on the shelf, and the wires going up to connect to the terminals on the old thermostat. The old unit is still there only for the handiness of the terminals (as opposed to just having wires coming out of the wall). You can also see an unrelated XBee hanging on the wall to the right. That is part of Power Hungry.

I’d love to make the project more permanent, either with a real PCB (if I can get over the pain-threshold of learning and using Eagle to design the circuit board), or at least with a soldered breadboard. I’d also like to come up with a cool case, probably using my 3D printer and some laser-cut acrylic from ponoko. I’d also like to go over the arduino code and clean it up, because I kinda hacked my way through it to get it to work.

The Code
You can get the code (for the arduino, and the graph server) on github.

Published by

Patrick Schless

I'm a (mostly) ruby/rails developer, living in Chicago. I work at Braintree, and I have lots of side-projects.

38 thoughts on “Building A Thermostat Using Arduino”

    1. Hi Elizabeth — Feel free to ping me at patrick – at – and let me know what you have in mind 🙂

  1. Thanks for this writeup. I’m going to experiment with it, because the thermostat in our house is going bad!
    I’m having some trouble with it, because once it goes to cooling mode, if you change the set temperature to where should heat, it is never detected. It goes to off, but never switches to heat.
    And the other way around, if it starts in heating mode, and you switch the desired temp, so that it should cool, it never goes to cooling mode.

  2. I have a side project for u & willing to pay . Small tape recorders ( loop recording ) work off remote control. Is this something u can do ?

  3. Do you have a schematic or circuit diagram for the circuit connecting the HVAC system? I’m pretty sure I know what I need to do, but I just want to be sure when I’m working with higher voltage components.

    1. Hi Dwight,

      I have since moved, and my new apartment doesn’t have central HVAC, so unfortunately this project is moth-balled.

  4. Seems like you got to the point where you can control the system, and then just emulated the original functionality of the thermostat. With the added calendar system.

    I have to wonder if you had given though to possible energy saving methods.

    What if one were to, for instance, leave the ac running for a while, and if the temp is close to the target then switch to just using the fan. Turn the ac off, let it blow cool-ish air to reach the target temp. Same for heat. Maybe there are other things possible. It just seems like you spent very little time on it.

    Not trying to criticize, just wanted to see more. I get the electronics of it, but there seems to be little are in the saving power. There has to be some software tricks to be done.

    1. Years ago, I wrote a program for a Johnson Control thermostat that measured the thermodynamic response of the area under control to predict the time it would take to get the area to a specific temperature at a a specified time so that when you programmed 74 degrees at 7 AM it was at 74 degrees at 7 AM. Not exactly power savings, but makes it warm when you get out of bed in the middle of the winter after being cool all night. A lot of analysis was done of how an area responds to changes in temperature It turns out that all you have to do is monitor the response of the system as an RC circuit, determine the values of R and C and use them to predict the time needed from the starting point to the end point. that is good enough for a first order of approximation.

  5. Patrick, I’m extremely interested in this because I’m currently building a cooling unit for my computer out of an old electric water cooler. Basically I’m going to use the cooler’s tank to chill the non-conductive fluid instead of radiators. The problem is I know that I cannot run it full cycle even with the thermostat that it comes with fully adjusted without condensation. My question is, is it possible to build and program this type of device to lock the fluid 10-15 degrees below ambient to avoid condensation?

  6. Hi there, just became alert to your blog through Google, and found that it’s really informative.
    I’m gonna watch out for brussels. I’ll
    be grateful if you continue this in future. Many people will be
    benefited from your writing. Cheers!

  7. It is really a nice and helpful piece of info. I am glad that
    you shared this helpful info with us. Please keep us informed like this.
    Thank you for sharing.

  8. I have a situation where Heating system is through wall mounted thermostat controlled by actuator valve.
    And Cooling system is through window air conditioning system.
    I need to control Heating and Cooling through single controller thermostat or remote.

  9. I must say it was hard to find your blog in search results.
    You write great content but you should rank your page higher
    in search engines. If you don’t know 2017 seo techniues
    search on youtube: how to rank a website Marcel’s way

  10. Hello admin, i must say you have very interesting posts here.
    Your website can go viral. You need initial traffic boost only.

    How to get it? Search for: Mertiso’s tips go viral

  11. I see you don’t monetize your page, don’t waste your traffic, you can earn additional cash every month because you’ve got hi quality content.
    If you want to know how to make extra $$$, search for:
    Boorfe’s tips best adsense alternative

  12. Thanks a lot for the helpful write-up. It is also my belief that mesothelioma cancer has an very long latency time, which means that signs and symptoms of the disease may not emerge right until 30 to 50 years after the initial exposure to asbestos. Pleural mesothelioma, which can be the most common type and impacts the area across the lungs, might result in shortness of breath, upper body pains, along with a persistent cough, which may produce coughing up blood vessels.

Leave a Reply

Your email address will not be published. Required fields are marked *