Hi folks,
Can You please help me out with my issue.
I´m trying to display the temperature to the LCD from inside a loop.
Probraly not the right way to do it, but I have not been able to search for a solution that works for me.
The temperature read out works in the serial monitor.
I have tryed to put this into the void setup, but that didn´t work:
Vo = analogRead(ThermistorPin);
R2 = R1 * (1023.0 / (float)Vo - 1.0);
logR2 = log(R2);
T = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
Tc = T - 273.15;
Tf = (Tc * 9.0) / 5.0 + 32.0;
Please tell me what I´m doing wrong.
Thanks in advance!
The complete Sketch:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
int ThermistorPin = 0;
int Vo;
float R1 = 10000;
float logR2, R2, T, Tc, Tf;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
int fan = 6; // the pin where fan is
int led = 8; // led pin
int temp;
int tempMin = 40; // the temperature to start the fan
int tempMax = 90; // the maximum temperature when fan is at 100%
int readTemp() { // get the temperature and convert it to celsius
temp = analogRead(ThermistorPin);
//return temp * 0.48828125;
}
void setup() {
{
// initialize the LCD
lcd.init();
// Turn on the blacklight and print a message.
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("FAN CONTROLLER");
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(Tc);
lcd.print(" ");
lcd.print((char)223);
lcd.print("C");
delay(2000); //Delay 2 sec.
}
{
Serial.begin(9600);
pinMode(fan, OUTPUT);
pinMode(led, OUTPUT);
pinMode(ThermistorPin, INPUT);
}
}
void loop() {
Vo = analogRead(ThermistorPin);
R2 = R1 * (1023.0 / (float)Vo - 1.0);
logR2 = log(R2);
T = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
Tc = T - 273.15;
Tf = (Tc * 9.0) / 5.0 + 32.0;
Serial.print("Temperature: ");
// Serial.print(Tf);
// Serial.print(" F; ");
Serial.print(Tc);
Serial.println(" C");
delay(500);
if (Tc < tempMin) { // if temp is lower than minimum temp
digitalWrite(fan, LOW);
}
if (Tc >= tempMin) { // if temp is lower than minimum temp
digitalWrite(fan, HIGH);
//analogWrite(A5, fanSpeed); // spin the fan at the fanSpeed speed
}
if (Tc >= tempMax) { // if temp is higher than tempMax
digitalWrite(led, HIGH); // turn on led
Serial.print("TEMP IS TO HIGH!");
}
else { // else turn of led
digitalWrite(led, LOW);
}
}

