First off I hope I've put this in the correct place. I've troubleshooted the DHT11 and it seeems to be working fine, so it must be an issue with the LCD code, if its in the wrong place I'm sorry and would appreciate if a mod could move it.
I followed a guide Here to set up a temperature and humidity sensor.
The issue is that the display gives erroneous readings for humidity, for example if I increase the humidity (by gently breathing on the sensor) the humidity % goes to 0% - 9% and the LCD occasionally prints %% (two % symbols) when this error occurs.
I've checked to make sure its not the sensor itself by running the DHT test code and the correct humidity is always displayed via the serial monitor, even when breathing gently on the sensor to alter the readout. The temperature is usually different than the temperature displayed on the LCD too.
As such I assume that the problem is with the code for displaying things, especially as I'm getting things like an extra % symbol at times.
Looking at the comments on the guide there is an issue with the code (it should be "#include <DHT.h>" but instead it's "#include <dht.h>" I've tried changing this but I run into more issues with the code if I do, two lines down under "dht DHT" with an error message of; 'dht' does not name a type
Any ideas what might be wrong?
/* DHT-11 sensor with 12c 16x2 LCD with Arduino uno
Temperature and humidity sensor displayed in LCD
based on: http://www.ardumotive.com/how-to-use-dht-22-sensor-en.html and
https://www.ardumotive.com/i2clcden.html for the i2c LCD library by Michalis Vasilakis
Recompile by adhitadhitadhit
Notes: use LCD i2c Library from link above, i'm not sure why but new Liquidcristal library from Francisco Malpartida isn't working for me
other thing, check your */
//Libraries
#include <dht.h> // sensor library using lib from https://www.ardumotive.com/how-to-use-dht-22-sensor-en.html
#include <LiquidCrystal_I2C.h> // LCD library using from https://www.ardumotive.com/i2clcden.html for the i2c LCD library
#include <Wire.h>
dht DHT;
//Constants
#define DHT11_PIN 2 // DHT 11 (AM2302) - pin used for DHT22
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 after finding it from serial monitor (see comment above) for a 16 chars and 2 line display
//Variables
float hum; //Stores humidity value
float temp; //Stores temperature value
void setup()
{
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setBacklight(HIGH);
}
void loop()
{
int chk = DHT.read11(DHT11_PIN);
//Read data and store it to variables hum and temp
hum = DHT.humidity;
temp= DHT.temperature;
//Print temp and humidity values to LCD
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.print(hum);
lcd.print("%");
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print(temp);
lcd.print((char)223);
lcd.println("C ");
delay(2000); //Delay 1 sec between temperature/humidity check
Serial.print(F("Humidity: "));
Serial.print(hum);
Serial.print(F("% Temperature: "));
Serial.print(temp);
Serial.print(F("°C "));
}
Edit: Ignore the last 5 lines of code (Serial.print) a friend and I were seeing if we could get it to display to the serial monitor using this sketch but instead used the DHT tester sketch that's in the DHT library.