Introduction: Smart Home Thermostat

About: Technologist, Electronic Engineer, sometime Coderdojo mentor.

These days we hear a lot about the Internet of Things and how Smart Devices will be Internet enabled to do cool things and make our lives better. Smart Thermostats have the capability to save a lot of energy by keeping the temperature of your home steady, heating your water to just the right temperature, and giving you controllability from your smartphone from anywhere. So no need to leave the heat on when it's cold and your going out just so it will be warm when you get home. Just turn on the heating from your phone.

In this project we'll be using the Spark Core, which is an Arduino compatible, Internet Connected microcontroller. Being Arduino Compatible you can program it using the Arduino programming language. Being Internet Connected you can program it over Wifi, remotely read program variables and acitvate program functions remotely. Perfect for our Smart Home Thermostat.


  1. Controls 3 Mains devices up to 40W each (Boiler, 2 Electro-Mechanical Valves)
  2. Sense Temperature at up to 4 Locations
  3. Turns Electro-Mechanical Valves On/Off to control the temperature of the house
  4. "Heat Water" mode (Boiler On, Valves Off).
  5. Android App to monitor temperatures, change Setpoint and Turn on/off.


By the way. If you like this Instructable, you might also like to read My Blog covering various projects and Tutorials.


Step 1: You Will Need

  • Up to 4x Temperature Sensor ICs : TMP36 or LM35
  • LEDs (Red)
  • Multicolour (RGB) LED
  • 6 x 220 Ohm Resistors
  • 3x 100 Ohm Resistors
  • 1x 10k Ohm Resistor
  • 1x Push Button
  • 4 x Main Rated Terminal Blocks (5 way)
  • Potentiometer (100k)
  • Veroboard (or design your own PCB).

Step 2: Mains Control

CAUTION: There are Mains Voltages involved in this project. The
design is opto-isolated, but poor construction or housing could expose the user to lethal Voltages that could cause death. If you don't feel satisfied you can build this safely then please do not proceed.

We're going to use a Photovoltaic Relay (see picture) to control the mains because it's:

  • Mains Rated (250V AC)
  • Opto-isolated for safety
  • Solid-State for reliability
  • <10mA turn on current so it can be driven directly by the Spark Core
  • Can switch 170mA (max) at 250V

170mA mains switching may not seem like much (40W), but it's enough to drive an electro-mechanical valve, so it can control the water to a radiator system (On / Off). If you need more power to control your boiler you can use it to drive the coil of a mains relay and make sure the relay contacts are appropriately rated for the load you require.

Step 3: Schematic and Hook-Up

Here's the Schematic of how to wire it up and a picture of one I made earlier.

Make sure the mains voltages are safely isolated from the low voltage side of the circuit.

I housed the Temp Sensor and the RGB LED in an existing (old) thermostat housing.

As I mentioned the 3 mains relays control the boiler, and 2 electromechanical valves.

The variable resistor and push button are used for manual override.

If you need to override the set temperature, turn the Pot clockwise, The setpoint will be the maximum of the programmed value or the value set by the pot.

Step 4: Spark Core Code

You can find the code over on Snip2Code.

Step 5: Internet Control

Use GET requests to interrogate the Spark Core to get temperatures etc..{DEVICE_ID}tempDOWN?access_token=123412341234

you should see something like this coming back:

"cmd": "VarReturn",

"name": "tempDOWN",

"result": 208,


{ "last_app": "",

"last_heard": "2014-10-24T20:25:07.191Z",

"connected": true,

"deviceID": "6758576856786fffed"



where "result": 208 means that the value (i.e.e temperature downstairs) is 20.8 . The float value is multiplied by 10 so it can be sent as an INT .

Use POST commands to change the setpoint:

POST /v1/devices/{DEVICE_ID}/SetVal

# EXAMPLE REQUEST IN TERMINAL # Core ID is 0123456789abcdef # Your access token is 123412341234 curl \ -d access_token=123412341234 \ -d params=SETDOWN:200

For guidance see, examples on Spark Core over at

That's it.

Once you have the GET and POST working you can embed that into an Android app. You can even use App Inventor so it's dead easy.

Also, you can log the data to a Google Drive Spreadsheet. The following line of code

sprintf(resultstr, "{\"data1\":%d,\"data2\":%d,\"data3\":%d,\"data4\":%d}", tempDOWNInt, tempWATERInt, tempOUTInt, State);

writes the relevant variables out to a string that can be read by the Spreadsheet.

See here for details.


Step 6: App Inventor

If you want to use App Inventor to make the App the only thing that's not totally straightforward is the Web Connectivity.

Use the Web block to perform the REST functions :

Call the Web GETs on a timer tick as shown and deal with the receive event as shown.

Microcontroller Contest

Participated in the
Microcontroller Contest