How to Make Your Own Smart Thermostat
Hardware Components:
- Microcontroller: Arduino MKR WiFi 1010 (Microcontroller to process sensor data and control the heating system. It has WiFi and Bluetooth capabilities).
- Sensors: Humidity and temperature sensor: BME280 Humidity Pressure Temperature Sensors
- OLED Display: 0.96 inch OLED SSD1306 Display I2C 128 x 64 pixels
- Relay Module: 5V/12V Relay Module, used as a switch to control the heating system.
- Real Time Clock: Real Time Clock RTC DS3231 I2C real time clock (for tracking accurate time)
- power supply: 5V/2A power adapter
- housing: 3D printed (see draft in this note) or retrofit box to accommodate components
- circuit board
- breadboard and jumpers (if you want to run it as a prototype and possibly expand it)
- custom printed circuit board (design it using KiCad EDA and print it using Eurocircuits)
Software Requirements:
-
IDE: Arduino IDE (you can use any IDE you like as long as you are able to upload code to Arduino)
-
Programming: You only need a basic knowledge of assembly and configuration tuning. If you want to expand the project, some experience with the above technologies may be helpful.
-
Arduino: C++
-
Database: SQL (MariaDB)
-
Front-end: TypeScript (Angular17 front-end)
-
Backend: TypeScript (Node.js, Express)
Step 1: 3D Printed Housing
Step 2: Print the PCB
Step 3: Assemble Hardware and Microcontroller Setup
Microcontroller Setup
Start the assembly process by setting up the microcontroller. Mount it on a breadboard so that it can be prototyped and connected more easily. Connect the microcontroller to a power source, making sure it receives a stable 5V/2A supply. This initial setup forms the basis of the thermostat, providing the necessary control and processing power for the remaining components.
Sensor Integration
Next, integrate the temperature and humidity sensors with the microcontroller. Depending on the type of sensor you choose, follow the specific wiring diagram to connect them properly. For the Adafruit sensor listed above, you can find it on their website. The sensor will provide real-time data about the ambient temperature and humidity, which the microcontroller will use to adjust the heating system. Secure the sensor in a position where it can accurately measure the room temperature.
OLED Display Connection
Connect the OLED display to the microcontroller, ensuring that the pins are configured correctly. The display will be used as a user interface to show the current temperature, set temperature and other relevant information. Proper connection of the display is critical for clear and accurate display output.
Relay Module Setup
Set up the relay module that will control the heating system based on temperature readings and user inputs. Connect the relay to the microcontroller to ensure it can handle the load of the heating system. The relay acts as a switch and the microcontroller can turn it on or off to regulate the temperature. Test the relay operation to ensure that it responds correctly to control signals from the microcontroller.
Step 4: Programming the Thermostat
-
periodically sends a heartbeat to the server.
-
if the heartbeat is successful, queues the sensor data request.
-
processes all pending requests in the queue.
-
attempts to reconnect if in fallback mode and sufficient time has elapsed.
-
controls the heating relay based on temperature while in fallback mode.
-
update the display periodically.
-
Connect the board: Plug the Arduino MKR 1010 WiFi into your computer using the USB cable.
-
Select Motherboard: Go to Tools->Motherboard and select Arduino MKR WiFi 1010.
-
Select Port: Go to Tools->Ports and select the port that corresponds to the board you are connecting to (e.g., COM3, /dev/ttyUSB0).
-
Open Sketch: Open the Arduino sketch file (.ino) in the Arduino IDE.
-
Configure Sketch: Modify the sketch to match your server IP, WiFi credentials, and other settings.
-
Verify the Sketch: Click the check mark icon in the upper left corner of the Arduino IDE to compile and verify the code. This ensures that there are no syntax errors.
-
Upload Sketch: Click the right arrow icon next to the check mark to upload the code to the Arduino MKR 1010 WiFi. the IDE will compile the code again and then upload it to the motherboard.
-
Turn on Serial Monitor: Go to Tools->Serial Monitor to turn on the serial monitor.
-
Set Baud Rate: Make sure the baud rate at the bottom of the serial monitor is set to 9600 to match the Serial.begin(9600); setting in the code.
-
View Output: You should see output from the Arduino, which includes debug messages and sensor readings.
Step 5: Setting up the Database, Server and Front-end
Step 6: Testing and Calibration