Interfacing analog thermostat with Arduino

Several people have asked this question, but none have been answered. Here's the project.

I am connecting thermostats from each room in the house to the arduino (disconnecting them from the HVAC). I want to use the thermostats as a trigger. If the thermostat is in 'cool' mode and the thermostat triggers to call for cool air, the arduino will control a servo to open the vent in that room and turn on the A/C compressor and fan if not already on. Don't go too far into trying to figure out the details because the immediate problem is that I can't read the status of the thermostat. The wiring at the thermostat is as such: White = heat, yellow = A/C, Red = 24VAC, Green = fan. When the system is on cool and the thermostat is triggered, yellow is shorted to red, so I'd like to use that as a switch to tell the arduino to turn on the AC compressor and fan, and open the vent for that room. I can get it to work for heat by connecting white to A0 and red to +5v. The value when the circuit is closed (analogRead()) is 1023. When the circuit is open (ie, the room is warm enough) the value jumps randomly from 0 to 9000+ and sometimes randomly hits 1023 triggering the servo. It doesn't work at all on cool. I can't figure out how to solve this problem. :frowning:

I suspect it may be an issue with ground since the analog pin compares it's input to the arduino ground. There are no grounds on thermostats. It's basically an SPST switch. Or at least that's how I understand it.

Anyone with helpful info would be much appreciated!

Servo Room_1; //create servo object for each room

void setup()
{
Room_1.attach(8);
Serial.begin(9600);
lcd.begin(16, 4); // set up the LCD's number of columns and rows:
lcd.print("Servo Control..."); // Print a message to the LCD.
}

void loop()
{

CheckThermostat();
delay(1000);

} //loop()

void CheckThermostat()
{
int x;

int val = analogRead(A0);
lcd.setCursor(0,1);
lcd.print(val);
switch (val)
{
case 1023:
lcd.setCursor(0,2);
lcd.print(Room_1.read());
if (Room_1.read() != 89) {
for (x=0;x<90;x++)
{
Room_1.write(x);
lcd.setCursor(0,2);
lcd.print(Room_1.read());
//delay(20);
}
}
break;
default:
lcd.setCursor(0,2);
//lcd.print(Room_1.read());
if (Room_1.read() > 10) {
for (x=89;x>0;x--)
{
Room_1.write(x);
lcd.setCursor(0,2);
lcd.print(Room_1.read());
//delay(20);
}
}
break;
}

}//CheckThermostat

Figured it out!

I needed a 1k ohm pulldown resistor on the analog pin.

+5v (red wire)--------------Thermostat------(yellow wire for A/C)----------()-------------Pin(A0)
|
|
1K resistor
|


__
_ (ground)

Then set pinMode(A0,INPUT); and use digitalRead(A0); to get a HIGH or LOW state.

Problem solved. Works like a charm.

Also, the new code (still just in proof of concept phase):

void CheckThermostat()
{
int x;
// analogReference(INTERNAL2V56);

int val = digitalRead(A0);
lcd.setCursor(0,1);
lcd.print(val);
switch (val)
{
case HIGH:
lcd.setCursor(0,2);
lcd.print(Room_1.read());
if (Room_1.read() != 89) {
for (x=0;x<90;x++)
{
Room_1.write(x);
lcd.setCursor(0,2);
lcd.print(Room_1.read());
//delay(20);
}
}
break;
case LOW:
lcd.setCursor(0,2);
//lcd.print(Room_1.read());
if (Room_1.read() > 10) {
for (x=89;x>0;x--)
{
Room_1.write(x);
lcd.setCursor(0,2);
lcd.print(Room_1.read());
//delay(20);
}
}
break;
}

}//CheckThermostat