Hello!
I'm new to programming, so my skills mainly include looking up commands and editing existing code. I have a code that should print the current temperature in F to the console, and if the temperature goes over 75 degrees it will activate a case fan. This all works well, but when the temperature goes below 75, the fan doesn't stop. Here is my code, as messy as it is.. If anyone can help out by fixing the code and/or telling me how I majorly screwed up, that would be seriously appreciated.
Thanks!
/*
Arduino thermistor example software
Tutorial: http://www.hacktronics.com/Tutorials/arduino-thermistor-tutorial
Copyright (c) 2010 Mark McComb, hacktronics LLC
License: The MIT License – Open Source Initiative (Go crazy)
*/
#include <LiquidCrystal.h>
#include <math.h>
/*
See tutorial for Thermistor connections
LCD Connections:
rs (LCD pin 4) to Arduino pin 12
rw (LCD pin 5) to Arduino pin 11
enable (LCD pin 6) to Arduino pin 10
LCD pin 15 to Arduino pin 13
LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2
*/
int pin2 = 2;
void setup(void) {
Serial.begin(9600);
pinMode(pin2, OUTPUT);
}
double Thermister(int RawADC) {
double Temp;
// See Thermistor - Wikipedia for explanation of formula
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp - 273.15; // Convert Kelvin to Celcius
return Temp;
}
void printTemp(void) {
double fTemp;
double temp = Thermister(analogRead(0)); // Read sensor
fTemp = (temp * 1.8) + 32.0; // Convert to USA
Serial.print(fTemp);
Serial.println(" F");
if(fTemp > 75)
digitalWrite(pin2, HIGH);
}
void loop(void) {
printTemp();
delay(1000);
}