I get this error every time. I used the DHT tester file from this library. Which gives me an error.
And then I realized that in my code Arduino recognizes only the readTemperature
function, not readHumidity
, but it doesn't give any compile error. Also, when I read the sensor, this is the output:
Humidity Sensor Test
Temp: 0C, Humidity: 0%
Temp: 0C, Humidity: 0%
Temp: 0C, Humidity: 0%
My code is here:
//DHT11 Sensor:
#include "DHT.h"
#define DHTPIN 5 // which digital pin we're connected to
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
//I2C LCD:
#include <Wire.h> // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h>
// Set the LCD I2C address
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup() {
Serial.begin(9600);
delay(300);
lcd.begin(16,2);
Serial.println("Humidity Sensor Test");
dht.begin();
delay(300);
}
void loop() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
int h = dht.readHumidity();
int t = dht.readTemperature();
// set the cursor to (0,0):
lcd.setCursor(0, 0);
// print from 0 to 9:
lcd.print("Temp: ");
lcd.print(t);
lcd.print("C");
// set the cursor to (16,1):
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.print(h);
lcd.print("%");
Serial.print("Temp: ");
Serial.print(t);
Serial.print("C, Humidity: ");
Serial.print(h);
Serial.println("%");
delay(2500);
}
Also I have the 10k resistor between data and Vcc pins. Data is connected to digital pin 5. Has anyone had this problem before?
lcd
declaration is wrong.