Two dht11"s , one arduino using cayenne


#1

Has anyone bin able to code two or three dht 11’s in one cayenne project ?.Ive bin able to hook up one works great! thanks


#2

Hello and Welcome to Cayenne Community.

It is the same as one, but your virtual address should be different and you of course has to initialize it as other, but on different PIN.

Here you can see how is done with dht11 / 22 and then add the logic to the cayenne dashboard :slight_smile:

http://diy-scib.org/blog/multiple-dht-humidity-sensors-arduino


#3

Would be great if you can share your code for using multiple DHT11’s when you get it up and running :slight_smile: I’m sure others in Cayenne community will have use for it.

Cheers,

~Benny


#4

I’m interested to hear what your use case is for two. The cable length for a DHT11 is limited to about 3m before you start getting issues. Either way, it’s certainly possible. Can you share what code you have so far?


#5

This is going to be used for arduino mega green house with two spaces and two seperate fan and heat supplies.This is what I have so far and IT WORKS! , The DHT1 pin is on a cable 20 ft long and does not get the same reading as the DHT2 ,on 2ft cable. I have added a part to the code( h1=h1-16.0;) to adjust the reading to match DHT2.IT WORKS ,in the arduino serial monitor .Both are have matching readings . The trouble Im having now is getting the cayenne (OUT) to read the -16.0 I have it there but must be wrong.Maybe someone can help me finish thanks

#include “DHT.h”
#define CAYENNE_DEBUG
#define DHT1PIN 2 // what pin we’re connected to
#define DHT2PIN 3
#define CAYENNE_PRINT Serial
#include <CayenneEthernet.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = “su5cik8jim”;

#define DHT1TYPE DHT11 // DHT 11
#define DHT2TYPE DHT11

DHT dht1(DHT1PIN, DHT1TYPE);
DHT dht2(DHT2PIN, DHT2TYPE);

#define VIRTUAL_TEMP1 (V0);
#define VITUAL_HUM1 (V1);
#define VIRTUAL_TEMP2 (V2);
#define VITUAL_HUM2 (V3);

void setup() {
Serial.begin(9600);
Serial.println(“DHTxx test!”);
Cayenne.begin(token);
dht1.begin();
dht2.begin();
}

void loop() {
Cayenne.run();
float h1 = dht1.readHumidity();
h1=h1-16.0;
float t1 = dht1.readTemperature(true);
float h2 = dht2.readHumidity();
float t2 = dht2.readTemperature(true);

// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t1) || isnan(h1)) {
Serial.println(“Failed to read from DHT #1”);
} else {
Serial.print(“Humidity 1: “);
Serial.print(h1);
Serial.print(” %\t”);
Serial.print(“Temperature 1: “);
Serial.print(t1);
Serial.println(” *C”);
}
if (isnan(t2) || isnan(h2)) {
Serial.println(“Failed to read from DHT #2”);
} else {
Serial.print(“Humidity 2: “);
Serial.print(h2);
Serial.print(” %\t”);
Serial.print(“Temperature 2: “);
Serial.print(t2);
Serial.println(” *C”);
}
Serial.println();
}

CAYENNE_OUT(V0)
{
Cayenne.virtualWrite(V0, dht1.readTemperature(true));
}

CAYENNE_OUT(V1)
{
Cayenne.virtualWrite(V1,(float) dht1.readHumidity( -16.0));

}

CAYENNE_OUT(V2)
{
Cayenne.virtualWrite(V2, dht2.readTemperature(true));
}

CAYENNE_OUT(V3)
{
Cayenne.virtualWrite(V3, dht2.readHumidity());
}


#6

I GOT IT ! thanks for the helpl hope someone else can use it…

#include "DHT.h"

#define CAYENNE_DEBUG
#define DHT1PIN 2 // what pin we’re connected to
#define DHT2PIN 3
#define CAYENNE_PRINT Serial
#include <CayenneEthernet.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = “su5cik8jim”;

#define DHT1TYPE DHT11 // DHT 11
#define DHT2TYPE DHT11

DHT dht1(DHT1PIN, DHT1TYPE);
DHT dht2(DHT2PIN, DHT2TYPE);

#define VIRTUAL_TEMP1 (V0);
#define VITUAL_HUM1 (V1);
#define VIRTUAL_TEMP2 (V2);
#define VITUAL_HUM2 (V3);

void setup() {
Serial.begin(9600);
Serial.println(“DHTxx test!”);
Cayenne.begin(token);
dht1.begin();
dht2.begin();
}

void loop() {
Cayenne.run();
float h1 = dht1.readHumidity();
h1=h1-16.0;
float t1 = dht1.readTemperature(true);
float h2 = dht2.readHumidity();
float t2 = dht2.readTemperature(true);

// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t1) || isnan(h1)) {
Serial.println(“Failed to read from DHT #1”);
} else {
Serial.print(“Humidity 1: “);
Serial.print(h1);
Serial.print(” %\t”);
Serial.print(“Temperature 1: “);
Serial.print(t1);
Serial.println(” *C”);
}
if (isnan(t2) || isnan(h2)) {
Serial.println(“Failed to read from DHT #2”);
} else {
Serial.print(“Humidity 2: “);
Serial.print(h2);
Serial.print(” %\t”);
Serial.print(“Temperature 2: “);
Serial.print(t2);
Serial.println(” *C”);
}
Serial.println();
}

CAYENNE_OUT(V0)
{
Cayenne.virtualWrite(V0, dht1.readTemperature(true));
}

CAYENNE_OUT(V1)
{
Cayenne.virtualWrite(V1, dht1.readHumidity()-16.0);

}

CAYENNE_OUT(V2)
{
Cayenne.virtualWrite(V2, dht2.readTemperature(true));
}

CAYENNE_OUT(V3)
{
Cayenne.virtualWrite(V3, dht2.readHumidity());
}