Mike Paige Code

#include <LiquidCrystal.h> // include LiquidCrystal library

LiquidCrystal lcd = LiquidCrystal(12, 11, 5, 4, 3, 2);

int value = 0;
double conversion = .0049;
double temp;
double cutoff = 65; // hardcode cutoff of 65 degrees (F) for now
int modeSwitch;

int switch1 = 9;
int switch2 = 10;
int fan = 7;

void setup() {
  lcd.begin(16,2);
  lcd.print("Fan Mode: ");
  pinMode(switch1, INPUT);
  pinMode(switch2, INPUT);
  pinMode(fan, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  lcd.setCursor(10,0);
  value = analogRead(0);
  convert();
 
  if (digitalRead(switch1) == HIGH && digitalRead(switch2) == LOW) {
    digitalWrite(fan, HIGH);
    lcd.print("ON    ");
  } else if (digitalRead(switch1) == LOW && digitalRead(switch2) == HIGH) {
    digitalWrite(fan, LOW);
    lcd.print("OFF   ");
  } else {
    lcd.print("AUTO  ");
    if (temp > cutoff) {
        digitalWrite(fan, HIGH);
      } else {
        digitalWrite(fan, LOW);
      }
  }
 
  lcd.setCursor(0,1);
  lcd.print("Temp (F): ");
  lcd.setCursor(10,1);
  lcd.print((int)temp);
 
  if (temp < 10) {
    lcd.setCursor(11,1);
    lcd.print(" ");
  }
 
 
  // wait half a second between reads
  delay(500);
}

void convert() {
 
 temp = conversion*value*200 - 273;
 
 // convert to Fahrenheit (COMMENT OUT THE CODE BELOW TO KEEP CELSIUS READING)
 temp = temp * (double)(9/5) + 32;
 // END conversion to Fahrenheit
 
 Serial.println(value);
 
}

Back