Hi guys, I have a problem with my 16 pin LCD currently. I'm making a thermostat which displays the current temperature and selected temperature(temperature is chosen using a potentiometer).
On the LCD it should display values for "Set to:" and "Currently:". Now here is the weird part, the "Currently" values seems to update itself however the "Set to" does not respond to changes made to the potentiometer. Funny thing is that it both values update itself on the serial comm and is working perfectly. Any ideas what is happening? Also, there are unnecessary lines being displayed as well. How do i get rid of those? I've added a picture!
#include <Wire.h>
#include <LiquidCrystal.h>
int tmp102Address = 0x48;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int potPin = A0; //analog 0
int relayPin = 1;// digital 2
int lowTemp = 25; //lowest temp in C you can set it to
int highTemp = 35; //highest temp in C you can set it to
void setup(){
Serial.begin(9600);
Wire.begin();
lcd.begin(16,2);
pinMode (relayPin,OUTPUT);
}
void loop(){
float temperatureSetAt = getThreshold();
float currentCelsius = getTemperature();
if(temperatureSetAt < currentCelsius){
digitalWrite(relayPin, HIGH); //turn it on
}else{
digitalWrite(relayPin, LOW); //turn it off
}
lcd.print("Set to:");
lcd.println(temperatureSetAt);
lcd.setCursor(0, 2);
lcd.print("Currently:");
lcd.println(currentCelsius);
Serial.print("Set Celsius:");
Serial.println(temperatureSetAt);
Serial.print("Current Celsius: ");
Serial.println(currentCelsius);
delay(2000); //just here to slow down the output. You can remove this
}
float getThreshold(){
int potVaule = analogRead(potPin);
potVaule = map(potVaule, 0, 1023, lowTemp, highTemp);
float floatValue = (float)potVaule;
return floatValue;
}
float getTemperature(){
Wire.requestFrom(tmp102Address,2);
byte MSB = Wire.read();
byte LSB = Wire.read();
//it's a 12bit int, using two's compliment for negative
int TemperatureSum = ((MSB << 8) | LSB) >> 4;
float celsius = TemperatureSum*0.0625;
return celsius;
}