Humidity DHT11 Example

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
ggoetz56
Posts: 17
Joined: 26 Oct 2016 10:39

Humidity DHT11 Example

Post by ggoetz56 »

Hi, (already posted this in German Section- without response)

I need 2 humidity-sensor with my Fibaro HomeCenter 2 (HC2). So I found the "Humidity and temperature sensor DHT11" example. But this won't work for me and my HDT22.

I believe the wire diagram isn't correct. I connected pin 9 on z-uno with pin 2 on DHT; Pin 3 left empty for correct function. Maybe you will change the diagramm.

So I need another Humiditysensor my quest:
Will I be able to have 2 Sensor on one board (lets say connected with pin 10).
Whats about the sketch. # define dhtPin2 10 seems ok, but zunoSendReport(3) will be the wrong statement.

So I'm not the electronic-crack I need someone to show me the details. If it is too complicated please tell me, I would cancel it.

Thank you
Gerhard
micky1500
Posts: 300
Joined: 07 Feb 2016 16:29
Location: England

Re: Humidity DHT11 Example

Post by micky1500 »

It works ok with One DHT11. was an easy example.
I bought a bundle of 5 DHT11's. Will try a second on a different pin.
But could be a couple of days before I find the time. incase anyone else knows a quick fix.

Micky.
Raspi 4 - (Buster - 32 Bit) Zwave Version 4.1.4, Raz 7 Pro, Serial API Version: 07.42
mdietinger@gmail.com
Posts: 39
Joined: 12 Aug 2016 12:08

Re: Humidity DHT11 Example

Post by mdietinger@gmail.com »

Micky,

issue is that the Fritzing schematics show PIN 3 as data Pin.
Datasheet and Gerhards experience use PIN 2 : http://www.micropik.com/PDF/dht11.pdf

Z-UNO team:
Not a big issue, but drawing should be corrected, or in case there are different versions with different pinout a remark would be required to check specs before connecting.
Gerhard already got answer on how to connect 1+ sensors in another forum.
I am currently testing HYT221 and working well with the corrected wire implementation.
Do some more testing and will post an example code in a view days.
Quite a pricy sensor but +/- 1.8% for humidity.


regards,

Markus
michap
Posts: 442
Joined: 26 Mar 2013 10:35
Contact:

Re: Humidity DHT11 Example

Post by michap »

mdietinger@gmail.com wrote: Gerhard already got answer on how to connect 1+ sensors in another forum.
Not very helpful for other users, who is looking for that solution ;)

That's why I added a tested and working code for all, who need 2 DHT sensors.

I have used PIN 11 and 12 - because of I like free pin 9/10 for additional I²C devices and do not want to "block" it.

This sketch show that you can use multiple sensors, change the PIN numbers (you can use the PIN 9/10 also - like in original sample).

I would suggest to use DHT22/AM2302 because of better data:
DHT11:
Good for 20-80% humidity readings with 5% accuracy
Good for 0-50°C temperature readings ±2°C accuracy

DHT22:

Good for 0-100% humidity readings with 2-5% accuracy
Good for -40 to 125°C temperature readings ±0.5°C accuracy

Additional - you can connect it to 3.3V (no needs to connect it to 5V like in original example)
If you connect to 5V - please do not forget to use a level shifter (as sample simple voltage divider with 2 resistors)

I hope the code help to understand the principle:

Code: Select all

// add library
#include "ZUNO_DHT.h"
// pin connection
#define DHTPIN1 11  // first sensor
#define DHTPIN2 12  // second sensor
 
DHT dht1(DHTPIN1, DHT22);  // use "DHT11" instead of "DHT22" for DHT11 sensor
DHT dht2(DHTPIN2, DHT22);
 
int humidity1;      // here we will store the humidity of first sensor
//float temperature1;   // here we will store the temperature of first sensor  
int temperature1;   // here we will store the temperature of first sensor  
int humidity2;      // here we will store the humidity of second sensor
//float temperature2;   // here we will store the temperature of second sensor  
int temperature2;   // here we will store the temperature of second sensor  

// for float values (decimals) sketch must be modified - see example with DS18B20
// http://z-uno.z-wave.me/examples/1-wire-ds18b20-temperature-sensor/
 
// set up channels
ZUNO_SETUP_CHANNELS(
      ZUNO_SENSOR_MULTILEVEL_TEMPERATURE(getterTemperature1),
      ZUNO_SENSOR_MULTILEVEL_HUMIDITY(getterHumidity1),
      ZUNO_SENSOR_MULTILEVEL_TEMPERATURE(getterTemperature2),
      ZUNO_SENSOR_MULTILEVEL_HUMIDITY(getterHumidity2)
);
 
void setup() {
  dht1.begin();
  dht2.begin();
  Serial.begin(); 
  Serial.println("start");
}
 
void loop() {
  // obtaining readings from the sensor DHT
  humidity1 = dht1.readHumidity();
  temperature1 = dht1.readTemperature();
  humidity2 = dht2.readHumidity();
  temperature2 = dht2.readTemperature();
  Serial.print("Humidity = "); 
  Serial.print(humidity1);
  Serial.println(" %  ");
  Serial.print("Humidity = "); 
  Serial.print(humidity2);
  Serial.println(" %  ");
  Serial.print("Temperature = "); 
  Serial.print(temperature1);
  Serial.println(" *C");
  Serial.print("Temperature = "); 
  Serial.print(temperature2);
  Serial.println(" *C");
  // send data to channels
  zunoSendReport(1);
  zunoSendReport(2); 
  zunoSendReport(3); 
  zunoSendReport(4); 
  // send every 30 second
  delay(30000);
}
 
byte getterTemperature1() {
  return temperature1;
}
 
byte getterHumidity1() {
  return humidity1;
}
byte getterTemperature2() {
  return temperature2;
}
 
byte getterHumidity2() {
  return humidity2;
}
Michael
michap
Posts: 442
Joined: 26 Mar 2013 10:35
Contact:

Re: Humidity DHT11 Example

Post by michap »

changed code a little bit
- "float" for temperature values with decimals (not int)
- added comment for DHT11 usage

Michael
ggoetz56
Posts: 17
Joined: 26 Oct 2016 10:39

Re: Humidity DHT11 Example

Post by ggoetz56 »

Thank you Mike for your explanation.
Now I know DHT22 is not a I2C-Device and only z-uno Pin 9 and 10 are able to manage such devices.

I will test the sketch
Thank you.
ggoetz56
Posts: 17
Joined: 26 Oct 2016 10:39

Re: Humidity DHT11 Example

Post by ggoetz56 »

First of all: the sketch works "as it is" for me.
Thank you Michael

Did some adoption:
Set Z-uno to sleep mode. Sending values every 15 min.
To minimize failure I will write 10 values to an array cut the highest and lowest value and sent the average to z-wave server.

Did anybody have a "arraysort()" for me?
mdietinger@gmail.com
Posts: 39
Joined: 12 Aug 2016 12:08

Re: Humidity DHT11 Example

Post by mdietinger@gmail.com »

michap wrote:changed code a little bit
- "float" for temperature values with decimals (not int)
- added comment for DHT11 usage

Michael
Michap, your example will not report temperature values with decimal to the main controller.
See exact definition how to make sensor to report with required precission: http://z-uno.z-wave.me/Reference/ZUNO_S ... ULTILEVEL/
Working implementation you can find on my HYT221 example. (Size 2 & precision 1 requires to multiply measured value by 10)
michap
Posts: 442
Joined: 26 Mar 2013 10:35
Contact:

Re: Humidity DHT11 Example

Post by michap »

mdietinger@gmail.com wrote:example will not report temperature values with decimal to the main controller
Right, thanks.
I forgot to modify the rest of the sketch after changing temp to float - changed it back and added comment.

Michael
Chiquitoloco
Posts: 17
Joined: 11 Sep 2016 11:26

Re: Humidity DHT11 Example

Post by Chiquitoloco »

Hi,

i'm trying to use a DHT22 with the library but i got this error :

Code: Select all

In file included from dht22.cpp:13:0:
C:\Program Files (x86)\Arduino\libraries\ZUNO_DHTlib/ZUNO_DHT.h:36:14: error: expected ')' before 'pin'
    DHT(s_pin pin, uint8_t type = DHT22);
              ^
C:\Program Files (x86)\Arduino\libraries\ZUNO_DHTlib/ZUNO_DHT.h:57:3: error: 's_pin' does not name a type
   s_pin _pin;
   ^
dht22.cpp: In function 'void getTempHum(unsigned char, unsigned char)':
dht22.cpp:31: error: no matching function for call to 'DHT::DHT(unsigned char&, unsigned char&)'
 DHT dht(DHTPIN, DHTTYPE);
                        ^
dht22.cpp:31:24: note: candidates are:
In file included from dht22.cpp:13:0:
C:\Program Files (x86)\Arduino\libraries\ZUNO_DHTlib/ZUNO_DHT.h:34:7: note: DHT::DHT()
 class DHT {
       ^
C:\Program Files (x86)\Arduino\libraries\ZUNO_DHTlib/ZUNO_DHT.h:34:7: note:   candidate expects 0 arguments, 2 provided
C:\Program Files (x86)\Arduino\libraries\ZUNO_DHTlib/ZUNO_DHT.h:34:7: note: DHT::DHT(const DHT&)
C:\Program Files (x86)\Arduino\libraries\ZUNO_DHTlib/ZUNO_DHT.h:34:7: note:   candidate expects 1 argument, 2 provided
no matching function for call to 'DHT::DHT(unsigned char&, unsigned char&)'
Someone have an idea?

thx
Post Reply