DHT 22 Read Fail

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
scottlit
 
Posts: 8
Joined: Wed Jan 29, 2014 6:14 pm

DHT 22 Read Fail

Post by scottlit »

I am receiving a read fail message from my AM 2302 while using the serial monitor in the IDE or serial LCD with backpack. I am at a total loss but can provide some context. I'm new to this, so bear with me. Initially, when attached individually to a breadboard, I could receive via the serial com port or lcd running the Adafruit library dht tester sketch. The source code I have written for my project will not work either. I am assuming wiring is to blame. I have run power and ground from a 5v rail on a perfboard to a screw-type terminal block then to the sensor. I am receiving 4.90v to the sensor, but that's also what is reading directly at the 5v pin on the arduino uno. Therefore, I don't suspect voltage drop as the problem. I have tried receiving data with a 10k pullup attached to the perfboard and with no pullup, no dice. In the serial monitor, after the "Read Fail, Failed to read from DHT", it does display humidity 0% and temp 0*c three successive times with a carriage return. I'm assuming this is just code execution in between sensor readings. Sorry for being lengthy and not including a diagram (don't know fritzing). Any help is greatly appreciated. Also here is the code I wrote if it helps in the diagnosis at all.
also, definitely connecting 5v to red sensor wire, gnd to black wire, and input to yellow. I have not tried another pin on the arduino. If so, can I just declare the new pin number before void setup without a pinMode declaration?

Code: Select all

#include "DHT.h"
#include <Servo.h>

#define DHTPIN 2     // what pin we're connected to

#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);    //dht has 5v vcc with 10k pullup between vcc and data 
Servo exhaustServo;
Servo intakeServo;

const int circFan = 5;  //include tx to serial lcd on pin 1 arduino lcd has 5v vcc
const int exhaustFan=6;
const int heatLight=7;
const int photocell=A0;
float dayTempHigh=25; //high with light =77F
float dayTempLow=23;  
float nightTempHigh=17;//high without light=62F
float nightTempLow=16;
int lightValue=0;
int state=LOW;
/*photocell placed on back side of chamber, third shelf from bottom, fascing high bay 
lights, 10k resistor.  Value is 770 with both heat lamps, 945-950 with one high bay, 
965-970 with both high bays.*/



unsigned long fanStartTime=0;
unsigned long fanInterval=600000;



void setup() {
  Serial.begin(9600); 
  Serial.println("DHTxx test!");
  exhaustServo.attach(8);
  intakeServo.attach(9);
  pinMode (circFan, OUTPUT);
  pinMode (exhaustFan, OUTPUT);
  pinMode (heatLight, OUTPUT);
  
 
  dht.begin();
}

void loop() {
  
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  
  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.print("Humidity: "); 
    Serial.print(h);
    Serial.println(" %\t");
    Serial.print("Temperature: "); 
    Serial.print(t);
    Serial.println(" *C");
    
  }
 lightValue=analogRead(photocell);//check lights, if heat lamps only then run night
 if (lightValue>800){    //day mode
   if (heatLight==LOW){
    if(t>dayTempHigh || h>70){
    digitalWrite (exhaustFan, HIGH);
    delay (15000);
    exhaustServo.write(90);
    intakeServo.write(90);
    digitalWrite (exhaustFan,LOW);
    delay(15000);
    exhaustServo.write(0);
    intakeServo.write(0);}
   }
 }
 else
 
 if (lightValue>800){      //day mode
   if (t<dayTempLow){
    if (exhaustFan==LOW){
   digitalWrite (heatLight,HIGH);}
   }
 }
 else
 
 if(lightValue<900){       //night mode
   if(t>nightTempHigh || h>75){
     if (heatLight==LOW){
       digitalWrite(exhaustFan,HIGH);
       delay(15000);
       exhaustServo.write(90);
       intakeServo.write(90);
       digitalWrite (exhaustFan,LOW);
       delay(15000);
       exhaustServo.write(0);
       intakeServo.write(0);}
   }
 }
 else
 
 if (lightValue<900){     //night mode
   if (t<nightTempLow){
     if (exhaustFan==LOW){
       digitalWrite(heatLight,LOW);}
   }
 }
 else
 
 if (fanStartTime+ fanInterval<millis()){
   state=!state;
   digitalWrite (circFan, state);
   delay (10000);
   digitalWrite (circFan, LOW);
   fanStartTime=millis();}
   
delay(2000);
Last edited by adafruit_support_bill on Fri Feb 28, 2014 8:01 am, edited 1 time in total.
Reason: Fixed the [code] tags

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: DHT 22 Read Fail

Post by adafruit_support_bill »

Initially, when attached individually to a breadboard, I could receive via the serial com port or lcd running the Adafruit library dht tester sketch.
Are you saying that it worked on a breadboard with the tester sketch? If so, does the tester sketch still work?

scottlit
 
Posts: 8
Joined: Wed Jan 29, 2014 6:14 pm

Re: DHT 22 Read Fail

Post by scottlit »

No, the test sketch does not work currently. It is now hardwired as described earlier, if that helps at all. Thanks

scottlit
 
Posts: 8
Joined: Wed Jan 29, 2014 6:14 pm

Re: DHT 22 Read Fail

Post by scottlit »

Sorry, forgot to mention that yes, the tester sketch did work with the breadboard

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: DHT 22 Read Fail

Post by adafruit_support_bill »

Try it back on the breadboard. If it works there, the problem is with the wiring. If not then the sensor may have failed.

If you can post a photo of your wiring, we'll take a look for possible causes.

scottlit
 
Posts: 8
Joined: Wed Jan 29, 2014 6:14 pm

Re: DHT 22 Read Fail

Post by scottlit »

Thanks,
I will try to get a good picture. Everything is already mounted in an enclosure (got a little ahead of myself). I am going to try on the breadboard. Not sure if I should use a pullup. I know the tutorial says 10k, the datasheet says 1k, and the main page on the Adafruit website says nothing since there is one mounted internally on the sensor. I have tried with and without, both to no avail. I would like to know which is best, just for future reference. If a pullup is not necessary, then I can go straight from the Arduino, right?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: DHT 22 Read Fail

Post by adafruit_support_bill »

The AM2302 has a pullup wired internally. You should not have to add one externally.

scottlit
 
Posts: 8
Joined: Wed Jan 29, 2014 6:14 pm

Re: DHT 22 Read Fail

Post by scottlit »

Tried wiring the AM2302 directly to the Arduino Uno (nothing else connected to arduino). Still receiving a read fail from the sensor while running the DHTester sketch included with the library. I think the sensor is bad. Any suggestions on simple/common issues with the components of the sensor so that I might be able to repair it. If not, is there any chance that I can get another. Thanks for all of your help and patience.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: DHT 22 Read Fail

Post by adafruit_support_bill »

When did you purchase this sensor?

scottlit
 
Posts: 8
Joined: Wed Jan 29, 2014 6:14 pm

Re: DHT 22 Read Fail

Post by scottlit »

I purchased it 2/1/14. I used it once on a breadboard with the tester sketch before I began having issues. Thanks

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: DHT 22 Read Fail

Post by adafruit_support_bill »

If you contact [email protected] with a link to this thread, we can send you out a replacement.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”