1

So I am trying to use a humidity sensor with an LCD, but have run into this problem I have yet to fix. My problem is that when it is turned on, it returns the values Humidity: 255% and Temp: 255C. I know for sure that I am getting a signal from the sensor and that is working 100% (I have tested it without an LCD display). I have asked about this in the Adafruit Discord server and someone brought up the possibility of the data being clipped somewhere in the data collection/signal processing/printing chain. Still very confused about how I can fix this, I ask for help.

Here is some code:

#include <dht11.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

dht11 DHT;

#define DHT11_PIN 7

void setup(){
  lcd.begin(16, 2);
}

void loop()
{
  int chk = DHT.read(DHT11_PIN);
  lcd.setCursor(0,0); 
  lcd.print("Temp: ");
  lcd.print(DHT.temperature);
  lcd.print((char)223);
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Humidity: ");
  lcd.print(DHT.humidity);
  lcd.print("%");
  delay(1000);
}
0

1 Answer 1

0

Obviously the DHT sensor has not acquired data to make sure do as follows:

void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(h) || isnan(t) ) {
   lcd.setCursor(0,0);
    lcd.println("DHT not ready!");
    return;
  }
 lcd.setCursor(0,0); 
  lcd.print("Temp: ");
  lcd.print(t);
  lcd.print((char)223);
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Humidity: ");
  lcd.print(h);
  lcd.print("%");
  delay(1000);
}

Make sure you connected the DHT the right way and initialized

DTH11

    Pin1 --> 5v and 10k ohm resistor

    Pin2 --> Arduino Pin7 and 10k ohm resistor

    Pin3 --> no connection

    Pin4 --> Gnd

Initialize correctly

    DHT dht(DHT11_PIN, DHT11);

and in setup() you have to start like

 dht.begin();

Now test and report back

6
  • I checked and it is telling me it that it cant read from the sensor. I beginning to think that this might be a hardware malfunction. I tried the sensor without the LCD and it worked fine, but the addition of it gives me errors. Is there a reason for this? Apr 20, 2020 at 22:51
  • See my edit above Apr 21, 2020 at 7:14
  • As Codebreaker mentions, it looks like you are missing a call to ` dht.begin()` in your setup function (and you need to check for NAN values)
    – Duncan C
    Apr 21, 2020 at 23:10
  • This is better because I have a visual feedback message. It just constantly says DHT not ready. It makes me think it might be a hardware issue (with the Arduino I think). I just want to rule out every other possible problem before I assume it is an Arduino hardware issue. Apr 22, 2020 at 5:48
  • Have you initialized correctly See my edit DHT dht(DHT11_PIN, DHT11); AND dht.begin(); IN setup() AND check wether you use resistors see above its unlikely that the sensor is NOT working Apr 22, 2020 at 7:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.