I was trying to create a digital thermometer using an LCD and a DHT11, but I had a few issues. Hopefully, you could help me with them. One was that my LCD characters were constantly shifting to the left and going off to the screen. This is my code:
#include <LiquidCrystal.h>
#include <DHT.h>
int dhtPin = 7; //Set up DHT11 pin
DHT dht(dhtPin, DHT11);
LiquidCrystal LCD(7, 8, 9, 10, 11, 12); //Create LCD object
void setup() {
Serial.begin(9600); //Turn on serial port
LCD.begin(16, 2); //Start LCD
dht.begin(); //Start DHT11
}
int convert(int tempInC){
return((tempInC * 9/5) + 32); //Calculate temperature in farenheit
}
void loop() {
int temp = dht.readTemperature(); //Read data off of DHT_11
int humi = dht.readHumidity();
Serial.println(" "); //Format text
LCD.setCursor(0,0); //Set LCD cursor
LCD.print("Temperature:"); Serial.print("Temperature: ");
LCD.setCursor(1,0);
LCD.print(convert(temp)); Serial.print(convert(temp));
LCD.print(char(223)); Serial.print("°");
Serial.print(" ");
LCD.print("F "); Serial.print("F ");
LCD.print("("); Serial.print("("); //Print temperature in celsius and farenheit
LCD.print(temp); Serial.print(temp);
LCD.print(char(223)); Serial.print("°");
Serial.print(" ");
LCD.print("C"); Serial.print("C");
LCD.print(")"); Serial.println(")");
delay(250); //Pause briefly
LCD.print(" "); //Clear line
LCD.setCursor(0, 1);
LCD.print("Humidity: "); Serial.print("Humidity: ");
LCD.print(humi); Serial.print(humi); //Print humidity in %
LCD.print("%"); Serial.println("%");
delay(250); //Pause briefly
LCD.print(" "); //Clear line
}
This is how my LCD screen looked:
LCD screen video
Another problem I had was that my DHT11 is constantly displaying the temperature as 0 C and 32 F, and it is at room temperature. I don't know whether this is a problem with my DHT11 sensor or my code.
If anybody could help me with either of these issues, that would be greatly appreciated. I have tried everything but it is not working.