DHT22

I see no difference in DHT11 or DHT22, so i use DHT11 in the code.

I am working on my first project with a DHT11 temperature sensor.
The first example did not show the degrees n Celsius.
Also not this, 2nd.

running it i always get 0 (zero) as Celsius and 1 as humidity?

Do i have to change the code to DHT22?

https://create.arduino.cc/editor/HarvdL/b2b405ae-3410-49ad-8d31-28a84effd7ec/preview

Pls help

Your create a SIMPLEDHT11 object called dht11 but are using a reference to a dht22 object in the code. Is this the same code that gives 0 and 1??? Surprised if it actually compiled without errors.

Yes. These should be the same. Either one, but the same.

Check your wiring… Here is an example using pin 7 instead of pin 2: http://www.circuitbasics.com/how-to-set-up-the-dht11-humidity-sensor-on-an-arduino/

Maybe post a picture of your circuit? And paste your actual code directly in your reply using code tags. </>

TNX a lot,
tried it (DHT22) in the meantime and got it running.

Had problems to find my posts already done.

I am a bit like Columbus on his discovery voyage of America :slight_smile:
When he departed, he did not know where he was going to!
When he thought he had arrived , he did not know where he was!
When he returned home, he did not know where he had been !

Now I am connecting 2 of the same type of DHT22,s to the board.

Thought the easiest way was to put a line after the Serial.Print
pinDHT22 = 3

wrong.

Started to change pinDHT22 within the beginning of the loop by :
if ( int pinDHT22 <3 )
Int pinDHT22 = 3

I think the structure of my coding is totally wrong or something like that.

FYI
My intention of this project is give extra heat to my floorheating in advance because there is too much humidity to light the wood stove in the living.
exuse my poor English.

#include <SimpleDHT.h>

// for DHT22, 
//      VCC: 5V or 3V
//      GND: GND
//      DATA: 2

int pinDHT22 = 2;
SimpleDHT22 dht22;

void setup() {
  Serial.begin(9600);
}

void loop() {
  // start working...
  Serial.println("=================================");
  Serial.println("Sample DHT22...");
  
  if (pinDHT22 < 3);
      Serial.print("Pin = 2 ");
  
  
  // int pinDHT22 = 3 ;
  
  
  
  
       }
  // read without samples.
  // @remark We use read2 to get a float data, such as 10.1*C
  //    if user doesn't care about the accurate data, use read to get a byte data, such as 10*C.
  float temperature = 0;
  float humidity = 0;
  int err = SimpleDHTErrSuccess;
  if ((err = dht22.read2(pinDHT22, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
    Serial.print("Read DHT22 failed, err="); Serial.println(err);delay(2000);
    return;
  }
  
  Serial.print("Sample OK: ");
  Serial.print((float)temperature); Serial.print(" *C, ");
  Serial.print((float)humidity); Serial.println(" RH%");
  
  // DHT22 sampling rate is 0.5HZ.
  delay(5500);
  
  
}

Error:
./opt/arduino-builder/arduino-builder -compile -core-api-version 10611 -build-path /tmp/481549455/build -hardware opt/arduino-builder/hardware -hardware ./opt/cores -tools opt/arduino-builder/tools -tools ./opt/tools -built-in-libraries opt/libraries/latest -libraries /tmp/481549455/pinned -libraries /tmp/481549455/custom -fqbn arduino:avr:uno -build-cache /tmp -logger humantags -verbose=false /tmp/481549455/DHT22Default_Harry_test

/tmp/481549455/DHT22Default_Harry_test/DHT22Default_Harry_test.ino:36:3: error: expected unqualified-id before ‘if’

if ((err = dht22.read2(pinDHT22, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {

^

/tmp/481549455/DHT22Default_Harry_test/DHT22Default_Harry_test.ino:41:3: error: ‘Serial’ does not name a type

Serial.print("Sample OK: ");

^

/tmp/481549455/DHT22Default_Harry_test/DHT22Default_Harry_test.ino:42:3: error: ‘Serial’ does not name a type

Serial.print((float)temperature); Serial.print(" *C, ");

^

/tmp/481549455/DHT22Default_Harry_test/DHT22Default_Harry_test.ino:42:37: error: ‘Serial’ does not name a type

Serial.print((float)temperature); Serial.print(" *C, ");

^

/tmp/481549455/DHT22Default_Harry_test/DHT22Default_Harry_test.ino:43:3: error: ‘Serial’ does not name a type

Serial.print((float)humidity); Serial.println(" RH%");

^

/tmp/481549455/DHT22Default_Harry_test/DHT22Default_Harry_test.ino:43:34: error: ‘Serial’ does not name a type

Serial.print((float)humidity); Serial.println(" RH%");

^

/tmp/481549455/DHT22Default_Harry_test/DHT22Default_Harry_test.ino:46:8: error: expected constructor, destructor, or type conversion before ‘(’ token

delay(5500);

^

/tmp/481549455/DHT22Default_Harry_test/DHT22Default_Harry_test.ino:49:1: error: expected declaration before ‘}’ token

}

^

exit status 1

You should do something like this:
Two sensors with the simpleDHT library

HarvdL:
I am a bit like Columbus on his discovery voyage of America :slight_smile:
When he departed, he did not know where he was going to!

Yes, but he didn't leave without a compass. You need to study some C++ tutorials.

The library has an example TwoSensorsDefault sketch. Why don’t you start with that sketch if you are using two sensors?

Yes, but he didn't leave without a compass.

He also didn't get to where he thought he was going.

aarg:
Yes, but he didn't leave without a compass. You need to study some C++ tutorials.

Totally right.
I do take my lessons, also from the book.

Practice and studying aftereach other is more fun .
I think there is a lot to learn :slight_smile:

HarvdL:
Totally right.
I do take my lessons, also from the book.

Practice and studying aftereach other is more fun .
I think there is a lot to learn :slight_smile:

I'm not denying the social aspect of learning. Also experimentation. It's just that with programming you have to be willing to stop and thoroughly nail something down sometimes.

It's just that with programming you have to be willing to stop and thoroughly nail something down sometimes.

In some projects, that's like nailing Jello to the wall.

wzaggle:
The library has an example TwoSensorsDefault sketch. Why don't you start with that sketch if you are using two sensors?

Working on that now, it is for DHT11

:frowning:

No worry! Communication and wiring is same for both DHT11 and DHT22. DHT22 is just more accurate.

wzaggle:
Your create a SIMPLEDHT11 object called dht11 but are using a reference to a dht22 object in the code. Is this the same code that gives 0 and 1??? Surprised if it actually compiled without errors.

Yes. These should be the same. Either one, but the same.

Check your wiring… Here is an example using pin 7 instead of pin 2: http://www.circuitbasics.com/how-to-set-up-the-dht11-humidity-sensor-on-an-arduino/

Maybe post a picture of your circuit? And paste your actual code directly in your reply using code tags. </>

Got the “2” x DHT22 running. Just changed the 11 to 22 wherever i could find it

I am surprised :slight_smile:

Now, pfff , why do you call this "Simple"DHT ?

It is called simple because you only had to write: read(pinDHT22, &temperature, &humidity, NULL)

The other 250 lines of code to make that one work were generously provided by someone else! :slight_smile:

Thnx to all of you guys.
Appreciate your help, remarks and encouraging to this 69 year old guy :slight_smile:

I,ll start now adding some more temp. Sensors and start data logging to see what is going on.
Together w,ll nail it :slight_smile: