Building a wireless thermostat using Arduino/1

Starting from this post, we’ll publish a series of tutorials that show how it’s simple to build custom and complex wireless solutions using Arduino and AirQ Networks products.

heating-systemThe first tutorial we publish is maybe the most simple but it’s the bare bone tutorial of all DIY and makers: a Wi-Fi thermostat. Unless you are one of those lucky people that live in that areas of the earth where there are 25°C during all the year, a thermostat is useful both during winter and summer. During winter a thermostat can control the heating system as well as conditioning system during the summer. But often devices are placed far from where we need to control them. And this is especially true for boilers that are usually placed inside specific rooms (see left picture).

So wireless is a crucial point to design a flexible and adaptive thermostat. But we want to go further. In the Internet of Things (IoT) era, we want to design a thermostat that is smart and that we can control from the web wherever we are.

Bill of material

This tutorial is divided in three parts. In the first part, we’ll design a really simple but functional thermostat able to control a remote boiler according a hardcoded temperature. To do this step we’ll need:

For the second part of this tutorial we’ll need:

For the third part we’ll need:

  • an Arduino Ethernet shield;

In addition to these components, a breadboard and some patches are required. However, you are totally free to arrange the project as you like.

First step

The first step of this tutorial is the simplest one, and it can be arranged in less then ten minutes. We’ll use a temperature sensor to detect the ambient temperature and when this temperature goes under a given threshold we’ll turn on the RELAY1 of an AirQ 305 control board. When this happen, a led connected to Arduino will turn on: this is really useful to understand that the boiler is turned on. In this tutorial we assume that the boiler is connected to the RELAY1, but in the real word this connection depends on the specific heating system.

The hardware setup

The hardware setup for this step is quite simple. The following diagram, made with Fritzing, clearly shows wiring.


Let’s describe it.

The first step is mounting the AirQ ShielD on Arduino. This is a trivial task, but if you are new to Arduino world we suggest to take a look at our survival guide.

Next, we have to interface the temperature sensor. The TMP36 is a temperature sensor by Analog Devices. It’s quite popular in DIY world, it’s inexpensive and it has a good measuring precision without calibration. We worked a lot in the past with this transducer, and we know that a 0.5°C precision can be achieved with a very little effort. There is only a trick to know if you want to take the best from it: it’s important to add a bypass capacitor between +3V3 and GND really close to the sensor. To be honest, it’s not a secret. It’s just what ADI says in its datasheet :-). But there are a lot of tutorials around in the web where this requirement is omitted. So, if you are not interested in really high precision, you can avoid to put that capacitor. Otherwise it’s important. For the sake of completeness, the capacitor should be a ceramic SMD capacitor placed on the same PCB layer of the TMP36 lead connection. However, the type of application we are doing doesn’t demand this high precision.

Next, looking at the above draw, we can see another wire between AREF pin and +3V3 pin. We added that wire because we’ll use external voltage as voltage reference for the analog input. For several reasons we won’t address here, it’s not suitable use the default voltage reference to compute A/D conversion of TMP36 output. So, to achieve the best precision, it’s better to use external reference and connect AREF pin to the +3V3 output.

Finally, we added a led to signal that remote RELAY is ON (this tutorial assumes that the AirQ 305 control board is far away from Arduino). The resistor in the above draws is just a current limiting resistor that avoids the led destruction.

The code

The code for this part of the tutorial is straightforward. But we’ll spend some minutes to comment it.


The first 22 lines of code are related to the sketch setup and are almost self-explaining. desiredTemperature is the variable where we set wanted ambient temperature. In the next part of this tutorial we’ll allow the user to setup the temperature using switches but until then this is the way to do it. sensorPin contains the Arduino analog pin where the output of TMP36 is attached. In setup() routine we set the external reference for A/D to EXTERNAL AREF pin, and we configure the pin 4 as output: that pin is used to blink led on/off. getTemperature() function is where we do A/D conversion and compute the temperature provided by TMP36. According to its datasheet, TMP36 has an offset of 500mV to allow negative temperatures without the need for negative voltages. Moreover, the sensors gives an output of 10mV for each °C.  The formula inside getTemperature() function address this.

The rest of the sketch is all about temperature regulation. If ambient temperature is lower than (desiredTemperature – 0.5) °C, it turns the RELAY1 ON (we assume that boiler is connected to RELAY1). Otherwise, we turn it OFF. Finally, when RELAY1 is ON, we turn on the LED attached to digital pin 4.

The following video shows how thermostat works :-)


The source code of this sketch is inside the example subdirectory of sNET repository, or it can directly downloaded using this link.

Be Sociable, Share!

Posted on by admin in Arduino, Hardware, Tutorials 3 Comments

3 Responses to Building a wireless thermostat using Arduino/1

  1. Pingback: Building a wireless thermostat using Arduino/2 | AirQ Networks Development Blog

  2. Pingback: Building a wireless thermostat using Arduino/1 | AirQ Networks Development Blog |

  3. cosmosuave

    Perfect just what I have been looking for as existing hardwired thermostat has been placed on an exterior wall and does not do a very good job controlling the temp be it summer or winter… With this I will not have to put holes in my walls… For the base control unit what would be the best way to provide power other than batteries?

    I do have a spot where my home alarm control panel is that I could mount the base control unit and tap the power supply there for it I guess…


Reply to cosmosuave