Hey guys,
I know this isn't gonna be the hardest among all the problems posted here but I just can't figure out why this isn't working.
Basically I've been trying to make a simple thermostat with a LM35 temperature sensor,a 10K rotary potentiometer and a lcd screen.
The potentiometer would give the desired temperature on a range from 0 to 30 °C ,and if the temperature returned from the LM35 was lower than the one calculated from the pot ,a led would light up.
The desired temperature and the actual one would respectively be shown up on the lcd screen.
Here's the code:
#include <LiquidCrystal.h>
int led=7; //led pin
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
lcd.begin(16, 2);
pinMode(led,OUTPUT);
Serial.begin(9600); //I've added this to monitor the two temperatures on serial screen,so i would have know it wasn't just a lcd problem
}
void loop() {
float temp; //actual temperature
int fine; //desired temperature
lcd.setCursor(0,0);
fine=((30*analogRead(5))/1024); //calculating the desired temp.
lcd.print("Temp finale:"); //printing it on lcd and serial monitor
lcd.setCursor(14,0);
lcd.print(fine);
Serial.print("Temp finale:");
Serial.println(fine);
lcd.setCursor(0, 2);
lcd.print("Temp:");
Serial.print("Temp attuale:");
temp=(5.0 * analogRead(0) * 100.0) / 1024; //calculating the actual temp.
lcd.setCursor(11,2);
lcd.print(temp);
Serial.println(temp);
if(temp<fine){ //lighting up the led
digitalWrite(led,HIGH);
}
else
digitalWrite(led,LOW);
delay(2000); //update frequency,otherwise the numbers on the lcd would flicker
}
The problem is that if the pot is rotated completely to 0,the lm35 will work correctly. When i start rotating it,the actual temperature will start dropping and then,from a certain point of the pot (about 1/3) would start rising until getting about 37°C
with the desired temp. on 30 °C.
I've tested the code and the hardware in many ways and everything works fine singularly;but whenever i put the code for the desired temperature and the actual one together,everything goes 'crazy'. I'm sure it's not an lcd problem 'cause it gives the same problem even on lcd screen.
I'll put a fritzing file for the wiring,
thanks in advance.