My custom Thermostat

After being frustrated by the varying temperatures throughout the house (mainly my sons room) I decided to build my own thermostat to help monitor and better control the house temps.

Initially I started with 2 DS18b20 temp sensors, one for the thermostat, and one for the sensor in my sons room. To make the sensor wireless, i tried a few options to get what I wanted. Out of the parts I already had lying around, I didn’t want to use bluetooth, rfm12b was a pain, and the cheap “wire transmitter/receiver” just didn’t work past like 10 feet. I finally found some simple, Serial RF transceivers from seeed studio, HC12s, that had great range, and all I had to do was connect them to the serial pins.

The wireless sensor ready to go. An ATmega328, DS18b20, the HC12, some sleep code and batteries and it was all good. Transmits once a minute.

#include <LowPower.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(7, 8); // RX, TX
#define ONE_WIRE_BUS 11
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int dsPower = 10;
int dsGround = 9;
int temptx;
int radioPower = 5;
int radioGround = 6;

void setup() {
//  Serial.begin(57600);
  mySerial.begin(9600);
  pinMode(dsPower, OUTPUT);
  pinMode(dsGround, OUTPUT);
  pinMode(radioPower, OUTPUT);
  pinMode(radioGround, OUTPUT);
  digitalWrite(dsGround, LOW); 
  digitalWrite(radioGround, LOW);
  digitalWrite(dsPower, HIGH);
}

void loop(){
  digitalWrite(radioPower, LOW);
  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
  LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF);
  digitalWrite(radioPower, HIGH);
  sensors.begin();
  delay(1000);
  sensors.requestTemperatures(); // Send the command to get temperatures
  float tempF = DallasTemperature::toFahrenheit(sensors.getTempCByIndex(0));
  delay(100);
  temptx = tempF+0.5;
  //  Serial.println(tempF);
  //  Serial.println(temptx);
  if (mySerial.available());
  {
    mySerial.write(temptx);
  }
  delay(50);

}

The actual thermostat was a bit harder. After a couple attempts at writing some code, I quickly realized I was in over my head as far as the actual temp controls went. I did some searching and finally found an arduino thermostat project that matched both parts that I had available and was, well, kinda what I was looking for.

http://www.avbrand.com/projects/thermostat/

This had exactly what I wanted. I found some of code a little confusing, but thankfully I didn't have to edit the main temp controls much so it wasn't a big deal. In his pictures he shows the fan on/auto switch to be and acutal switch, but in the code it acted more like a button. It took a bit to figure that one out. So, now it's a button rather than a switch. no big deal.

Starting out, I got a SainSmart Mega (budget!) and a 4-Relay board to control the Heating unit.

I added in a second LCD to display the temp in my sons room (along with the rf transceiver). My current thermostat had a very basic filter reminder, so I decided that not only did I want that, but I wanted a little bit more advanced one. I added in a Real Time Clock module, and set it to 90 days. Along with that, I added in the Filter reset button, with a blinking LED that let me know when it was time. The countdown is also displayed on the 2nd LCD.

After several trips to my local (and awesome) parts store, Surplus Gizmos, I finally started putting it together in the project box. I had to find a small one with a decent color (my wife did not want a normal project box, it had to be small, slim, and white), I magically found this one that was originally meant to be some sort of network POE junction box. Some of the other trips were due to my own ignorance. In trying to keep the buttons in place, I initially tried super glue. That was dumb. The glue seeped into the buttons and made them unusable. I settled on Hot Glue. That worked great. Next came the task of fitting all the components into the box, and then getting everything wired up. I’d like to think it would look a whole lot neater if I had used a larger box, but whatever. it works and looks good on the outside.

Around the same time that I started building this, I had also come across the esp8266. After playing around with it and trying to find a use for it, I decided to integrate it and have it upload the 2 temps to thingspeak. Now, as everyone knows, you cant (or at least shouldn’t) power the esp from the arduino. I tried for awhile. it would work for about 30 minutes and then stop. Eventually I built a 3.3v regulator with a LD1117 and a couple 22uF caps (and a clip on heatsink) and fitted it down in the bottom of the box.

My ThingSpeak Page

Then I realized I had made something that would be incredibly annoying. The LCD’s had a nice bright blue LED backlight. And where the thermostat will be hung on the wall, I can see from my couch. I do not want that god awful bright lite staring at me while I’m up late watching tv. So, I installed an IR proximity sensor. It now only lights up when you’re about 8 inches or closer.

Finally, once I was mostly done putting it together, I noticed that the temperature on the thermostat was substantially higher than the current thermostat (about 6 degrees F). This made no sense. Eventually I swapped it out with a DHT11, and that read much better (after cutting a hole in the top of the box).

So now, here is a bacis rundown:
The Set Temperature is stored in memory, so even if you unplug the unit, it remembers.
The Secondary wireless sensor in my sons room has threshold limits set, so if the temp in his room goes too high (the sun just cooks his room), the fan will kick on (probably set to turn AC on in the summer) until the temp comes down, and will then auto shut off.ro
The RTC provides a good filter life timer.
The ESP8266 uploads data to thingspeak, hopefully oneday will be a webserver offering wireless control via web.

attached is the final (well, current) code. a crappy fritzing pic, and a video!

_2_thermostat_DHT_ESP_IRdemo.ino (16.6 KB)

Nice job. I like it.

Super project and description...tnx

(One small suggestion. If the relays are switching mains, which they may not be, then place some isolation between the front panel buttons and the relay board)

Thanks Guys!

(One small suggestion. If the relays are switching mains, which they may not be, then place some isolation between the front panel buttons and the relay board)

Yeah, I thought about that. While I dont have any room to put anything thicker than paper (its a tight fit and barely closes now), i will be putting electrical tape over top of the relay connection points.

Hopefully someday in the future (in a new house) I will be able to seperate panel from the controllers (or put everything in a larger project box and mount it in the wall).

Next on the docket is to setup the esp8266 with a raspberry pi easyIOT server for wireless control.

So I installed it today. After a small fight with the wiring (the hvac wires were very short with no slack), I finally got it going.

I discovered one flaw in going with the IR proximity sensor. Remember when I said this:

Then I realized I had made something that would be incredibly annoying. The LCD's had a nice bright blue LED backlight. And where the thermostat will be hung on the wall, I can see from my couch. I do not want that god awful bright lite staring at me while I'm up late watching tv. So, I installed an IR proximity sensor. It now only lights up when you're about 8 inches or closer.

?

Yeah, well...that whole "I can see it from my couch" part? Yeah, the thing lights up every single freaking time I use the f#@king TV remote.

Will a ToF sensor have this same issue? I have an HC04 ultrasonic lying around, but I'm just not sure I want to use it.

Classic....

You could try to treat this as a 'de-bounce' issue. That is, you treat the signal as valid only if you get a constant activation for at least 250 or 500ms or longer.

The IR from the remote control will have a modulated carrier signal which should produce lots of on/off tranistions at much shorter intervals. (20uSecs to circa 10mSecs)

However, that would depend on proximity sensor specs, which are unknown?? (Datasheet link?)

Another approach would be to point the sensor facing down towards the floor and if neccessary add in some physical barrier to block the signal from the remote - even recess it into the enclosure a bit.

One other issue I just found: For some reason, if the fan is set to "ON" (as opposed to Auto), and the AC comes on, once the AC turns off, the fan will not turn off. ever. Even switching the fan from ON to Auto to ON to Auto, it stays on. Switching from Cool to Heat also did not help. It wasn't until I raised the set temp to turn on the Heat that the fan finally switched off. Hmm...

Should be easy enough to find out with some serial prints which of these variables is causing it:

  digitalWrite(RLY_FAN, fan_mode == 1 || is_cooling == 1 || jx_Fan == 1 ? LOW : HIGH);

Nice project.

Well, after a couple of weeks, I had to take it down and go back to the drawing board. I found a couple bugs, and my wife wasn't a big fan of the fact that wasn't an "Off" switch (never thought about that). Also, now that I have a reprap, I hope to be making my own housing for it, so hopefully get a little more room to work with.

For a related project where I built my own wireless thermostats, see https://github.com/LenShustek/tempsensor