In this tutorial we will show how to build WiFi touch screen thermostat. ESP8266 WiFi touch screen thermostat is example of complex sensor build by ESP8266, Arduino Mega 2560 and TFT 3.2" touch screen display. Thermostat is connected to EasyIoT Cloud and can be controlled over internet.
Main features of thermostat
- 6 modes - Auto, Off, LOLO, LO, HI, HIHI
- Touch screen
- WiFi connected
- Four set temperatures (LOLO, LO, HI, HIHI) and weekly schedule
- Time display
- Additional data display - temperature in other room, air pressure and weather forecast
- Connected to EasyIoT Cloud and can be controlled in WEB interface or native mobile application over internet
Materials
-Arduino Mega 2560
Arduino Mega 2560 | |
$9.97 | |
$6.99 |
-ESP8266 WiFi module
ESP8266 ESP-01 Serial WIFI Wireless Transceiver Module | |
$2.11 | |
$17.00 |
ESP8266 ESP-03 Serial WIFI Wireless Transceiver Module | |
$2.07 | |
$2.15 |
ESP8266 ESP-12 Serial WIFI Wireless Transceiver Module | |
$2.06 | |
$1.75 |
ESP8266 ESP-05 Serial WIFI Wireless Transceiver Module | |
$1.88 |
ESP8266 ESP-07 Serial WIFI Wireless Transceiver Module | |
$2.18 | |
$1.88 |
-BMP180 Digital Barometric Pressure Sensor
BMP180 Digital Barometric Pressure Sensor | |
$1.22 | |
$1.29 |
-DHT22 Digital Temperature And Humidity Sensor
DHT22 Digital Temperature And Humidity Sensor | |
$2.67 | |
$2.45 |
-1 Channel Isolated 5V Relay Module
1 Channel Isolated 5V Relay Module | |
$1.34 | |
$1.12 |
-RTC DS1302 Real Time Clock Module
RTC DS1302 Real Time Clock Module | |
$0.99 | |
$0.82 |
-3.2" TFT LCD Module Touch Panel+ TFT 3.2" LCD Shield Expansion Board For Arduino
3.2 TFT LCD + 3.2 TFT LCD Shield | |
$22.99 | |
$15.45 |
See buying guide at the end for details and please shop in our store to support EasyIoT framework.
Build
Connections
Arduino Meaga 2560 TFT display
This is easy, because we will use shield. Just put TFT 3.2" LCD Shield Expansion Board and 3.2" TFT LCD Module Touch Panel on top of Arduino Mega 2560.
ESP8266
ESP8266 is used as WiFi gateway to EasyIoT Cloud. It is loaded with firmware written in Arduino IDE. In this case we will use HW serial1 on Arduino Mega 2560 to connect ESP8266 module. Follow Connenct 5V Arduino and ESP8266 tutorial to connect ESP module to Arduino. Arduino Serial1 RX pin is 19, Tx 18 and Reset pin is 12. For 3.3V power supply we will use 3.3 V from TFT shield expansion board. See picture below where to connect 3.3 V.
BMP180
Arduino | BMP180 module |
VCC | VCC |
GND | GND |
20 | SDA |
21 | SLC |
DHT22
Arduino | DHT22 |
VCC | 1 VCC |
GND | 4 GND |
8 | 2 DATA |
Relay module
Relay module input is connected to pin 51 on Arduino. We also connect VCC and GND.
RTC DS1302
Arduino | DS1302 |
VCC | VCC |
GND | GND |
11 | CE |
10 | IO |
9 | CLK |
Source Code
Additional libraries are here: lib.
ESP8266 source program
ESP8266 source code can be found at GitHub. Upload program with ESP8266 Arduino IDE. If you are using ESP-01 then keep DEBUG in comments. To enable DEBUG use ESP8266 NODE MCU which allows one additional software serial.
Arduino Mega 2560 program
Arduino Mega 2560 program is available at GitHub.
Before you upload program to Arduino is recommended to change following lines:
#define DEFAULT_AP_SSID "XXXX"
#define DEFAULT_AP_PASSWORD "XXXX"
#define DEFAULT_CLOUD_USERNAME "XXXX"
#define DEFAULT_CLOUD_PASSWORD "XXXX"
Set access point name and password and EasyIoT Cloud username and password. You can later set those settings on thermostat touch screen (Settings->WiFi Cloud), but it's easier to change it in program. Program will automatically add thermostat to EasyIoT Cloud and configure module parameters. Of course you need to register to EasyIoT Cloud first.
Configure EasyIoT Cloud
Automation
Our thermostat also shows temperature and humidity in another room and outside. First add those modules to EasyIoT Cloud. Add three automation programs to forward value of sensors (temperature 1, humidity 1 and temperature 2) to thermostat. In automation (Configure->Automation) add new program and select program type to Forward value. Then select appropriate module and parameter to forward values. Thermostat parameters are following:
Sensor.Parameter4 - temperature 1
Sensor.Parameter5 - temperature 2
Sensor.Parameter6 - humidity 1
Future improvements
This is first version of thermostat. For future versions there is idea to add multiple zones to thermostat. Also display graphic design is basic. If we use SD card attached to TFT display we can create screens with nice graphic.
See more tutorials at http://iot-playground.com/build
Buying guide
To support this site and EasyIoT framework development please buy in our store.
Comments
If I verify your code in Arduino IDE i recieve a error message about MQTT *myMqttPtr; (row 107).
This ino I loaded from GITHUB: https://github.com/iot-playground/EasyIoT-Cloud/blob/master/ESP8266_mqtt_serial_gw/ESP8266_mqtt_serial_gw.ino
I tried a lot of Librarys but it won't help.
I don't understand this error.
Please help.
Thanks.
Bert From The Netherlands.
I would like build this project, but i have DHT22 module (not only sensor), and serial monitor write DHT reading failed, and false temperature on display. How can i modify the code for DHT22 module?
Thansk and regards
Laszlohttps://components101.com/sensors/dht22-pinout-specs-datasheet
The sensor work perfectly in another application.
Thank you, Gabor
I scrupulously followed what was written in the project section.
As for ESP8266 I use a D1 Mini I updated it with the firmware "v0.9.5.2 AT Firmware"
Thanks in advance.
For heating only. You can easy modify this project and add additional DO output to control cooling.
RSS feed for comments to this post