View Single Post
Old 04-17-11, 12:19 PM   #14
Daox
Administrator
 
Daox's Avatar
 
Join Date: Aug 2008
Location: Germantown, WI
Posts: 5,525
Thanks: 1,162
Thanked 374 Times in 305 Posts
Default

So, I think its finally ready to go. I made some final tweaks and everything appears to be working perfectly. I had to add a capacitor to the signal line on the kitchen sensor because I was getting noise on the line. I pulled a 10uF capacitor off some circuit board I had laying around and it seems to work great. It wouldn't hurt to put one on the attic temp sensor too, but it didn't jump around much at all, so I just left it. Also, I've removed the 10K pull down resistor on my setup. It seems to be working fine without it.

Anyway, here is the new schematic.




Here is the code. I added another check in the program. If the kitchen temperature gets up to 80F/27C, the relay will turn off and stay off. Also, if you uncomment the serial parts of the code, you can very easily log the temperatures.

Code:
/* Thermal Differential Controller

  The program monitors two temperature sensors and
  activates a relay when one sensor is warmer than
  the other.
*/

int SsensorPin = 4;  // the pin to input attic temperature
int TsensorPin = 5;  // the pin to input kitchen temperature
int RelayPin = 2;  // the pin to operate the relay
int ledPin = 13;  // led pin (verify fan on condition)

int Ssensor = 0;  // variable to store the value of the attic temperature
int SensorDiff = 0;  // variable to store the Ssensor value plus differential (Diff)
int Tsensor = 0;  // variable to store the value of the kitchen temperature
int Diff = 3.0;  // temperature difference that must exist between attic and kitchen before relay enables (degrees C)


void setup() {
  pinMode(SsensorPin, INPUT);
  pinMode(TsensorPin, INPUT);
  pinMode(RelayPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  
  // Serial.begin(9600);
  
  digitalWrite(RelayPin, LOW);
  
}

void loop() {
  
  // read sensor inputs and assign to variables
  Ssensor = analogRead(SsensorPin) / 2;
  Tsensor = analogRead(TsensorPin) / 2;
  
  // add temperature difference to Ssensor value
  SensorDiff = Ssensor - Diff;

  // send temperature signals back to computer
  /*
  Serial.print(Ssensor);
  Serial.print(", ");
  Serial.print(Tsensor);
  Serial.print(", ");
  Serial.println(SensorDiff);
  delay(1000);
  */

  // if attic is warmer than kitchen sensor, enable relay
  if (SensorDiff > Tsensor  && Tsensor < 27) {
      digitalWrite(RelayPin, HIGH);
      digitalWrite(ledPin, HIGH);
      delay(1000);
    }
  
  // if attic sensor is cooler than kitchen sensor, disable relay
  if (Ssensor < Tsensor || Tsensor > 27 ) {
    digitalWrite(RelayPin, LOW);
    digitalWrite(ledPin, LOW);
    delay(1000);
  }
}
Attached Images
 
__________________
Current project -
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.



To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
&
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

Last edited by Daox; 04-17-11 at 12:21 PM..
Daox is offline   Reply With Quote
The Following User Says Thank You to Daox For This Useful Post:
AC_Hacker (04-17-11)