Go Down

Topic: Class for DHT11, DHT21 and DHT22 (temperature & humidity) (Read 62 times) previous topic - next topic

robtillaart

Its under Humidity

    * DHT_lib One library that supports both DHT11 and DHT 22   <<<<<<<<<<<<<<<<<< that one

This is the direct URL - http://arduino.cc/playground/Main/DHTLib

Don't know if mine is the best, best is a subjective term at best (oops recursion) and it allways depends on the project context what is the best match.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

cbiale

Ustedes usan la linea de datos conectada directamente a un puerto?. And not use a resistor entre la linea de datos y Vcc.

robtillaart

Quote
Ustedes usan la linea de datos conectada directamente a un puerto?. And not use a resistor entre la linea de datos y Vcc.
You use the data line connected directly to a port?. And not use a resistor between the Vcc and data line.


No I did not use a resistor between the data line and the Vcc. But in my project the lines were very short. If your lines are longer you could try a 4K7 resistor (similar to I2C).

Regards,
Rob
Translation by Google translate


No, no hizo uso de una resistencia entre la línea de datos y la Vcc. Pero en mi proyecto de las líneas eran muy cortos. Si las líneas son más largas que podría tratar de una resistencia de 4K7 (similar a I2C).

Saludos,
robar
Traducción de Google Translate
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Static

#13
Sep 03, 2011, 10:57 pm Last Edit: Sep 06, 2011, 04:01 pm by Static Reason: 1
I'm trying to build a simple sensor upload to Pachube.  I've been troubleshooting this for awhile, and it seems that the problem is with the DHT22 readings, not with the push to Pachube.
I'm reading the data from the DHT22 correctly:

Quote
+++++++++++++++++++++++++++++++++++++++++++++++++
OK,   47.2,   26.0
sync status code <OK == 200> => 200
data count=> 4
<id>,<value>
0,654
1,712
2,1
3,1

That's my serial output.
The line after the "+"s is the checksum and humidity and temperature read from the DHT22.  The two lines below that are link messages regarding my connection to Pachube.  The final 5 lines deal with the data being sent to Pachube.  The first two pieces (0 and 1) of data are analog reads from a light sensor and a motion sensor connected to analog lines.  The two items following that (2,3) are the temperature and humidity reads from the DHT22.
I can read the DHT22 in the first portion of my code.  I cannot read them in the second portion of my code.  Why?
I've tried various methods of placing the initial DHT22 data into variables, and printing those variables.  Inevitably the serial monitor prints out a "1" when it is trying to send the data feed to Pachube.

Am I wrong?  Am I attacking this the wrong way, and instead should be looking at the Pachube end of things?


Code: [Select]
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
*  Sensors:  DHT22 dataline connected to pin 7.  Suggested 4.7k Pull-up used
             Analog Pin 0 is a photocell to detect light levels
             Analog Pin 1 is a motion sensor

* Based on code:
* Created 22 April 2011
* By Jeffrey Sun
* http://code.google.com/p/pachubelibrary/
* and
* robtillart
* http://arduino.cc/forum/index.php/topic,58531.0.html
* http://arduino.cc/playground/Main/DHTLib

*/
#include <dht.h>
#include "ERxPachube.h"
#include <Ethernet.h>
#include <SPI.h>

dht DHT;
#define DHT22_PIN 7
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x21, 0xE3 };
byte ip[] = { 192, 168, 1, 20   };                  // no DHCP so we set our own IP address

int Temp;
int Humidity;
int OldTemp = Temp;
int OldHumidity = Humidity;

#define PACHUBE_API_KEY "PACHUBE API KEY" // fill in your API key PACHUBE_API_KEY
#define PACHUBE_FEED_ID 34665 // fill in your feed id

ERxPachubeDataOut dataout(PACHUBE_API_KEY, PACHUBE_FEED_ID);

void PrintDataStream(const ERxPachube& pachube);

void setup() {

Serial.begin(9600);
Ethernet.begin(mac, ip);

dataout.addData(0);
dataout.addData(1);
dataout.addData(2);
       dataout.addData(3);
}

void loop() {

Serial.println("+++++++++++++++++++++++++++++++++++++++++++++++++");
float fSensorData = 15.23;
       int chk = DHT.read22(DHT22_PIN);
       switch (chk)
       {
         case 0:  Serial.print("OK,\t"); break;
         case -1: Serial.print("Checksum error,\t"); break;
         case -2: Serial.print("Time out error,\t"); break;
         default: Serial.print("Unknown error,\t"); break;
         }
       // DISPLAY DATA
       Temp = (DHT.temperature, 1);
       Humidity = (DHT.humidity, 1);
       //Serial.print(Temp);
       //Serial.print(",\t");
       //Serial.println(Humidity);
       Serial.print(DHT.humidity, 1);
       Serial.print(",\t");
       Serial.println(DHT.temperature, 1);
dataout.updateData(0, analogRead(0));
dataout.updateData(1, analogRead(1));
dataout.updateData(2, (DHT.temperature,1));
       dataout.updateData(3, (DHT.humidity,1));
int status = dataout.updatePachube();

Serial.print("sync status code <OK == 200> => ");
Serial.println(status);

PrintDataStream(dataout);
       OldTemp = Temp;
       OldHumidity = Humidity;
delay(30000);
}

void PrintDataStream(const ERxPachube& pachube)
{
unsigned int count = pachube.countDatastreams();
Serial.print("data count=> ");
Serial.println(count);

Serial.println("<id>,<value>");
for(unsigned int i = 0; i < count; i++)
{
Serial.print(pachube.getIdByIndex(i));
Serial.print(",");
Serial.print(pachube.getValueByIndex(i));
Serial.println();
}
}

Static

Possibly related, maybe not:
I'm getting a fair number of checksum errors (Approximately 1 in 10).  Is there a way to reduce that number?  Any suggestions?

Go Up