How to Build your own Arduino Thermostat

If you are looking for information about how a thermostat works and how you can build your own DIY Arduino Thermostat, you are at the right place, keep reading or bookmark this page for later!

Before I start, I should say that I have been postponing this post for quite some time, the main reason is that you can’t write a tutorial on how to create an Arduino Thermostat, because every HVAC unit is slightly different. For that reason, I have decided to explain how I built mine hoping that some people might get some inspiration out of it.

What will You find here?

  • Basic understanding of what is a thermostat and how does it work.
  • Different examples of thermostat wiring diagrams.
  • How to reverse engineer your own thermostat.
  • How I built my DIY Arduino Thermostat.

 

If you are starting with Arduino you should check the Arduino for Dummies Guide, it will help you get up to speed.

Introduction to Thermostats

Before we get into details on how you can approach building a DIY Arduino Thermostat, I want to walk you through the basics of the different types of thermostats and how do they work, if this is too basic for you, skip to the building part.

Thermostat Definition

I know this is very to basic but I needed to start with something…

Speaking in general terms, a thermostat is a device that senses the temperature and takes action to elevate or decrease it until it is as close as possible to the setpoint or target temperature. Although this post will only focus on HVAC machines, there are tons of systems that require a thermostat: a water heater, an oven..etc.

In case you didn’t know (I didn’t), HVAC stands for Heating, Ventilation and Air conditioning. On this post, I will explain to you how to have basic control over your HVAC system (if you have one) using an Arduino.

Thermostat vs thermometer

You may know this but since some people asked me about it I am going to through a few words…

The main difference is that a thermometer only senses the temperature and provides information, it doesn’t take an action to affect the ambient temperature. A thermostat on the flip side, not only monitors the temperature but it is also able to regulate it using things like your central heating system.

Different Types of Thermostats

Let’s talk about the different types of thermostat from 2 points of view, the wiring and the functionality that they offer.

Wiring

There are several types of thermostats. In this section, I will talk about the most popular ones and will give you some tips on how to identify them.

Line-Voltage Thermostats

This type of thermostat is generally used for single heating systems like baseboards or radiant systems. The way they work is actually pretty simple. The thermostat is connected in series with the heating system and when the device reaches the setpoint temperature, it stops the current from flowing through the thermostat. These type of systems are generally connected to 240V so be careful if you decide to manipulate it. Not that 120V can’t get you in trouble…

Low-Voltage Thermostats

Nowadays, the low-voltage thermostat is the most common option for home installations. You will find them controlling all sorts of central heating systems that use oil, gas or electricity. This type of thermostats has several advantages over the line-voltage type:

  • They are more efficient in the way they handle the flow of current.
  • The operating voltage is between 24v and 50v hence reducing the exposure to higher voltages. That is the reason because you see that the cables inside of the thermostat are not as thick as for the first type.
  • There are lots of options in the space of programmable thermostats.

The main difference is that the low-voltage thermostats don’t control directly the flow of the current but rather tell the central heating system what to do to do based on the ambient temperature.

If you are looking to see what type of thermostat you have installed at home check the following Blog post.

Outlet Thermostats

These are not very common but you can still see some of them around. For the sake of simplification, I will tell you that they are like a smart plug with a temperature sensor. It allows you to specify a setpoint temperature and when it is reached, it turns itself ON or OFF. Pretty simple isn’t it?

Functionality

Regardless the type of thermostat, some of them can be programmed up to a certain degree. I can mainly think of three types. I don’t sell thermostats so this classification is completely made up…

Dumb Thermostat

This is the most absolutely basic type of thermostat. You select a setpoint temperature and the thermostat will do its best to keep it within the range.

 

Arduino Thermostat - Dumb Thermostat

 

Not-So-Dumb Thermostat

In this category, you will find thermostats that are slightly more expensive but deliver significantly more functionality. They are based on the same principals as the dumb thermostat but provide you with a much more granular way to specify the temperature.

For example, if you follow a similar schedule every week in terms of what time do you wake up and what time you come back from work you can program your  Not-So-Dumb Thermostat to warm up the house right before you need it and keep it off the rest of the time. This can already result in a great deal of savings for your utility bill.

Arduino Thermostat - Programmable Thermostat

Smart Thermostat

The Smart Thermostats go a step further to help you save energy at home. Some features that you may find on Smart Thermostats are:

  • Ability to program the temperature with a great deal of granularity.
  • Presence detection to keep the temperature in check only when somebody is at home.
  • Voice control using devices like Google Home or Amazon Alexa.
  • Control the settings with your smartphone when you are not home or when you are home but you are too lazy to walk to the thermostat.

Arduino Thermostat - Smart Thermostat

 

What we are trying to build on this post is the foundations of a Smart Thermostat.

Thermostat Wiring Diagram for Low-Voltage

Here is the last bit of theory before we get down to business building the DIY Arduino Thermostat.

The table below gives you an idea of the color and function of the terminals according to the industry standards. The tricky part here is that the industry standards aren’t always the standard

 

Color Terminal Code Purpose Description
Red R 24 AC Power This is the 24V power terminal. Most of the low-voltage thermostats work with this voltage although you can find them all the way up to 50V.

It is not uncommon to find 2 red cables RH and RC. In this case, both carry 24VAC and you can use them to energize separately heat and cool.

Black C 24 AC Common This is the common ground for the 24V.
White W Heat This is the terminal to be energized for the heat
Yellow Y Compressor This is the terminal that energizes the compressor.
Orange O RV On In Cool O and B terminals interact with the reverse valve. The reverse valve controls the flow of refrigerant in the piping system, basically allowing you to provide cool or hot air.
O energized calls for cool air.
Blue B RV ON In Heat Same as the terminal O but to call for heat. It is very common to see these two terminals combined into one with the legend O/B.

The industry standard is that when O/B is energized the unit provides cool air. If it is not energized it provides heat. As always, this depends on the HVAC unit.

Green G Indoor Fan The green terminal usually controls the fan to the level that your system allows it.
No Standard Defined Y2 2nd Stage Cool Y2 basically activates a feature to boost the power of your compressor. It is only required on climates that are extremely hot.
No Standard Defined W2 2nd Stage Heat Similar terminal to Y2 but to provide heat.
No Standard Defined E Emergency Heat This feature turns off the heat pump on an emergency and switch to electricity.

 

I want to do my best to give you an understanding of what you will find when you open your thermostat so I will do two things. First, I will give two of the most common examples that you can find. Second, I will provide you with the steps that I followed to find out how mine works, I hope that helps…

Thermostat Wiring Diagram: Example 1

Color Terminal Code Purpose
Red R 24 AC Power
Black C 24 AC Common
White W Heat
Yellow Y Compressor
Green G Indoor Fan
  • HEAT:  In most cases, connecting R to W will turn ON the heat. Sometimes you also need to connect R to G. That depends on your system.
  • AC:      In most cases, connecting R to Y will turn ON the AC. Sometimes you also need to connect R to G. That depends on your system.

I say sometimes because this depends entirely on the manufacturer, DON’T TAKE ANYTHING FOR GRANTED.

Thermostat Wiring Example 2

Color Terminal Code Purpose
Red R 24 AC Power
Black C 24 AC Common
Yellow Y Compressor
Orange O/B Reverse Valve
Green G Indoor Fan

This is a slightly more complicated case.

On this schema, you have to energize Y to start blowing air, then, depending on if O/B is active or not it will blow hot or cold air. As in the prior case, sometimes you will have to energize also G.

As I said, this is what I have seen based on my experience replacing thermostats, having said that, I am not a technician so there is probably a whole world out there that I don’t know about…

To finish this section I want to walk you through the steps that I took to find out how my HVAC thermostat worked. This is what helped me to reverse engineer and replicate the same behavior using relays and an Arduino.

How Does your Thermostat Work?

1. Open your current thermostat and check how is it wired.

If you see five or more thin cables with different colors, chances are that your unit is using a low-voltage thermostat. If this is not your case, it is probably a line-voltage thermostat.

You can also see if the legend on your terminals looks alike any of the examples above.

If you remove any of the cables make sure you take a picture first, if your memory is a good as mine, you won’t remember later…

2. Search for your thermostat specs on the internet. 

Check what the manufacturer says about the unit. In my case, I needed to connect R to Y to turn on the unit. If O/B is not energized it blows hot air, if it is energized it blows cold air. The terminal G is automatically turned ON when you energize terminal Y.

Trust, but verify

Even if the specs of your unit are crystal clear, which they are usually not…it is always good to verify that the understanding of the wiring is correct.

3. Verify your understanding using a multimeter

In order to verify that your understanding is correct, you can use a multimeter. Measure the voltage between the terminal C and the rest of the terminals. Set your thermostat on the different modes (AC, HEAT…) and check what terminals are energized on each function.

This will give you a pretty good idea of the terminals that you will have to connect to activate the different modes.

I am sure you know this but do not ever let R and C terminals get in touch, the outcome of this can’t be good…

How to Build your own Smart Arduino Thermostat

While I generally try to write detailed tutorials suitable for everyone, this is most definitely not one of them. I am not an HVAC expert, just a guy with a lot of curiosity that has done some research so please, if you decide to do this project, you do so at your own risk. If you don’t have at least a basic understanding of electricity an electronics I would advise you against it.

Things that you should know before you start:

  • The Arduino Thermostat project is based on the MySensors framework so you should first get familiar with it. I would recommend you to follow the DIY Home Automation Sensors tutorial because it will help you get up to speed in no time.
  • You should have a decent understanding of Arduino and how to program it. If you are not yet familiar with it. Check Getting Started with Arduino.
  • If you haven’t played with relays before check How to control a relay with Arduino. I would add the info here but to be honest, the internet is full of tutorials about that…

Shopping List

Here is the list of components that you will need, if you have followed DIY Home Automation Sensors you should have everything except for the relay board already.

Units Description AlliExpress Amazon
1 NRF24L01 Link Link
1 Arduino Nano  Link Link
1 Jumper Cables Link Link
1 DHT22 Temperature and Humidity Sensor Link  Link
1 4-Channels –  Relay Board Link 

For this project, I am using the Arduino Nano, mostly because I don’t have size restrictions but any Arduino will do it though.

What is Relay?

A relay is an electronically operated switch…what? Long story short, a relay allows us to open and close a circuit driving a high voltage load with a low voltage signal, 5V in this case, like the one that Arduino can provide. This magnificent component provides a small microcontroller with the ability to control devices that require higher voltage, like a bulb for example.

At this point, you might already have an idea of how the relay is going to help us here. The relay will energize the different terminals connecting R to Y and O/B resulting in our HVAC turning ON the HEAT or the AC.

Arduino Thermostat: Wiring Things Up

If you followed the DIY Home Automation Sensors tutorial you will only have to connect a few extra wires to get your Arduino Thermostat up and running. The diagram that I am going to show is based on my own Arduino Thermostat, you will have to wire things up based on your own findings but I can help you do it if you contact me.

Arduino Thermostat - Wiring Diagram

Arduino Thermostat Code

Same way as the wiring, the code will be slightly different for your Arduino thermostat, you will need to adapt it to your own needs. I have added comments to the code to try to make it as simple as possible. Pay special attention to the function hvacCommand() and to the definition of the pins for the relays, you should be able to use the rest of the code as it is.

 

 

Add the Items to the Home Automation Controller

Here you have the items of items that you will need to add to your items file in case you are using OpenHab.

 

 

Please, let me know in the comments if there is something that isn’t clear or you would like me to add.

 

Future Improvements

The Arduino thermostat has lots of room for improvement, here are a few things that I can think of…

  • Add a motion sensor to turn ON and OFF the unit based on presence.
  • Add an AUTO mode.
  • Include external sensors to capture the temperature of the room at different locations.
  • Include an OLED screen to monitor the temperature.
  • Anything else? tell me about it in the comments.

BK Hobby has great content related to temperature sensors using NodeMCU, if you aren’t subscribed to the channel you are really missing out! I am going to leave you here a video about his temperature sensors in case you want to check it out.

Conclusion

As I said before, this wasn’t a step by step tutorial but rather a walk through. I did a lot of research when I started my Arduino Thermostat Project and I thought it could be useful for some people trying to do the same.

I hope you learned something today and got an inspiration for your next project.

If you like or hate this post please, tell me about it by email or in the comments, also if you have questions of course!

This Post Has 6 Comments

  1. wow, your DIY its incredible. Firts I am sorry of my english, I am from Spain and I dont speak it well. I want to install a duct air conditioner in my new house, and I want to install motorized grids, and controls them with arduino. But I need to replace the control unit of the air conditioned system with arduino. What kind or model of air conditioned do you recommend me to do this DIY?

    Thank you very much.

  2. Que tal Julio?

    Your English is just fine and I am Spanish as well by the way :).

    Where are you from? If you struggle with the language no worries, just email me and I can answer you in Spanish.

    I would not chose a unit based on that. I assume you already have an AC unit which is hooked up to a Thermostat correct?

  3. jajaja, all right…

    Gracias David, jaja, me parto. Soy de Valencia ciudad.

    Te cuento, me encanta arduino y sus posibilidades, de hecho controlo la calefacción (caldera con radiadores) desde cualquier parte del mundo, puedo ver su estado, temperatura de consigna, temperatura del salón, etc (todo a través de thingspeak). Con ello quiero decirte que tengo algunos conocimientos tanto de electrónica como de programación, aunque soy mas un roba código.

    Bueno, la cuestión es que me vot a hacer una reforma integral en una vivienda y quiero meter una bomba de calor y A/A por conductos, pero claro, lo que me gustaría es poder domotizarlo y meter rejillas motorizadas en todas las estancias. Pero claro, me enfrento al problema de la “unidad central de control por cable” del equipo con su respectivo sensor de temperatura, que es en definitiva el que hará que la máquina se mueva o se pare.

    Lo que quiero es, tal y como has hecho tú, saltarme la unidad central de control y sustituirla con un arduino, proporcinarle wifi para su control externno, y por supuesto con sus rejillas motorizadas.

    El problema, como te he dicho es el control del equipo en sí, porque claro, si tengo la habitación en la que se encuentra el sensor de temperatura principal a la temperatura de consigna, el equipo se apagará, estén como estén las temperaturas de las otras habitaciones.

    Así que lo que pretendo es que cada habitación esté a la temperatura deseada, en plan Air Zone, pero DIY.

    Así que lo que haré será domotizar todas las rejillas mecanizadas, controladas con arduino con un sensor de temperatura en cada habitación, y por supuesto con tu pedazo de proyecto, que es lo que ando buscando. Poder activar el equipo para enfriar o calentar cualquier habitación.

    No sé si me habré explicado bien.

    Para ello lo que necesito saber es el tipo de máquina que debo de comprar, porque sí sé que hay máquinas que en ON/OFF funcionan con 220, así que con un relé me sobraría, pero lo que pretendo es lo mismo que has hecho tú, algo mas “smart”.
    Así que como aun no he comprado ningún equipo, pues sería genial si me pudieses aconsejar sobre qué equipo pillarme para poder automatizarlo a “full”, sustituyendo la unidad central por un arduino….

    Espero no haberte confundido, más que explicado,jajajajajaj

    Gracias por todo y un saludo.

    P.D.: ¿De donde eres?

  4. Hi Julio,

    I will answer you by email so we don’t mix stuff up on the comments 🙂

  5. What are you communicating with? Also, I see no reference in your code to the “recieve” function. Is there something missing?

  6. Hi Jim,

    This tutorial is based upon this other one https://www.smarthomeblog.net/diy-home-automation-sensors/
    It uses a library called MySensors which is where you will be able to find the function Receive.
    The thermostat communicates with a gateway (Raspberry Pi) which then send messages to an MQTT broker.

Leave a Reply

Close Menu