Programmable thermostats are a great way to save both energy and money. But you don’t have to go out and buy one: you can upgrade your old mechanical thermostat! All you need is an Arduino microcontroller and a servo motor.
The servo is positioned next to the thermostat, then the rotor of the servo is connected to the arm of the thermostat that controls the temperature setting. The Arduino can then use the servo to adjust the temperature setting of the thermostat at different time periods of the days.
Arduino Connector Cables
2 x Momentary Switches
2 x 100 kohm Resistors
Large Paperclip (or other steel wire)
Below is a copy of the Arduino code for this project. Download the code and open it up in the Arduino programming editor. The first thing that you need to do is set the default temperature (in degrees Fahrenheit) in the variable “defaultTemperature.” This will be the temperature that your house will be most of the time. Throughout the week, the temperature will be adjusted up or down from this baseline.
Next, you need to set the hourly temperature adjustments. These are stored in a two dimensional array named “dayTimeArray .” The array is divided into days of the week and individual hours in each day. Each hour of the week is initially set to 0. This means that at this time the temperature setting is equal to the default temperature. To adjust this, enter a value for that hour (positive or negative) that represents the number of degrees up or down that you would like to change the temperature setting relative to the default temperature. For example, if the default temperature is 68 degrees and you want the temperature at a certain time to be 66 degrees, then you would enter a value of “-2” for that position in the array. Enter in the temperature adjustments for each hour of the week.
Continuing down the code, you need to enter in the numerical value for the current day of the week (0 through 6), the hour of the day (0 through 23) and minute (0 through 59). Each of these is stored in its own variable.
Below this you will find a variable named “servoTemperatureConversion.” This represents the number of degrees of the servo’s rotation correspond to a degree change on the thermostat. You can adjust this to calibrate the system to your specific servo. But you will want to wait until you can attached the servo rotor to the adjustment arm of the thermostat.
Once you have made all the necessary changes to the code, upload it to your Arduino.
Connect the Switches and the Servo
Two switches are connected to the Arduino to allow you to manually adjust the temperature without having to reprogram the system. For this you need two momentary switches. One side of each switch is connected to 5V. The other side of the switches are connected to digital pins 10 and 11. Then digital pins 10 and 11 are also connected to GND with 100 kohm resistors. These resistors act as pull-down resistors and will keep the digital pins in a LOW state until the buttons are pressed. This prevents false triggering from electrical noise. To avoid switch bouncing (the system interpretting one button press as multiple button presses), the code it set up to only accept one input from the switch per second.
The servo has three wires. One wire (typically red) connects to 5V. Another wire (typically brown or black) connects to GND. The third wire (orange in this case) is the signal wire and connects to digital pin 9. Different manufacturers use different color codes so find the appropriate colors for your servo.
Attach the Servo to the Side of the Thermostat
The next thing that you need to do is stick the servo to the side of the thermostat. The easiest way to do this is with a large drop of hot glue. Make sure that the mounting hole on the rotor is lined up horizontally with the head of the adjustment arm of the thermostat.
Connect the Rotor of the Servo to the Temperature Setting Arm of the Thermostat
The easiest way to connect the rotor of the servo to the arm of the thermostat is with a piece of steel wire. Set the servo to the default position (by turning on the Arduino) and set the thermostat the default temperature. I just used a large paperclip. First I straightened out the wire, then I bent it into a shape that would connect the two pieces. Lastly, I bent the wire into a loop at each end to hold the pieces in place.
Use the Thermostat
Now your DIY programmable thermostat should be working. It will automatically adjust the temperature for you throughout the week. To make manual adjustents to the temperature, you can press the up or down buttons and all the temperature settings will be shifted up or down by one degree.
Keep in mind that if the Arduino ever powers down, it will restart the program, so if the power goes out remember to reset the day and time.