The code below is what i have made pretty much solely based off the thermistor 2 example that is on aurdinos library. I added a lcd display and made it control the relay to my car fan using a npn transistor. The display all works, using a 2x16 LCD and a sainsmart nano V3.0 but the program wont display the temp in degrees only the millivolts. I cant seem to figure it out, look over my code and see what rookie mistake i made?
const int fanMOSFET = 9;//fan transistor not a mosfet anymore
#include <math.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
double thermistor (int RawADC){ //this function is suppose to calculate into kelvin
long res; //for the pull up resistor
double temp;
res = 3950.0 / (1024/RawADC- 1);//br bl or (x 4 series)
temp = log(res); //temp --temporary value
temp = 1 / (0.001465721734 + (0.0002322546976 * temp)+ (0.0000009030452298 * (temp * temp * temp))); // uses steinhart-hart formula used a calculator for my thermistor
temp = temp - 273.15; //converts kelvin to celcius
}
#define ThermistorPIN 0 // is this supposed to go here??
void setup(){
//Serial.begin(9600);// i never tried using this
delay(1000);
digitalWrite (fanMOSFET, LOW); //fan off for vehicle start
lcd.begin (16, 2);
lcd.print ("Fan Off"); //use as a check
delay(1000);
lcd.clear();
}
double temp; // what is this for?
void loop(){
lcd.clear();
lcd.setCursor(8,0);// these are to print multiple values before clearing the screen
int tempValue = analogRead (ThermistorPIN);
float tempMVolt = (tempValue/1023.0)*5.0;//calibrate
lcd.print("mV");
lcd.setCursor(12,0);
lcd.print(tempMVolt, 3); // this section works and displays correctly
//delay(100);
//float tempC = (tempMVolt - .5) * 100; // using TMP36
temp = thermistor (analogRead (ThermistorPIN));
lcd.setCursor(0,0);
lcd.print("Deg C");
lcd.setCursor(0,1);
lcd.print(temp, 3);// always displays temp as 0.00...???????
//delay(100);
if (temp > 83.0){ //switches fan on or off as per calculated temp
digitalWrite (fanMOSFET, HIGH);
lcd.setCursor (7,1);
lcd.print ("Fan ON");
}
else if (temp < 73.0){
digitalWrite (fanMOSFET, LOW);
lcd.setCursor (7,1);
lcd.print ("Fan OFF");
}
delay(200);//so i can read the display before it changes
}