Making your own smart ‘machine learning’ thermostat using Arduino, AWS, HBase, Spark, Raspberry PI and XBee

Previous part:
4. Storing data in the Amazon Cloud (HBase)

5. Turning the boiler on and off at the right time (Arduino)

5.1 Six boiler on/off intervals per hour (understanding how a thermostat works part II)

After finishing the previous part, I collected the temperature sensor data and the data from the photo resistor for a couple of weeks (when the normal thermostat would turn the boiler on and off).

The next step was to turn the Arduino into an actuator and let the Arduino turn the boiler on and off, Thus turning the Arduino into a thermostat.

Looking at the collected information I noticed that regardless of the temperature and difference between the set and actual temperature the thermostat would never turn the boiler on and off more than 6 times per hour. Regular intervals can be distinguished between every moment the thermostat turns the boiler on. Looking at the data in more detail I saw that when the temperature difference between the set and the actual temperature was smaller it would turn the boiler on for a fewer number of minutes than with a bigger difference, as can be seen in figure 9.

Figure 9: six boiler on/off intervals per hour

Knowing now what to search for, I searched the Internet for the interval value of a thermostat. And this was exactly how a thermostat worked. For most thermostats the interval per hour is a setting, ranging from 3 to 12 intervals per hour. Unless you have a system that does not have gas fired furnace, for example a heating system that uses excess heat from a power plant (something that is common in Amsterdam), you are supposed to turn your boiler on and off only a couple of times per hour. The first reason is for this is that if you constantly turn your boiler on and off you would break it. The second reason is that it takes a while before the room temperature increases after the boiler turns on the heat. This depends on the distance between the boiler and the thermostat and how long it takes for the room to absorb the heat form the radiators. This also explains why my normal thermostat sometimes overshoots and the room gets a lot warmer than the set temperature. In figure 9 you can see it actually takes 10 minutes before the room gets warmer after the boiler is turned on.

5.2 Thermostat Hardware (final breadboard layout schematic)

The hardware to turn the boiler on and off is the simple relay schematic from the ARDX starter kit . The relay was added on a separate breadboard, which was added to the setup explained in part 2 of this blog post. The final breadboard layout and schematic for this project are shown in figure 11 and 12.

5.3 Arduino thermostat code

To control the boiler with the Arduino I used the same interval pattern. I created three run levels and three functions. The run levels are in the main loop()of the arduino.

The first run level (level 0) is the off state. In this level it checks, with the function frunScen(), weather it is necessary to go into on mode. If the temperature difference is more 3,5 degrees Celsius it goes to the second run level.

In the second run level (level 1) the Arduino decides for how long it should turn the boiler on. For this it uses the function fscenLenght() that takes the temperature difference as input. It then proceeds to the third and last run level.

The third run level (level 2) always runs for 10 minutes. This level takes the ‘duration the boiler has to be on’ as input. Every cycle in the third run level, the Arduino checks if the boiler should still be on, using the fboilerStat() function. If the amount of on time or the desired temperature has been reached in turns the boiler off. The fboilerStat() function ads 3.5 degrees Celsius to the set temperature to allow for a temperature decrease when the boiler is turned off. After ten minutes the run level goes back to 0.

To monitor the Arduino thermostat, the set boiler state and the time the Arduino decides the boiler should be on are also send to the Raspberry PI and subsequently forwarded to the Cloud server. Allowing analysis of the workings of the thermostat. The result can be seen in figure 10, showing that the Arduino perfectly mimics my normal Honeywell thermostat.

Figure 10: Arduino thermostat

Thermostat main loop

Thermostat functions

Figure 11: Final breadboard layout

Figure 12: Final schematic

Next part:
6. Using outside temperature and scenarios to control an Arduino from a Raspberry PI

2 thoughts on “Making your own smart ‘machine learning’ thermostat using Arduino, AWS, HBase, Spark, Raspberry PI and XBee

  1. Pingback: Enabling technologies: how to build your own NEST | SmartDomus

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s