Go Down

Topic: HVAC controller log / Introduction (Read 5 times) previous topic - next topic

LVLAaron

Jun 04, 2014, 02:42 am Last Edit: Jun 23, 2014, 01:38 am by LVLAaron Reason: 1
Hello everyone! Today I purchased my first Arduino components. I haven't really dabbled with DIY electronics for 20 years; when I was a kid I had one of those 200-in-1 radio shack kits and managed to do pretty well with it.

Arduino is something that has always had my attention and I have wanted to play with but never found a reason to use. I'm the kind of person that needs to solve a problem. Last week my fairly new, expensive, programmable HVAC thermostat died. It was hot out so I quickly looked up the wiring diagram, jumped some of the wires and enjoyed cold air.  XD - Enter the Arduino!

My HVAC unit is easily by 4 contact points.
* Common +24 volt feed
* Fan/Blower
* Heat
* AC

I dug around amazon and came up with a quick list of stuff available on Prime (Inventory at the bottom)

I know nothing about Arduino, but chose the Uno because it seems to be the most used in projects of this size. Would a nano work for something small like this?

I'm very excited about all of this and look forwarding to keeping this log updated. That's all  the data I have for now, I have a ton of research to do. If anyone has comments, thoughts, ideas, or links to existing projects that would be beneficial to me please post them up.

Arduino Arduino Uno Ultimate Starter Kit + LCD Module
http://www.amazon.com/gp/product/B00HI0RYJK/ref=oh_details_o00_s00_i01?ie=UTF8&psc=1


Arduino compatible DHT11 Analog Temperature & Humidity Sensor
http://www.amazon.com/gp/product/B00AF22GDC/ref=oh_details_o00_s00_i00?ie=UTF8&psc=1


Arduino compatible Light Sensor
http://www.amazon.com/gp/product/B00AF278A8/ref=oh_details_o00_s00_i02?ie=UTF8&psc=1


Channel DC 5V Relay Module
http://www.amazon.com/gp/product/B00C8O9KHA/ref=oh_details_o00_s00_i03?ie=UTF8&psc=1



Progress update #1
http://forum.arduino.cc/index.php?topic=244679.msg1759280#msg1759280

Progress update #2
http://forum.arduino.cc/index.php?topic=244679.msg1767138#msg1767138

Progress update #3
http://forum.arduino.cc/index.php?topic=244679.msg1776507#msg1776507

draythomp

I started my adventure with thermostats in much the same way.  Things to consider:

You only need three relays and the current that they need to control is pretty low ... think small.
You need to power the device, where you gonna put the wall wart?
Controlling it locally is nice and traditional, do you want to control it remotely?
Suppose you put the electronics with the air handler where the transformer is and only the sensor at the old thermostat location (this probably requires remote control)
Once you cobble it together, what are you going to put it in to make it look good?  You're going to want to show it off ... aren't you?
Light sensor ??  Need to turn it down at night or something?
Humidity sensor ??  It would be nice to know, but what do you need it for?
How many wires do you  have at the control point?  Would it be possible to pump power for the board that way?
How big a piece of the wall do you want to take up?
Remember, you need to be able to read the display at night; LED displays are nice for that.  But some of them are really irritating at night (note, red sucks)
For a first project, graphic displays take a lot of work.  Think letters and numbers. (if you remote it, you can use a web page)
Programmable is nice, but remember you have to create the user interface.  How are you going to ask for input from the thermostat.  Setting temperature can be a real pain if you have to push a button 25 times to do something.

This is just the stuff I came up with on the spur of the moment, the real list is much, much, longer.  Shoot, what are you going to do in the case of a power failure?  What defaults are you going to have.  How do you get the time into the thermostat and how are you going to keep it correct?

I'll stop now.  I've been through this and just want to ease the field for you.
Trying to keep my house under control http://www.desert-home.com/

LVLAaron

Hey! I was partly inspired to do this project after seeing your site earlier this week. It's great to have your feedback.

Nothing super surprising to me in your list but let me go over it for the viewers at home;

* I got the big relay board because it was cheap and I know I'll use it for other projects in the future. For this small project I plan on moving to solid state relays once I've got it stabilized a bit.
* Power: My thermostat is directly above a 110 outlet so I can easily power it from that, or run some low voltage wire through the wall to the existing hole where the HVAC cables run. (I'm not sure how the power source from the HVAC works, if it's always on, etc. It's probably enough to run the bits I'm adding. Investigation needed)
* It will look good. Don't worry.  :D I take a lot of pride in making these sorts of things look like artwork.
* Light and Humidity; Probably not in use for this project. They were a few dollars and I knew I'd have fun with them. There are many days in the spring/fall where the temperature in the house is fine, but it's just a bit muggy and I want to run the AC for 5 minutes to dry it out a little bit. (Thought; maybe I just add a button that runs the AC for 10 minutes... something like that)

* Display. I want to show what modes are in use; AC, HEAT, FAN. I want to show actual temp, and the set/target temp. As far as user input, I'll default to 70f and just have buttons for up/down. I usually never go outside of 68-72 unless I'm gone for long periods of time.
* I'm thinking some small toggle switches to select modes.


I would really like to make it controlled by a simple web interface. Not sure what kind of effort that will be.

draythomp

I don't want to monopolize the thread, so I'll keep it short.  Build something pretty simple at first, then use it a couple of weeks.  When you get some experience, then go completely nuts and make it really cool.  A really neat way to show what mode it's in is with a colored led display: red letters for heat, green for only the fans, blue for A/C, and of course, white for idle.  If I hadn't taken mine to the web for control, that's exactly what I'd do.  Adafruit has that kind of display and remember, serial displays are really easy, parallel ones will drive you nuts with connections.  Graphic displays can wait until you understand web controls, do graphics on something you can see like a tablet or phone.

Have fun.
Trying to keep my house under control http://www.desert-home.com/

flyboy

@LVLAaron
Disclaimer:
Be sure you have a very good understanding of your HVAC system sequence of operation before using this as a controller.  There are some very important safeties that must be used.  If this is a gas furnace, there are rollout switches and induced draft fan safeties that are in place to keep you from dying in a fire or from CO poisoning.  If it's all electric, you need limit switches so your heaters turn off in the event of a blower failure.

Project/fun
It sounds like a very interesting project.  Draw up a clear objective for your project.  What are the features you want?  Start small, and work your way up.  Once you're confident that the basics are working properly and safely, start adding some bells and whistles.  Have fun, be careful.

wildbill


@LVLAaron
Disclaimer:
Be sure you have a very good understanding of your HVAC system sequence of operation before using this as a controller.  There are some very important safeties that must be used.  If this is a gas furnace, there are rollout switches and induced draft fan safeties that are in place to keep you from dying in a fire or from CO poisoning.  If it's all electric, you need limit switches so your heaters turn off in the event of a blower failure.

Safety is important, but are these things relevant to a thermostat replacement? On my HVAC at least, such things are encapsulated in its own control boards: the thermostat asks the HVAC to provide heat or cooling - it's up to the HVAC to 'decide' whether it's safe to comply.

LVLAaron

I'm just replacing the thermostat on the wall, not getting into the HVAC unit itself.

For example, the only leads for heat are "HEAT" and "+24v"  - Whatever is inside the HVAC unit does the rest of the exhaust fan spinup/cooldown, etc.

draythomp

If you have a heat pump, you'll have a wire for heat/cool, a wire for fan, a wire for compressor, 24vac, and common.  Sometimes they don't carry the 24vac to the thermostat, you'll have to check that.  Just prowl around the web, find a thermostat schematic, and you're ready to go.

It's a little different if you have a furnace/AC, but the same idea.  Find a schematic for the thermostat and steal the ideas.

There's tons and tons of information out there.
Trying to keep my house under control http://www.desert-home.com/

LVLAaron

I am already familiar with the wiring for my unit. When my original thermostat gave out on me I just used some jumper wires to get the AC going.  8)

LVLAaron

First real update! Some action shots and some code.

Action shot #1 - Successfully reading sensor data and displaying it on the LCD.


Action shot #2 - Added code to determine if ambient temperature is above or below a static "target" temp. The LED's have been added to indicate which side of the target the air is at. Also wired in the relay board. Relay 1 and 2 act in concert with the red and yellow leds.


Here's my sketch;
Code: [Select]
// include the libraries for gizmos
#include <LiquidCrystal.h>
#include <dht11.h>

dht11 DHT11; // Figure out what this line does
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins

// These constants won't change:
const int ACledPin = 8;      // Air Conditioner LED (RED)
const int HTledPin = 9;      // Heat LED (YELLOW)
const int threshold = 90;    // an arbitrary threshold level that's in the range of the analog input

const int RELAY_01 = 6;    // RELAY 1 PIN 9
const int RELAY_02 = 10;   // RELAY 2 PIN 10

void setup() {
  DHT11.attach(7);       // Attach DHT11 sensor to pin 7
  lcd.begin(16, 2);      // set up the LCD's number of columns and rows:
  Serial.begin(9600);    // Serial setup

  pinMode(ACledPin, OUTPUT);  // initialize pin 8 as output
  pinMode(HTledPin, OUTPUT);  // initialize pin 9 as output
  pinMode(RELAY_01, OUTPUT);  // initialize pin 6 as output
  pinMode(RELAY_02, OUTPUT);  // initialize pin 10 as output

  // Leaves the relays in default "off" (no noise/click)
  digitalWrite(RELAY_01, HIGH);
  digitalWrite(RELAY_02, HIGH);

}

void loop() {
  int chk = DHT11.read();   // Check status of the sensor
  lcd.setCursor(0, 0);      // Set cursor to top left


////////////// if then ////////////////
  float analogValue = (DHT11.fahrenheit()); // trying to set up the temp reading as an int variable

  // if the analog value is high enough, turn on the LED:
  if (analogValue > threshold) {
    digitalWrite(ACledPin, HIGH);
    digitalWrite(HTledPin, LOW);
    digitalWrite(RELAY_01, HIGH);
    digitalWrite(RELAY_02, LOW);
  }
  else {
    digitalWrite(ACledPin, LOW);
    digitalWrite(HTledPin, HIGH);
    digitalWrite(RELAY_01, LOW);
    digitalWrite(RELAY_02, HIGH);
  }

  // print the analog value:
  Serial.println(analogValue);
  delay(1);        // delay in between reads for stability
  ////////////// if then ////////////////

  lcd.setCursor(0, 1);
  lcd.print("Temp(F): ");
  lcd.print(DHT11.fahrenheit(), 2);

  delay(2000);

}


As always I am open to all constructive criticisms.

Next steps for me;
* User input for target temperature instead of being hard coded. Display this on the LCD.
* Work on temperature "swings". In HVAC speak, if you are in AC mode and have your temp set at 72, the swing is usually 1 to 3 degrees. Let's assume our swing is 1 in this case. This means that when the ambient room temp reaches 73 the AC turns on, and runs until it cools the air to 71 degrees. 1 degree of "swing" in either direction of the target temp.

* Further down the road, overrun protection. It's not good to have the compressor turn off and then turn it back on in quick succession. Need something in the code  that says if the unit has been running in the last 10 minutes, to not run until 10 minutes has passed.

That's it for today. More parts coming tomorrow.

wildbill

Some clearer names might be nice. ACledPin is ok, in context, so is HTledPin but you wouldn't have to think about it if it were HeatLedPin. As for Relay_01 and Relay_02 - really! Shouldn't analogValue be Termperature or TemperatureF?

These things don't really matter, especially in such a small sketch but they make it slightly harder to work with and spot bugs. As the sketch gets bigger, that will become more important.

delay(1) doesn't serve any useful purpose now - that delay(2000) is doing its job.

Finally, why do you use DHT11.fahrenheit() to get the temperature for printing to the LCD when you already have it in analogValue?

LVLAaron

Quote
Some clearer names might be nice

Absolutely. It's on my list of to-do's. I'll do a replace-all a little later on.

Quote
delay(1) doesn't serve any useful purpose now - that delay(2000) is doing its job.

I was hoping that I could have two different things going on; a 1 second delay for the serial output and a 2 second delay for the screen refresh. Not possible?

Quote
Finally, why do you use DHT11.fahrenheit() to get the temperature for printing to the LCD when you already have it in analogValue?

Good catch. I can tidy that up.

wildbill

Quote
was hoping that I could have two different things going on; a 1 second delay for the serial output and a 2 second delay for the screen refresh. Not possible?


It's possible, but not using delay. You'll need to use millis instead - the blink without delay example in the IDE shows you how to manage it. You'll need to use millis (or a RTC) when you get to the point of ensuring the compressor doesn't cycle too often. Also, use of delay will make your code unresponsive to the user when trying to change the set point.

draythomp

Nobody ever listens to me when I tell them that the way to handle delays and timers is with the Time and TimeAlarm libraries.  You can set a timer to fire every two seconds and update the display.  This will run without any delay() calls and leave the processor free to do something else, like check for user input.  Doing it for a second is a bit iffy since that's its smallest granularity, but most often, we don't need a second, we need a delay of some kind and we just choose a second.  Yes, you can have multiple timers and alarms.

I use this set of libraries extensively to handle changing displays, where I show something for a couple of seconds and something else for a couple of seconds.  I also use it to have things report on a schedule; whether they report hourly, daily, every 10 seconds, etc.  I have it turn things on at 8 and off at 10.  It just works.  If you don't need the actual time, just set it to whatever comes to mind, it will keep time and establish timers and alarms from there.  I sync my stuff up off a GPS chip, but you certainly don't have to be that extreme.

A very tiny bit hard to understand at first, but once you use it, it turns out to be incredibly easy.  You can turn a simple arduino into a multiprocessor pretty easily (albeit, a slow one).  But, like I said, no one listens to me when I talk about it.

For temperature readings, I use a moving average of several readings.  Temperature sensors can react too quickly to breezes and such for use in a home thermostat, so I slow them down a bunch by sampling a lot and averaging.  I don't usually put delays in the read because I want the processor available for other things delay() locks everything out except interrupts.

Here in the desert I use a hysteresis of -2,+1 in the summer and -1,+2 in the winter.  That was after trying about a jillion different things that kept the compressor on too long or cycled it too rapidly.  This is something you'll have to experiment with, so make it a value you can change on the fly.  Of all the weird things I ran into, the proper hysteresis curve was the most annoying.
Trying to keep my house under control http://www.desert-home.com/

LVLAaron

Well I'm certainly listening! I am impressed with your setup. I will look at those libraries, and if memory serves, you have all of your code posted somewhere?

Go Up