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. 

 

Materials

Arduino Microcontroller
Arduino Connector Cables
Servo Motor
2 x Momentary Switches
2 x 100 kohm Resistors
Large Paperclip (or other steel wire) 
Jumper Wires

 

The Code

Attached 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 [7][24].” 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.

 

  Download Code  


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 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.  

 

  Download Code  


Give this project a try for yourself! Get the BOM.

 

Comments

2 Comments


  • Jake Blanton 2018-01-17

    Those types of thermostats are notoriously difficult to set for an exact / repeatable setting and the temperature setting is more of a ballpark estimate than anything else.  If you are going to go to the trouble of adding an Arduino controller to make a programmable thermostat (vs just buying a programmable thermostat), you probably should consider adding a temperature sensor to the Arduino and then to either directly control the contacts inside the thermostat or if you want to use the servo like in this article, just have it move the temperature setting slider all the way from one side to the other so that it basically operates as an ON-OFF switch.  Of course, you don’t want to be cycling your air-conditioner / heater on and off rapidly since that uses more energy and wears things out faster, so you should include code for a minimum ON time and a minimum OFF time.  Another thing to consider is that even after you turn off the air-conditioner / heater, there still exists some cool/heat in the unit and that can be utilized instead of being wasted by letting the fan run for a certain period of time after the compressor has been shut off.

  • Georgielaa 2018-02-05

    Great article. I’m thinking of doing something similar in my house. It’s a rented house so installing a new smart thermostat is not an option.