Monday, February 11, 2013

WiFi Thermostat Control Part 1

Living in an Apartment can be a challenge when it comes to home automation. Most projects require modifying or tapping into the building in one way or another. Our Apartment was remodeled before we moved in but they didn't replace the aging thermostat. It is the old style with the lever on top that controls a glass tube of mercury. I knew I could replace the thermostat with some relays and a microcontroller or get a retail WiFi thermostat but I needed something that didn't modify it in any away.







Looking through my inventory of parts I remembered I had a micro servo from the Adafruit Motor Shield kit. This servo with a microcontroller and a Wifly radio would be perfect. The idea is that the servo can set the temperature on the thermostat to give you remote control. The servo is connected to the lever on the thermostat with a paperclip. There was a few ways I could go about this. Either sync the microcontroller with the marked temp on the thermostat or use the lever as a switch. All the way to the right is "ON" and all the way to left will be "OFF". My initial test was just moving the servo by 10 degress in either direction depending on which button or a command over WiFi.

My microcontroller of choice was the Romeo from DFRobot. I was given one after helping at the Maker Faire last year. It has everything I need for any project. Its really a great prototyping platform since it has a motor controller, breakouts for I2C, 5 buttons tied to a single ADC pin, and headers that have power, signal, and ground for servo and senors. You can check it out here: www.dfrobot.com (v1 with Atmega328p), they also have a newer one with the Atmega32u4 like the Leonardo here: www.dfrobot.com.

Parts:

Added later
  • SHT1x Temp and Humidity Sensor (You could use any temp sensor)

This can be done with any microcontroller like a regular Arduino, you will just have to use a breadboard or a protoshield with some buttons. The Xbee shield does have prototyping space you could use. Later on, I do plan to make this more permanent with either a JeeNode or my own microcontroller design for home automation nodes and support for Lithium Ion batteries.

Assembly is pretty easy, the hardest part is probably the paperclip. As seen below you want to cut the paperclip just long enough to loop through the servo and wrap around the thermostat level. (This all depends on how yours is setup.) Cut a small piece of the 3M double sided tape and affix it to the bottom of the servo. Once you figure out your placement you can remove the adhesive cover and stick it. Give it a good squeeze so you get a good bond.




I connected the servo to the sensor header for pin 9 which has PWM. Add the Xbee shield and your choice of Xbee socket compatible radio. The original code I had used the buttons to move the servo 10 degrees and used the thermostat temp control. Once that was working reliable I added the SHT1x sensor. I had already used it on Sbot2 so it was a matter of swapping the sensor wire pin order and plugging it into the i2c header on the Romeo.

You can find the lastest version of the code on GitHub.
https://github.com/FriedCircuits/ServoThermostatControl

There are two ways to set the temp, either locally with the buttons or over a remote Telnet session which can be used from your mobile phone and a Telnet app. I plan on writing a web based GUI or maybe start building a mobile app for the whole home automation system. I would like to add voice control like I did with the smart outlet and the Raspberry Pi with the TV. http://www.mobilewill.us/2012/07/raspberry-pi-commandir-and-beyond.html

Here are the commands for the Telnet session:

  • t - view set temp, air temp and humidity (Need to add heater status)
  • o - forces off
  • n - forces on
  • u - raise set temp 1 degree
  • d - lower set temp 1 degree

Since I am using single character control there is a problem on start-up since the Wifly sends out its status which triggers the heater to turn on. Once I add an interface then I can add a header to the command like I do for my robots. This way garbage data won't trigger the heater control. 

Button Control:
  • Up - Raise temp 1 degree
  • Down - Lower temp 1 degree
  • Left - Force off
  • Right - Force On
The reason for the force is just in case the heater is on and it thinks its off. This helps for when you first power it up. I plan to improve the code so this isn't needed. 

While adding the set temperature option, I added a check to see if the set temp has changed and if so save it to EEPROM. That way if there is power outage it will resume with the last set temperature. 

Finally, I used the built-in LED to show the heater status. While the heater is on, the LED is on (solid) and it will turn off when the heater is off. 

I am really happy with the way this turned out and plan to add a DS3243 RTC to it in Part 2 for scheduling and logging of the temperature throughout the day and year. I could even take into account temperature senors in other rooms and wither someone is home or not.

I hope this inspires home automation ideas for your home or apartment. If you have a project you would like to share you can email or comment below and I can post it up. Click on MrMobileWill under contributors for my email. 

1 comment:

  1. Good post....thanks for sharing.. very useful for me i will bookmark this for my future needs. Thanks.


    ReplyDelete