Introduction
As part of my heating system I have discussed how I am building a set of thermostats that can control the baseboard heaters in my house. The vast majority of these heaters are not located near my PC, electrical box or any of my other computer hardware.
However there is one, that is located in my office close enough to my router that I can connect it up via Ethernet rather than WiFi.
This post will begin looking at prototyping the Ethernet model. A prototype is a handy way of testing the components we have purchased and experimenting with the equipment before we solder it together.
Components required
For the Ethernet model of the thermostat the following components are required:
- Arduino Uno
- Temeprature sensor
- Visual display unit
- Ethernet shield
- Buttons/manual method of input
- Power supply
- Ethernet cable
- Relays
The picture below shows a group of components I purchased to build the Ethernet model and to prototype with. It includes:
- An Arduino Uno
- Seeed Studio Ethernet Shield
- Temperature sensor purchased from Adafuit – AM2302
- All in one TFT screen + button joystick – 1.8″ TFT

Thermostat components
First steps are prototyping
The prototype we will be exploring below will build a simple thermometer.
For the prototyping I will not be using the TFT Shield to start with. This is primarily because I am evaluating screen types, which are the best and which ones are better suited for certain locations in the house.
There is a separate post in the works for this, and the outcome of that evaluation will result in the chosen screen type when I blog about turning the Ethernet prototype into the production model.
So to start with we will hook up Arduino, Ethernet shield and temperature sensor and test it works.
For the temperature sensor there is code available via the Adafruit site for testing purposes. This can be downloaded here, along with the instructions for wiring up your equipment.
The picture below shows the temperature sensor wired up.

Temperature sensor
Once the sensor was wired up I tried out a few of the test sketches that could be downloaded from the above link. Once I was happy this worked, I then attached the Ethernet shield to the Arduino and attached the temperature sensor to the Ethernet shield.
The picture below shows this setup. Note: At this point I haven’t done any soldering.

Ethernet shield
File->Examples->Ethernet->Web server
example.
Modify the settings in the code to assign it an IP# for your local network and upload it to your Arduino. Once done, you can plug in the Ethernet shield to your router and access the IP# you assigned it via a browser on a home computer or tablet.
If you receive the “analog input” message on your screen as a web page, your test has been successful.
For our next test we are going to merge some of the code from the web server example and the temperature example that you downloaded from the Adafruit website.
First, attach your Arduino back to your PC if it isn’t already setup.

Ethernet and Thermostat
Take the following test code and paste it into the Arduino IDE.
Test code.
/*
Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modified 4 Sep 2010
by Tom Igoe
modified 18 Oct 2012
by Andy Dennis
DHT test
Returns temperature and humidity.
modified 18 Oct 2012
by Andy Dennis
*/
#include "DHT.h"
#include <spi.h>
#include <ethernet.h>
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);
DHT dht(DHTPIN, DHTTYPE);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup()
{
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
dht.begin();
}
void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
client.println("Failed to read from DHT");
} else {
client.print("Humidity: ");
client.print(h);
client.print(" %\t");
client.print("Temperature: ");
client.print(t);
client.println(" *C");
}
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
The above code is simply a combination on the Web server sketch and DHTester sketch combined.
You can modify the IP# on this to assign it one on your home network and change the output message if you like.
Now upload this to your Arduino and hook it back up to your router.
With your PC/Tablet, now hit the IP# you assigned it via your web browser. You should see something like the following (provided you didn’t modify the message)
Humidity: 52.3% Temperature: 26 C
This confirms that the temperature sensor is working, and the data can be output via HTTP over Ethernet.
Next Steps
Obviously this is a very simple example, and doesn’t do what we need it to yet. However it demonstrates some of the technologies we plan to use, and also confirms that our components are working. We also have a working thermometer as a by-product of our tests.
Our next steps will be as follows:
1.) Choose the correct VDU (visual display unit)
2.) Test the VDU alongside the prototype code
3.) Write the code to output the temperature over HTTP and to send the data back to the Raspberry Pi
4.) Write the code to manipulate the baseboard heaters
5.) Solder the components together
6.) Place them in a case
7.) Wire the new thermostat unit into the baseboard heater, and attach it to the wall.
I’ll be blogging on the above to provide an easy guide to completing the production model, and also adding the code to BitBucket.
Summary
The above example has shown that a quick prototype can be used to test our components before writing a lot of code and soldering equipment together.
The next post in this series will be dedicated to testing the VDU and assigning one to the prototype that is easy to use and displays the data we need it to.