So After trying several sketches for a LM35 and none working I finally found one that was giving me accurate results. The problem is the code is way over my head. I was able to modify it enough to get the serial and temperature to a LCD but I cant figure out why its not tripping the relay after set values. The sketch completely ignores the temperature value therefor will never set the relay HIGH. What am I missing?
/*
LM35 thermometer, no floats, no delays
http://www.ti.com/lit/gpn/lm35
*/
const int relay = 0;
const byte sampleBin = 8, // number of samples for smoothing
aInPin = A5;
const int fudge = 170; // adjust for calibration
const int kAref = 1090, // analog ref voltage * 1000
kSampleBin = sampleBin * 1000,
tEnd = 5000; // update time in mS
int tempC,
tempF;
uint32_t total, // sum of samples
tStart; // timer start
int sensorPin = 5;// The analog pin the LM35's Vout is connected to.
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
/*
Initialize serial connection with the computer*/
void setup()
{
pinMode(relay, OUTPUT);
Serial.begin(9600);
lcd.begin(16,2);
analogReference(INTERNAL); // use 1.1V internal ref
analogRead(aInPin);
for (int i = 0; i < sampleBin; i++) // for smoothing, fill total
total += analogRead(aInPin); // with sampleBin * current
// reading
}
void loop()
{
if (millis() - tStart > tEnd)
{
tStart = millis(); // reset timer
total -= (total / sampleBin); // make room for new reading
total += analogRead(aInPin); // add new reading
tempC = total * kAref / (kSampleBin + fudge);
tempF = (tempC * 18 + 3200) / 10;
Serial.print("Temperature- ");
prntTemp(tempF);
Serial.println();
}
}
void prntTemp(int temp)
{
Serial.print(temp / 10); // whole degrees
Serial.print(".");
Serial.print(temp % 10); // tenths
Serial.print("\t");
// display Temperature on LCD
lcd.setCursor(0,0);
lcd.print("Temperature-");
lcd.setCursor(0,1);
lcd.print(tempF);
lcd.println(" degrees F ");
delay(10);// print data every 10milliseconds
if (tempF >= 78.0)
{
digitalWrite(relay, HIGH);
}
}