DHT22 Temperature/Humidity sensor ladyada DHT22 Library: How to slow it down

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
DennyP
 
Posts: 5
Joined: Sat May 18, 2013 6:41 am

DHT22 Temperature/Humidity sensor ladyada DHT22 Library: How to slow it down

Post by DennyP »

Hello all,

I'm currently using the library http://learn.adafruit.com/dht for my DHT22 and I'm using a Adrunio Uno.
The sketch is working, providing me with data every 250 milliseconds (according to the code).

However I want to increase this to a second/1000 milliseconds.

How can I do this? I was thinking using a delay code (don't know where to put it), or editing the Dht.h file that came with it.

The code is as follows:

Code: Select all

// 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)

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(38400);
  Serial.println("LABEL,Time,Temperature (C), Humidity (%)");  

  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("DATA,TIME,"); Serial.print(t); Serial.print(","); Serial.println(h);
  }
}
Cheers,
Dennis

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

Re: DHT22 Temperature/Humidity sensor ladyada DHT22 Library: How to slow it down

Post by adafruit_support_bill »

The simplest way is to add a "delay(750);" anywhere in the loop.

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

Return to “Arduino”