I just re-wrote code, using variables. I'm not getting any readings from my sensors. I suspect it's in the area designated "float output". It seems there should be a reference to the 3 sensors there. Not sure. Your thoughts?
#include <SPI.h>
#define sensorPin1 A0
#define sensorPin2 A1
#define sensorPin3 A2
#define fanControl 2 // Arduino pin connected to relay for fan
#define pumpControl 3 // Arduino pin connected to relayfor pump
#define getOutdoorTemp
#define getSupplyTemp
#define getReturnTemp
// resistance at 25 degrees C
#define THERMISTORNOMINAL 10000
// temp. for nominal resistance (almost always 25 C)
#define TEMPERATURENOMINAL 25
// how many samples to take and average, more takes longer
// but is more 'smooth'
#define NUMSAMPLES 5
// The beta coefficient of the thermistor (usually 3000-4000)
#define BCOEFFICIENT 3950
// the value of the 'other' resistor
#define SERIESRESISTOR 10000
int samples[NUMSAMPLES];
const int AIR_TEMP_THRESHOLD_UPPER = 74; // Start fan to circulate warm air around barrels, change to your desire value
const int AIR_TEMP_THRESHOLD_LOWER = 70; // Stop fan to prevent cooling barrels, change to your desire value
const int WATER_TEMP_THRESHOLD_UPPER = 50; // Start pump to heat greenhouse floor, change to your desire value
const int WATER_TEMP_THRESHOLD_LOWER = 40; // Stop pump to prevent cooling greenhouse floor, change to your desire value
void setup(void) {
Serial.begin(9600);
pinMode(sensorPin1, INPUT);
pinMode(sensorPin2, INPUT);
pinMode(sensorPin3, INPUT);
pinMode(fanControl, OUTPUT);
pinMode(pumpControl, OUTPUT);
}
void loop(void) {
uint8_t i,j,k;
float average;
// take N samples in a row, with a slight delay
for (i,j,k=0; i,j,k< NUMSAMPLES; i,j,k++) {
samples[i,j,k] = analogRead(sensorPin1); analogRead(sensorPin2); analogRead(sensorPin3);
delay(100);
}
// average all the samples out
average = 0;
for (i,j,k=0; i,j,k< NUMSAMPLES; i,j,k++) {
average += samples[i,j,k];
}
average /= NUMSAMPLES;
// convert the value to resistance
average = 1023 / average - 1;
average = SERIESRESISTOR / average;
delay(100);
float output;
output = average / THERMISTORNOMINAL; // (R/Ro)
output = log(output); // ln(R/Ro)
output /= BCOEFFICIENT; // 1/B * ln(R/Ro)
output += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
output = 1.0 / output; // Invert
output -= 273.15; // convert absolute temp to C
output = output *1.8+32;
delay(100);
float oATemp = getOutdoorTemp(sensorPin1);
float supplyTemp = getSupplyTemp(sensorPin2);
float returnTemp = getReturnTemp(sensorPin3);
{
if (oATemp > AIR_TEMP_THRESHOLD_UPPER) {
Serial.println("Fan relay is turned on");
digitalWrite(fanControl, HIGH); // turn on
} else if (oATemp < AIR_TEMP_THRESHOLD_LOWER) {
Serial.println("Fan relay is turned off");
digitalWrite(fanControl, LOW); // turn off
}
{
if (returnTemp > WATER_TEMP_THRESHOLD_UPPER) {
Serial.println("Pump relay is turned on");
digitalWrite(pumpControl, HIGH); // turn on
} else if (returnTemp < WATER_TEMP_THRESHOLD_LOWER) {
Serial.println("Pump relay is turned off");
digitalWrite(pumpControl, LOW); // turn off
}
}
}
Serial.print("Outdoor Air Temperature");
Serial.print(oATemp);
Serial.println(" Deg F");
delay(1000);
Serial.print("Supply Water Temperature");
Serial.print(supplyTemp);
Serial.println(" Deg F");
delay(1000);
Serial.print("Return Water Temperature");
Serial.print(returnTemp);
Serial.println(" Deg F");
delay(1000);
}