Introduction
In this guide, I will walk you through the full process of building your own WiFi-enabled thermostat using cheap, easy-to-find parts. With some basic electronics knowledge and less than $20 in materials, you can construct a connected thermostat that allows you to control your home's temperature right from your smartphone.
Overview of the Build
Here is a high-level overview of the main steps we will walk through:
-
Selecting the microcontroller - The brain of our thermostat will be a low-cost ESP8266 microcontroller which includes built-in WiFi connectivity. This allows it to connect directly to your home network.
-
Adding temperature/humidity sensor - To monitor conditions, we will use a DHT11 sensor chip. This provides digital temperature and humidity readings to the microcontroller.
-
Connecting a display - For visual output, we will add a basic 16x2 LCD character display. This will show the current temp and humidity.
-
Writing the software - We will write some Arduino code to read the sensors, update the display, and handle connectivity.
-
Constructing the hardware - Finally, we will assemble all the components together on a breadboard and enclose in a case.
Selecting the Microcontroller
The ESP8266 is a low-cost yet powerful microcontroller with integrated WiFi. It can connect directly to your home WiFi network and be controlled remotely. There are a variety of ESP8266 development boards available for just a few dollars. The NodeMCU or Wemos D1 Mini boards are two popular, inexpensive options.
For this project, I chose the Wemos D1 Mini because of its small form factor and ease of use. It has a built-in USB port so it can be easily programmed and powered from any computer or charger. And the integrated WiFi antenna provides good range.
The Wemos D1 Mini packs a lot of punch for the price. Key specs:
- Microcontroller: ESP8266 with 4MB flash memory
- WiFi: 802.11 b/g/n (2.4 GHz only)
- Operating Voltage: 3.3V
- Input Voltage: 7-12V
- GPIO pins for connecting sensors, displays, etc.
- Micro USB port for power and programming
With WiFi, plenty of GPIO pins, and Arduino-compatible firmware, this $4 board has everything needed for an IoT thermostat.
My Reasons for Choosing the Wemos D1 Mini
I selected the Wemos D1 Mini for several reasons:
-
Built-in WiFi - This is the key feature that enables wireless connectivity and control. No need for a separate WiFi module.
-
Small size - Under 2" square, this leaves plenty of space for other components.
-
3.3V logic - Many sensors run at 3.3V, avoiding the need for logic level shifting.
-
Micro USB power - Easy to power from any USB charger. And enables simple programming.
-
Arduino-compatible - Can leverage Arduino libraries and example code.
For this low-cost DIY build, the Wemos checks all the boxes!
Adding Temperature and Humidity Sensing
To create a useful thermostat, we need to be able to monitor the ambient temperature and humidity. For this, I chose the DHT11 sensor. This is an inexpensive, widely used digital temperature and humidity sensor.
The DHT11 provides fairly accurate readings with standard 5V power and a single data pin connection.
Key specifications:
- Temperature range: 0-50°C with +/- 2°C accuracy
- Humidity range: 20-90% RH with +/- 5% accuracy
- Digital output via single data pin
- Low power consumption
- Simple 3-4 pin interface
This sensor contains all the logic and circuitry inside needed to read humidity and temperature levels and output a digital signal. So it's very easy to connect to a microcontroller like the ESP8266.
I opted for the DHT11 over the very similar DHT22 because:
-
Lower cost - Can be found for under $2
-
Good enough accuracy - +/- 2°C is acceptable for a home thermostat
-
Smaller size - DHT11 is more compact
-
Less power hungry - Important for battery-powered use
By keeping costs down and fitting into a smaller case, the DHT11 is a smart choice here.
Adding a Display
To be able to see the current temperature and humidity at a glance, our thermostat needs some sort of display.
The simplest option is an LCD character display. These low-cost modules provide an easy way to output textual data like numbers and text.
For this build, I chose a 16x2 LCD display. This provides:
- 2 rows of 16 characters each
- Standard HD44780 compatible interface
- Large and easy to read 5x8 pixel characters
- Backlight option for visibility
Connecting the LCD only requires 6 wires - 5V power, ground, and then one pin each for digital data, clock signal, and reset. Most microcontrollers have plenty of GPIO pins to handle this.
The 16x2 size shows the key info like temperature and humidity while keeping the display portion compact. And costs under $5.
Why I Picked a 16x2 Character LCD
After considering different display options like OLED and e-ink, I settled on the 16x2 LCD for the following reasons:
- Inexpensive - Usually only $3-5 depending on backlighting
- Easy to interface - With a compatible HD44780 driver
- Compact - Fits in a small case
- Low power - Much less than alternatives like OLED
For showing a few lines of text, the tried and true LCD is a practical choice here.
Developing the Thermostat Software
The software side of this project involves two main components:
- Arduino sketch running on the ESP8266 to control the hardware
- Web server code to handle the WiFi interface
Luckily, we can make use of existing Arduino libraries and examples to simplify development.
For the microcontroller side, we need to:
- Initialize the WiFi module
- Read data from the DHT11 sensor
- Output text and values to the LCD
- Send sensor readings to the web server
And on the web server:
- Display a web page with the current temp/humidity
- Accept requests to change the thermostat temperature setpoint
By piecing together some existing Arduino example sketches, we can get the key functionality working without too much code.
The sketch will be written in the Arduino IDE then uploaded to the Wemos D1 Mini board.
Assembling the Circuit
Here are the steps I followed to assemble this on a breadboard:
- Insert the Wemos D1 Mini board
- Connect the DHT11 sensor to 3.3V power and a data pin like D1
- Connect the 16x2 LCD module to 5V and the following control pins:
- D2 for Register Select (RS)
- D3 for Enable (EN)
- D4 for Data (D4)
- D5 for backlight power
- Connect buttons to pins D6 and D7 for adjusting setpoint up/down
- Power the Wemos by USB or 7-12V input
Once wired up on the breadboard, the circuit can be tested and debugged as needed.
Creating the Enclosure
For the enclosure, I opted for a compact 3D printed case. This holds the Wemos board, breadboard, LCD display, and DHT11 sensor together in a tidy package.
I designed it in Tinkercad using precise measurements of the components. The case design includes:
- Cutouts for the LCD and buttons
- A rear compartment to house the Wemos and breadboard
- Ventilation holes for airflow around the DHT11 sensor
- Side clips to hold the case together
Printed in PLA plastic, the case measures 4" x 3" x 1.5" and can be placed anywhere just like a traditional thermostat.
For a sleek look, I chose a black semi-gloss PLA filament and went with a 20% infill setting for durability.
Total Cost Breakdown
Here is the final cost breakdown for the main components used in this project:
- Wemos D1 Mini - $4
- DHT11 sensor - $2
- 16x2 LCD display - $5
- Case - $2 in filament
- Miscellaneous (wires, resistors, etc) - $5
Grand Total: $18
Coming in under the $20 budget, this proves you can create an impressive IoT device very affordably.
Having the ability to view and control the temperature of your home from anywhere provides real value. And given the low component cost, this DIY WiFi thermostat can pay for itself in energy savings over time.
Conclusion
In closing, with some basic electronics components costing less than $20 total, I was able to construct a fully functional web-connected thermostat with temperature and humidity display.
Following the steps outlined here, you can create your own low-cost WiFi thermostat that gives you smart heating control using the existing Arduino environment.
The same approach could also be adapted to control other devices like lights, motors, or appliances based on sensor input. The possibilities are endless when it comes to inexpensive home automation with ESP8266 boards and a bit of coding. Let me know if you end up building your own thermostat after reading this!