Hello, my first post. I've been searching for answers and just cant figure it out. I think my questions may be just so simple no one bothers to write about it but I'm very new to this code thing.
I'm trying to get a TMP36 to turn on a relay at a certain temperature.
I'm Using a Arduino Leonardo with a standard 4 channel relay module powered separately. I have the following pins wired.
TMP36 PIN1 to Arduino PIN 3.3V with a jumper to AREF
TMP36 PIN2 to Arduino PIN A1
TMP36 PIN3 to Arduino PIN GND
Relay IN1 to Arduino PIN6
The first part of the sketch works fine and I can get he info from the serial monitor. I can also power the cycle the relay using a simple ON/OFF sketch so i'm pretty sure its wired up right I just cant figure out how t use the temp sensor info to control the relay. Any help would be greatly appreciated.
#define aref_voltage 3.3
int tempPin = 1;
int tempReading;
int Relay1 = 6;
void setup(void) {
Serial.begin(9600);
analogReference(EXTERNAL);
pinMode(Relay1,OUTPUT);
}
void loop(void) {
tempReading = analogRead(tempPin);
Serial.print("Temp reading = ");
Serial.print(tempReading);
float voltage = tempReading * aref_voltage;
voltage /= 1024.0;
Serial.print(" - ");
Serial.print(voltage); Serial.println(" volts");
float temperatureC = (voltage - 0.5) * 100 ;
Serial.print(temperatureC); Serial.println(" degrees C");
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print(temperatureF); Serial.println(" degrees F");
delay(1000);
}
// Part Below Not Working
void loop(){
if (" degrees F" > 80)
digitalWrite(Relay1, LOW);
else
digitalWrite(Relay1, HIGH);
delay(500);
}