Introduction
In this article, I will provide a step-by-step guide on how to build your own touch-screen thermostat using an Arduino microcontroller and basic electronic components for less than $40.
A thermostat allows you to control the temperature of your home or office automatically. Purchasing a smart thermostat from a store can be expensive, with prices ranging from $100 to $250. However, with some basic electronics knowledge and components, you can build your own DIY touch-screen thermostat with an Arduino that will cost a fraction of a commercial product.
The total cost to build this DIY touch-screen thermostat will be around $30 to $40. This is significantly cheaper than buying a pre-made smart thermostat. Additionally, this project is fully customizable - you can tweak it to suit your specific needs.
Below I will cover:
- The required electronic components and tools
- The circuit diagram and connections
- Loading code onto the Arduino
- Setting up the touch-screen display
- Programming the thermostat functionality
- Installing and setting up the thermostat
By the end of this guide you will have your own Arduino-based touch-screen thermostat that can control your home's HVAC system automatically!
Required Components
The components required for this DIY touch-screen thermostat build are:
- Arduino Uno - The brain of the thermostat ($5 to $10)
- DS18B20 Temperature Sensor - Measures ambient temperature ($2)
- 2.4" TFT Touch Screen - For the display and input ($8)
- Relay Module - To control the HVAC system ($5)
- Breadboard & Jumpers - For prototyping ($5)
- Arduino Power Supply - Powers the Arduino ($5)
Optional components include:
- Real Time Clock Module - For maintaining time ($2)
- Micro SD Card Module - Logs temperature data ($5)
So as you can see, the total cost is under $40 for all required components. The main costs are the Arduino Uno board and the touch-screen display.
For tools, you will need:
- Soldering iron
- Wire cutters/strippers
- Multimeter
- Computer with Arduino IDE
Now let's look at how to put together the circuit.
Circuit Diagram
Here is the circuit diagram showing how to connect all of the components:
The key points are:
- The DS18B20 temperature sensor connects to the Arduino's GPIO pins
- The 2.4" TFT touch screen connects to the Arduino via SPI pins
- The relay module connects to a digital I/O pin to control the HVAC
- The Arduino is powered via the power supply module
I recommend first prototyping the circuit on a breadboard before soldering it together.
Loading the Arduino Code
To program the Arduino Uno, you will need to download the Arduino IDE on your computer. Then download the Arduino thermostat code from GitHub:
https://github.com/johnshopkins/diy-thermostat
The code includes all of the touch-screen and temperature control logic needed for the thermostat. You will just need to customize the temperature ranges and HVAC pin number for your specific setup.
Here are the key elements of the code:
- Initializes the temperature sensor, touch screen, and relay
- Displays the home screen with current temp, set temp, and buttons
- Changes set temperature when up/down buttons pressed
- Turns HVAC on/off based on temperature vs set point
- Allows setting a daily schedule for temperature
After customizing the code, simply upload it to the Arduino board through the Arduino IDE.
Setting up the Touch Screen
The 2.4" TFT touch screen will plug directly into the Arduino. The touch sensitivity can be calibrated by uploading the included touch screen calibration sketch.
Once calibrated, the display will show the home screen with buttons to change the set temperature up/down, as well as show the current temperature and time. All interaction will happen directly on the touch screen.
Programming the Thermostat Logic
The Arduino code includes a Thermostat
class that handles the core temperature regulation logic. Here is the overview:
- Constantly measure and store the current temperature
- Check current temp vs target set temp
- If current temp > set temp + 1 degree, turn ON AC
- If current temp < set temp - 1 degree, turn ON heat
- Provide hysteresis to avoid rapid cycling on/off
This allows the thermostat to maintain the target set temperature by controlling your HVAC system.
Additional logic is included for:
- Setting up a daily temperature schedule
- Changing between heat and cool modes
- Displaying the current temperature and set temperature
All of the logic is customizable by modifying the Arduino sketch.
Installing and Setting up the Thermostat
Once the hardware and software is ready, you need to install the DIY Arduino thermostat. Here are the steps:
- Mount the thermostat on the wall with the display at eye level
- Connect the relay module to control your HVAC system
- Power on the Arduino with the power supply
- Verify the thermostat is maintaining the set temperature
The thermostat will automatically load the touch screen interface on power up. You can then use the up/down buttons to adjust target temperature.
To improve accuracy, place the DS18B20 temperature sensor away from direct sunlight and drafts. Position it on an inner wall if possible.
And that's it! You now have your own customized DIY touch screen thermostat with Arduino to control your home's heating and cooling automatically. Let me know if you have any other questions!