Grove Temperature and Humidity Sensor shows no value/timeout error

Hi, I am connecting Grove Temp & Hum Sensor to XBee Carrier + Wifi Bee, I am using the library in the Wiki and use the example like this :

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

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

// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11 
//#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

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

  dht.begin();
}

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)
  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.print(" %\t");
    Serial.print("Temperature: "); 
    Serial.print(t);
    Serial.println(" *C");
  }
}

but the result is :

DHTxx test!
Read failFailed to read from DHT
Humidity: 0.00 %   Temperature: 0.00 *C
Humidity: 0.00 %   Temperature: 0.00 *C
Humidity: 0.00 %   Temperature: 0.00 *C

==============
and then I tried to use another code :

/* YourDuino.com Example Software Sketch
   DHT11 Humidity and Temperature Sensor test
   Credits: Rob Tillaart
   http://arduino-direct.com/sunshop/index.php?l=product_detail&p=162
   terry@yourduino.com */
   
/*-----( Import needed libraries )-----*/
#include <dht11.h>

/*-----( Declare objects )-----*/
dht11 DHT11;

/*-----( Declare Constants, Pin Numbers )-----*/
#define DHT11PIN 2

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600);
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  Serial.println();
}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  Serial.println("\n");

  int chk = DHT11.read(DHT11PIN);

  Serial.print("Read sensor: ");
  switch (chk)
  {
    case 0: Serial.println("OK"); break;
    case -1: Serial.println("Checksum error"); break;
    case -2: Serial.println("Time out error"); break;
    default: Serial.println("Unknown error"); break;
  }

  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);

  Serial.print("Temperature (oC): ");
  Serial.println((float)DHT11.temperature, 2);

  Serial.print("Temperature (oF): ");
  Serial.println(Fahrenheit(DHT11.temperature), 2);

  Serial.print("Temperature (K): ");
  Serial.println(Kelvin(DHT11.temperature), 2);

  Serial.print("Dew Point (oC): ");
  Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));

  Serial.print("Dew PointFast (oC): ");
  Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));

  delay(2000);
}/* --(end main loop )-- */

/*-----( Declare User-written Functions )-----*/
//
//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
        return 1.8 * celsius + 32;
}

//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
        return celsius + 273.15;
}

// dewPoint function NOAA
// reference: http://wahiduddin.net/calc/density_algorithms.htm 
double dewPoint(double celsius, double humidity)
{
        double A0= 373.15/(273.15 + celsius);
        double SUM = -7.90298 * (A0-1);
        SUM += 5.02808 * log10(A0);
        SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
        SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
        SUM += log10(1013.246);
        double VP = pow(10, SUM-3) * humidity;
        double T = log(VP/0.61078);   // temp var
        return (241.88 * T) / (17.558-T);
}

// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
        double a = 17.271;
        double b = 237.7;
        double temp = (a * celsius) / (b + celsius) + log(humidity/100);
        double Td = (b * temp) / (a - temp);
        return Td;
}

/* ( THE END ) */

and the result is :

DHT11 TEST PROGRAM 
LIBRARY VERSION: 0.3.2



Read sensor: Time out error
Humidity (%): 0.00
Temperature (oC): 0.00
Temperature (oF): 32.00
Temperature (K): 273.15
Dew Point (oC): nan
Dew PointFast (oC): nan

=====
I tried another code again from here :

#define dht11_pin 14 //Analog port 0 on Arduino Uno
//#define dht11_pin 54 //Analog port 0 on Arduino Mega2560
  
byte read_dht11_dat()
{
  byte i = 0;
  byte result=0;
  for(i=0; i< 8; i++)
  {
    while (!digitalRead(dht11_pin));
    delayMicroseconds(30);
    if (digitalRead(dht11_pin) != 0 )
      bitSet(result, 7-i);
    while (digitalRead(dht11_pin));
  }
  return result;
}
  
  
void setup()
{
  pinMode(dht11_pin, OUTPUT);
  digitalWrite(dht11_pin, HIGH);
  Serial.begin(9600);
  Serial.println("Ready");
}
      
void loop()    
{
  byte dht11_dat[5];   
  byte dht11_in;
  byte i;// start condition
       
  digitalWrite(dht11_pin, LOW);
  delay(18);
  digitalWrite(dht11_pin, HIGH);
  delayMicroseconds(1);
  pinMode(dht11_pin, INPUT);
  delayMicroseconds(40);     
    
  if (digitalRead(dht11_pin))
  {
    Serial.println("dht11 start condition 1 not met"); // wait for DHT response signal: LOW
    delay(1000);
    return;
  }
  delayMicroseconds(80);
  if (!digitalRead(dht11_pin))
  {
    Serial.println("dht11 start condition 2 not met");  //wair for second response signal:HIGH
    return;
  }
    
  delayMicroseconds(80);// now ready for data reception
  for (i=0; i<5; i++)
  {  dht11_dat[i] = read_dht11_dat();}  //recieved 40 bits data. Details are described in datasheet
    
  pinMode(dht11_pin, OUTPUT);
  digitalWrite(dht11_pin, HIGH);
  byte dht11_check_sum = dht11_dat[0]+dht11_dat[2];// check check_sum
  if(dht11_dat[4]!= dht11_check_sum)
  {
    Serial.println("DHT11 checksum error");
  }
  Serial.print("Current humdity = ");
  Serial.print(dht11_dat[0], DEC);
  Serial.print("%  ");
  Serial.print("temperature = ");
  Serial.print(dht11_dat[2], DEC);
  Serial.println("C  ");
  delay(2000); //fresh time
}

the result :

Ready
dht11 start condition 1 not met
dht11 start condition 1 not met
dht11 start condition 1 not met
dht11 start condition 1 not met
dht11 start condition 1 not met
dht11 start condition 1 not met

I was wondering that the cause is the I/O pin, in both code above they use pin 2 but when I googling around I found that the code is for DHT11 like this :

pin 1 = VCC
pin 2 = Signal/Data
pin 3 = NC/Not Connected
pin 4 = Ground
not a Grove like I am using :

that's why the codes above use pin 2, so I tried to change it to pin 5 as discribed in Xbee Carrier Wiki, although I am not sure that pin 5 means D5 and pin 6 means D6 Grove Connector:

When using an RFBee, the following pinouts apply for using the arduino IDE
Pin 5 is the Grove connector for I/O - Yellow wire
Pin 6 is the Grove connector for I/O - White wire

and when I carefully look at the cable, everything is at the right place :
Cable Colour == Xbee Carrier == Grove Temp Hum
Yellow == D5 == SIG
White == D6 == NC
Red == VCC == VCC
Black == Ground == Ground
but the result is the same, timeout or communication failed

I also asked on "Question & Answer" section in Xbee Carrier product guide and Jacket Chueng answered :

Hi.You also need to add some code to the program,such as: pinMode(16, OUTPUT); digitalWrite(16, LOW).And more information you can refer to our wiki:Pin 16 may need to be driven low to provide enough power to the I/O Grove [via mosfet].
Answered by Jacket Chueng | 2013-04-07

anyone can give me some more detail what should I do? I am a newbie on Arduino and microcontroller, I just want to make a simple project and develop it later after this has been success.
Thank you.

#sorry for my bad english

So the only problem is how to connect it ?
Do you have a Arduino board ?

Erdin:
So the only problem is how to connect it ?
Do you have a Arduino board ?

no, the problem is how to make the result shows the sensor value, because from all codes i have been tried they were showing nothing but zero and timeout error
I use Xbee Carrier and in Arduino software i already choose Arduino Duemilanove w/ ATmega328 as instructed in the Wifi Bee Wiki

Is there any suggestion?

The sketch is not the problem.
I have never seen a bad sketch by ladyada/adafruit.

Do you have a multimeter ? Can you measure if the 5V and GND are good ? And does the signal wire go from the sensor the to microcontroller ?
If you would have a Arduino board, you could test the sketch, and have it running in 5 or 10 minutes. But I don't know how your board is connected.

I have measured the vcc and ground and the result is around 3.8 V. And what should I do to check the signal wire?
The sensor connected to Xbee Carrier using 4-wire-cable, it looks like this :

Xbee Carrier programmed with Arduino IDE and set the board to Arduino Duemilanove w/ Atmega 328

Is this you, http://www.seeedstudio.com/forum/viewtopic.php?f=17&t=4388 ?
You don't have to hide it, you could have added a link to it. No problem.

I have been looking at the schematics the website and the photos, but it is a classic example how not to do it.
They use different names, different pin numbering, and explanation that is not complete.

I think Arduino digital pin 5 is connected to the signal wire of the DTH11.
But you got that far already and it didn't work.

Did you read this: "Pin 16 may need to be driven low to provide enough power to the I/O Grove [via mosfet]".
Could you try pin 5 once more with the Ladyada code ?
Add this to the code at setup(), before dth.begin().

// These lines are needed to ensure that power is provided to the Grove I/O connector
pinMode(16, OUTPUT);
digitalWrite(16, LOW);

If that doesn't work, disconnect the sensor, and write a sketch that toggles pin 5 every second. Try to measure that with a multimeter.

yeah that's me and I'm not trying to hide it but because the content is almost the same then it's no use to add the link.. :smiley:

I changed the code like this :

void setup() {
  Serial.begin(9600); 
  Serial.println("DHTxx test!");
 // These lines are needed to ensure that power is provided to the Grove I/O connector
  pinMode(16, OUTPUT);
  digitalWrite(16, LOW);
  dht.begin();
}

but the result still the same.. :frowning:

so, how should I write the code to toggle pin 5 every second?

#include <dht11.h>
#define DHTPIN 5   

void setup() {
  Serial.begin(9600); 
  pinMode(16, OUTPUT);
  digitalWrite(16, LOW);
}

void loop() {
  pinMode(5, OUTPUT);
  digitalWrite(5, LOW);
  delay(1000);
  pinMode(5, OUTPUT);
  digitalWrite(5, HIGH);
  delay(1000);
}

please correct it

Not sure if this will help you or not. It may. This is something I had issues with as well (In a sense) using the DHT11. Here is a link to the tread I posted. At the end of it I provide a diagram, links to the updated Lib files and some code for testing. This is with an UNO board mind you.

Your sketch will work, but you can set the "pinMode(5, OUTPUT);" once in setup(), you don't have to do that every time.

The pull-up resistor is something I forgot to mention. Use a pull-up resistor of 4k7 or 10k from the signal line to 5V.
See also this tutorial, Connecting to a DHTxx Sensor | DHT11, DHT22 and AM2302 Sensors | Adafruit Learning System

sencorp:
Not sure if this will help you or not. It may. This is something I had issues with as well (In a sense) using the DHT11. Here is a link to the tread I posted. At the end of it I provide a diagram, links to the updated Lib files and some code for testing. This is with an UNO board mind you.

Outdated and confusing? - #9 by system - Programming Questions - Arduino Forum

I already tried that code before and the result is :

C`$±4(8ìW)¸° 8`4Uù<4(($W)¨=ì8($u(?³ (è$u8¸=°6:84u4=°4

Erdin:
Your sketch will work, but you can set the "pinMode(5, OUTPUT);" once in setup(), you don't have to do that every time.

The pull-up resistor is something I forgot to mention. Use a pull-up resistor of 4k7 or 10k from the signal line to 5V.
See also this tutorial, Connecting to a DHTxx Sensor | DHT11, DHT22 and AM2302 Sensors | Adafruit Learning System

I think Grove Temperature and Humidity Sensor is a ready-to-use sensor, there is no need to add anything because it already has a 10k resistor
take a look on this pic :

I change the code I wrote before :

#include <dht11.h>
#define DHTPIN 5   

void setup() {
  Serial.begin(9600); 
  pinMode(16, OUTPUT);
  digitalWrite(16, LOW);
  pinMode(5, OUTPUT);

}

void loop(){
  digitalWrite(5, LOW);
  delay(1000);
  digitalWrite(5, HIGH);
  delay(1000);
}

then i measured SIG and GND on DHT11, first time and second time I measured it worked, multimeter show 3.2 V then go to 0 V and then back to 3.2 V again. But i am not sure if I accidentally connect the SIG/VCC with GND using the multimeter needles or what, when I measured it again the power stay at 3.2 V, no change even I waited several seconds. Did that makes an effect?

edited
OK I have retried it many times to make sure, and I think my hand was slipped out a little that makes a change on measuremenet, because when I retried it again many times there was no change on measurement, stay still on 3.2 V.. :~

help me please :frowning:

I'm sorry, but I don't know what else to do.
The resistor is indeed on the breakout board.

You might want to try another sensor, perhaps this one is broken.
Is it possible to have someone looking at it at your place ?
Perhaps someone with a logic analyzer or an oscilloscope.
It is even possible to record the signal to/from the DHT11 with the audio input of a PC. I use an attenuator to reduce the 5V to 1V.

If you buy an Arduino Uno and a new sensor, it should be working without problem.

I asked my friend to check it using oscilloscope, it only shows the voltage but when he checked the SIG and GND it shows nothing, even he tried to change the temperature around the sensor with blowing his warm breath to the sensor, the pulse didnt change. So, the sensor maybe broken?

I'm using the sensor with Wifi Bee + Xbee Carrier because I want to connect the sensor to wireless network.

That are two different things, "nothing" and "pulse didn't change".
The Arduino request data from it, so you should see the start pulse.
Some explanation is here, Measurement of temperature and relative humidity using DHT11 sensor and PIC microcontroller | Embedded Lab

If it is not responding, it might be broken.

Sorry for my bad english, it's difficult to find the right words to describe what I wanted to say.. :frowning:
So, the sensor was not responding, and the shop suggested me to send it back to them so they can help to check if the sensor is fine.

You need to test the Sensor to make sure its operating properly.
The Sensor is a 1 wire sensor which uses bidirectional data transmission on the data line.
If you pull the data line low for 20 ms and then release it , the sensor will send a binary data stream
which comprises 5 bytes of data.
The sensor normally sends nothing until you ask it to send.

can you help me with the code to do that?

You need a CRO to test the sensor.
Until you verify that the sensor is actually working properly, theres no point in trying to write code to test it.

They said the sensor is fine, and someone said that the sketches I used above don't match for xbee carrier, but matches for simple board like Uno, Mega, etc. and he said that I should build simple web server which can read sensor data. I've used sketch from Wifi Bee Wiki :

/*
 * A simple sketch that uses WiServer to serve a web page
 */


#include <WiServer.h>

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[]    = {192,168,234,55};   // IP address of WiShield
unsigned char gateway_ip[]  = {192,168,234,1};   // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
char ssid[]                 = {"Connectify-me"};   // max 32 bytes
unsigned char security_type = 3;               // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"0987654321"};	// max 64 characters

// WEP 128-bit keys
prog_uchar wep_keys[] PROGMEM = { 
	0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,	// Key 0
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	// Key 1
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	// Key 2
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00	// Key 3
};

// setup the wireless mode; infrastructure - connect to AP; adhoc - connect to another WiFi device
#define WIRELESS_MODE_INFRA	1
#define WIRELESS_MODE_ADHOC	2
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char sensorValue;
unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------


int counter;
// This is our page serving function that generates web pages
boolean sendMyPage(char* URL) {
  
    // Check if the requested URL matches "/"
    if (strcmp(URL, "/") == 0) {
        // Use WiServer's print and println functions to write out the page content
        WiServer.print("<html>");
        // Instruct the web broweser to refersh every 10 seconds 
        WiServer.print("<head><meta http-equiv=\"refresh\" content=\"10\"> </head>"); 
        WiServer.println("<H1>WifiBee Connected...<H1>");
        WiServer.print("<H2>Sensor Value = ");
        WiServer.print(sensorValue);  // connected to an exernal sensor. The RAW value is send to the client.
        WiServer.print("</H2>");
        WiServer.print("</html>");
        // URL was recognized
        return true;
    }
    // URL not found
    return false;
}


void setup() {
  // Initialize WiServer and have it use the sendMyPage function to serve pages
  WiServer.init(sendMyPage);
  
  // Enable Serial output and ask WiServer to generate log messages (optional)
  Serial.begin(57600);
  WiServer.enableVerboseMode(true);
}

void loop(){
  sensorValue = analogRead(5);  // connected to an exernal sensor via Grove interface in Grove - XBee Carrier .
  // Run WiServer
  WiServer.server_task();
 
  delay(10);
}

And the result is :

WifiBee Connected...
Sensor Value = xxx

but it is only RAW value a.k.a analog value, how to convert it to temp & humid data?