LowPowerLab Forum

Software support => Coding questions => Topic started by: harrinator on March 03, 2020, 03:56:33 PM

Title: trouble getting DHT11 to work
Post by: harrinator on March 03, 2020, 03:56:33 PM
Hi,

I'm attempting to use the DHT11 with the Moteino with trace antenna and have been having trouble getting any results from it (the code compiles, and I'm continually getting "Failed to read from DHT sensor!" in the serial monitor). I know the sensor itself isn't faulty because the same code works properly on an Arduino Uno.

I have connected the + and - pins to the 3.3V and Ground pins and tried each analog input for the data pin. I have attached the code I was using below.

Thank you in advance for any help/advice you can provide- I'm pretty new to Moteino and Arduino in general.

Code: [Select]
#include "DHT.h"
#define DHTPIN A0     
#define DHTTYPE DHT11   

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");

  dht.begin();
}

void loop() {
 
  delay(2000);
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);

  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  float hif = dht.computeHeatIndex(f, h);
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F");
}
Title: Re: trouble getting DHT11 to work
Post by: Felix on March 03, 2020, 04:51:13 PM
Power supply voltage: 5V
https://www.osepp.com/electronic-modules/sensor-modules/63-humidity-temperature-sensor