View Single Post
Old 01-02-15, 07:58 AM   #66
nkuck
Lurking Renovator
 
Join Date: Dec 2014
Location: USA
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Here is my current sketch and most everything is working fine, except:
When I activate the external relay (a Reeed Relay Shield) both the Ssensor and the Tsensor temps rise 10-20 degrees and stay high until the relay disengages. Could there be some internal heat being generated by the load? Doesn't seem like it would be high enough to make a difference. Thanks for all of your support and patience.

// Pins
int SsensorPin = 4; // the pin to read solar panel temperature
int TsensorPin = 5; // the pin to read water tank temperature
int RelayPin = 7; // the pin to control the pump relay
int ledPin = 13; // led pin to verify relay on condition
int vref;

// Variables
int Ssensor = 0; // holds the value from SsensorPin
int SensorOnDiff = 0; // holds the Ssensor value plus on differential (OnDiff)
int SensorOffDiff = 0; // holds the Ssensor value plus off differential (OffDiff)
int Tsensor = 0; // holds the value from TsensorPin
int SensorReadings = 5; // number of sensor readings to take
int Counter = 0; // sensor readings loop counter
int OnDiff = 4; // temp diff that must exist to turn pump on (dec F)
int OffDiff = 2; // temp diff that must exist to turn pump off (deg F)

// initialize the library with the numbers of the interface pins

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
pinMode(SsensorPin, INPUT);
pinMode(TsensorPin, INPUT);
pinMode(RelayPin, OUTPUT);
pinMode(ledPin, OUTPUT);

Serial.begin(9600);

digitalWrite(RelayPin, LOW); // turn pump off

// set up the LCD's number of columns and rows:
lcd.begin(16,2);
}
void loop()
{

// read sensor inputs, convert to degrees, and assign to variables
Counter = 0;
while(Counter < SensorReadings)
{
Ssensor += analogRead(SsensorPin) / 2;
delay(50);
Tsensor += analogRead(TsensorPin) / 2;
delay(50);
Counter++;
digitalWrite(ledPin, LOW);
delay(250);
}
// calculate average temp from sensor inputs
//Ssensor = (500.0 * Ssensor / SensorReadings) / 1024;
// Tsensor = (500.0 * Tsensor / SensorReadings) / 1024;

Ssensor = Ssensor / SensorReadings;
Tsensor = Tsensor / SensorReadings;

// calibrate sensors
Ssensor = Ssensor - 15;
Tsensor = Tsensor - 16;

// add temperature difference to Ssensor value
SensorOnDiff = Ssensor - OnDiff;
SensorOffDiff = Ssensor - OffDiff;

// Print temps to the Computer
Serial.print("Solar temp= ");
Serial.println(Ssensor);
Serial.print("Tank temp= ");
Serial.println(Tsensor);

// Print temps to the LCD
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 0);
lcd.print("Solar=");
lcd.print(Ssensor);
delay(50);
lcd.print((char) 223);
lcd.print("F");
lcd.setCursor(12, 0);
lcd.print("Pump");

lcd.setCursor(0, 1);
lcd.print("Tank =");
lcd.print(Tsensor);
delay(50);
lcd.print((char) 223);
lcd.print("F");

// if heat source is warmer than heat sink sensor, enable relay
if (SensorOnDiff > Tsensor)
{
digitalWrite(RelayPin, HIGH);
digitalWrite(ledPin, HIGH);
lcd.setCursor(13, 1);
lcd.print("ON ");
delay(500);
}
// if heat source sensor is cooler than heat sink sensor, disable relay
if (SensorOffDiff < Tsensor) {
digitalWrite(RelayPin, LOW);
digitalWrite(ledPin, LOW);
lcd.setCursor(13, 1);
lcd.print("OFF");
delay(500);
}
}
nkuck is offline   Reply With Quote