Building a connected thermostat

Updated: Aug 11, 2020

Time to cook: 120min

Difficulty: +++++


This recipe is a step-by-step plan to build a connected thermostat. In this recipe we will cover the hardware and connectivity part to monitor the ambient temperature and humidity in a room and actuate a relay. In following recipes we are going to cover the UI part to set the temperature, making it a true look-alike NEST thermostat!

We will use the Arduino MKR1010 WiFi board and a DHT temperature & humidity sensor connected to the AllthingsTalk Maker platform.



 

Ingredients


  • Arduino MKR1010

  • MKR Grove Shield

  • DHT11 Temperature & Humidity sensor

Prerequisites



Tools

  • Arduino IDE


 

The Building Plan


Create a digital representative for the thermostat on AllThingsTalk Maker


  • Login with your ATTALK Account on https://maker.allthingstalk.com

  • Under your playground (or another ground) create a ‘Your own’ device from the WiFI/LAN devices hardware tile

  • Give the device a name (eg : Smart Thermostat)

  • Under the device, create an asset of the type sensor with a name called ‘temperature’ and select number as profile type and select advanced as profile type and enter the following JSON information:


{ "type": "number", "unit": "°C" }


  • Under the device, create an asset of the type sensor with a name called ‘humidity’ and select number as profile type and select advanced as profile type and enter the following JSON information:


{ "type": "number", "unit": " %RH" }


  • Under the device, create a virtual asset of the type actuator with a name called ‘relay’ and select boolean as profile type



The result should look as follows:




Note: Under the ‘settings’ in the tab ‘Authentication’ you will find the device Bearer Token and Device ID. Remember where to find them, you will be needing them later



Assembling the Hardware


  • Connect the Grove Shield onto the Arduino MKR board

  • Connect Grove - Temperature & Humidity Sensor Pro to port D2 of Grove-Base Shield.

  • Connect Grove - relay to port D0 of Grove-Base Shield.

  • Connect the Arduino MKR1010 WiFi board with a via USB onto your computer




The shield & module can be powered with a 5V power supply. The relay N.O. contact can be used to control the heating system. You can in most cases use the existing wiring from your old thermostat to connect to the heating system. (cfr your heating manual)


Installing the Arduino libraries



Note: If you are not familiar with the Arduino IDE, the following tutorials might help:


Configure & Upload the Arduino Sketch


  • copy paste the sketch (see below)

  • Complete the keys.h file with your DeviceID and Device Token. You can find them under the ‘settings’ in the tab ‘Authentication’ you will find the device Bearer Token and Device ID

  • Enter the WiFi credentials

  • Upload the sketch on your Arduino device



Testing the device


Open the serial monitor on the Arduino IDE. You should see that the device is registering to your WiFi SSID, subscribing to the MQTT topics.




Look at the device assets on your digital representative in AllThingsTalk Maker you have created in the first step. You should see the data coming in.



Next, let’s see if we can actuate the relay from AllthingsTalk Maker.


  • Select your device on AllThingsTalk Maker

  • Click on the ‘+’ sign in the upper right corner and select create pinboard

  • On the Pin device assets screen click ‘create pinboard’

  • toggle the switch on the relay control

  • You should see the payload in the debug window of the Arduino IDE and the relay attached to the MKR1010 should turn on




Note: optional, you can create the Smart Thermostat also as a ‘Thing’ on your Smart HUB. This can be achieved using MQTT with the integration described in the recipe: ‘Connect to an external MQTT Broker’

1 view0 comments

Recent Posts

See All