DHT sensor connection

I connected a HT sensor AM2301 to a Nano 33 IoT but the values returned are always wrong.
I correctly connect the 3V3 pin, the GND pin and the DATA pin but the values returned from the sensor are wrong (temp: -3275.1, humy: 49.9). Blowing on the sensor these values change (remaining wrong) so I think the sensor is anyway good.
I use another, identical sensor but the result remains the same.
The software part is correct but I'm not sure about the wires connection. Some online examples report the use of a 10K resitor between VCC and DATA pins.
What am I doing wrong?

The sensor red wire (VCC) in connected with Arduino 3V3 pin
The sensor black wire (GND) in connected with Arduino GND pin
The sensor yellow wire (DATA) in connected with Arduino D6 pin (digital GPIO

  • Always show us a good schematic of your proposed circuit.
    Show us good images of your ‘actual’ wiring.
    Give links to components.
1 Like

I'll echo what Larry says

and dont assume we keep data sheets in our heads, so please post links

1 Like

Humidity is in the normal range, but the temp looks very wrong, maybe a bad sensor. Of course without a wiring diagram and code it's difficult to know.

1 Like

Despite you being sure that "the software part is correct", until you show us the sketch, there's no way we can know that.

1 Like

@michelallara ,

Your other topic on the same subject deleted.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

1 Like

I didn't want to duplicate the post. I would have liked to write a new, updated one and delete the old one but I can't delete my posts (and I really don't understand why). I wrote my first post and everyone told me I needed to put more information. Well, I put them on but no one seems to have noticed.

The sketch is correct, believe me (it's not the first I wrote). :wink:

I've written hundreds if not thousands of programs over the years. And I still make mistakes. If you think you don't, you're just kidding yourself. Good luck and good bye.

1 Like

You didn't need a new topic, you just needed to add the required information in this one.

The forum is a free service provided by Arduino and supported by volunteers working for free. The forum rule is that topics and posts cannot usually be deleted, with the exception of spam and abuse. The reason is that once a volunteer has offered help then deleting your topic wastes the time of the volunteers trying to help. Also, the forum provides a resource for others seeking answers to similar questions already asked and answered.

1 Like

It was only to say that my question is about the wire connection and the usage of a 10K resistor. Anyway thank you.

I don't know the solution but if you just want to know about a 10k resistor then I suggest you try it. I doubt connecting a 10k resistor will damage anything. If it doesn't solve the problem then to get help you will need to provide the requested information.

According to the AM2301 datasheet, the manufacturers suggest a pullup resistor of around 5.1kΩ.
See page 5 for further details.

1 Like

I used a 10K resitor and a 5K6 resitor but nothing seems to work.
One thing remains: the voltage.
The sensor documentation reports that its voltage can be from 3V3 to 5V but the 5V is preferred.
Arduino Nano 33 IoT use 3V3 as output voltage and I'm using that.
I will try to feed the sensor with 5V.

If you do this, you will need to verify that the data out does not go to 5v along with the supply.

You may need a voltage divider as the The Nano33 IOT is not 5v tolerant.

1 Like

Where is the code? What library did you use (the device is a DHT21)? Was the library old? Was the library a 4-pin library or a 3-pin library? So many questions.

I know, thank you. :+1:

I tried different libraries (dht, DHT, DHTNew, simpleDHT), getting always the same, identical result, the same values from the sensor (I tried 2 sensors and 2 arduino). That's why my question is about the connection of the sensor and not about the code (very simple and easy).

Anyway, here one of the implementations tried:

#include "DHT.h"

#define DHT_PIN 6
#define DHT_TYPE DHT21   // AM2301 

DHT dht(DHT_PIN, DHT_TYPE);

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

void loop() 
{
 float h = dht.readHumidity();
 float t = dht.readTemperature();

 if (isnan(t) || isnan(h)) 
 {
   Serial.println("Failed to read from DHT");
 } 
 else 
 {
   Serial.print("Humidity: "); 
   Serial.print(h);
   Serial.print(" %\t");
   Serial.print("Temperature: "); 
   Serial.print(t);
   Serial.println(" *C");
   delay(2000);
 }
}

I'm the writer of the DHTnew library and some other DHTlibraries too.

For 3V3 boards I would advice a 3K3 or even 2K2 resistor
if the wire is longer than ~25 cm = 10"

Can you run the sketch dhtnew_pulse_diag.ino and post the output?
(5 dumps ~ 30 seconds is sufficient)

It does check dump the low level timing of the sensor.

1 Like

********** Here's the output with a 4K6 resitor **********

dhtnew_pulse_diag.ino

awake 2 3 4 2
1
5 6 7

RUN: 1
IDX: 89
WAKEUP
1126 4 17 243 3 132
HUM
3 17 48 32 49 29 52 29 51 29 49 74 52 70 52 69
52 71 48 71 52 29 52 29 48 71 49 74 51 71 52 70

TEMP
52 70 49 70 52 71 48 71 52 67 52 74 48 74 49 71
51 71 50 30 51 71 48 71 52 67 52 74 49 74 48 74

CRC
49 70 52 29 51 29 49 32
49 70 49 29 55 5917 4 467

BYE
125 2

awake 2 3 4 6
5
4
3
2
1
5 6 7

RUN: 2
IDX: 89
WAKEUP
1128 4 17 396 4 272
HUM
12 30 51 74 49 72 52 71 48 74 49 71 51 29 49 32
49 70 49 74 51 71 52 70 51 71 52 70 49 71 55 64

TEMP
52 70 49 74 52 70 52 70 52 70 49 32 49 70 52 71
48 71 49 74 51 71 52 70 51 71 48 32 49 32 48 30

CRC
51 71 48 30 54 6216 3 443
3 468 3 523 3 494 3 762

BYE
210 2

awake 2 3 4 4
3
2
1
5 6 7

RUN: 3
IDX: 89
WAKEUP
1128 4 16 255 3 244
HUM
23 32 48 29 52 29 52 74 48 73 49 71 51 71 52 71
48 29 52 29 51 68 52 74 48 74 49 72 49 74 48 71

TEMP
52 70 49 71 51 68 52 74 48 74 48 73 49 70 52 71
51 30 48 29 52 29 52 32 48 74 49 71 51 71 54 25

CRC
52 29 52 29 48 71 52 67
55 6118 3 472 3 502 4 694

BYE
169 2

awake 2 3 4 4
3
2
1
5 6 7

RUN: 4
IDX: 89
WAKEUP
1126 4 26 281 24 192
HUM
22 29 49 29 50 29 52 74 48 74 49 74 48 71 52 70
49 32 49 29 51 71 49 72 52 71 51 71 52 71 48 71

TEMP
52 70 49 71 51 68 51 73 52 71 51 71 49 74 51 68
52 29 48 29 52 29 52 32 48 74 48 74 49 71 51 29

CRC
52 29 48 36 45 71 49 67
55 6127 3 468 3 496 3 748

BYE
258 2

awake 2 3 4 3
2
1
5 6 7

RUN: 5
IDX: 89
WAKEUP
1128 4 19 196 34 189
HUM
23 32 48 30 51 29 52 29 48 74 52 70 51 71 52 71
48 71 51 30 51 29 49 71 51 74 49 74 47 74 49 70

TEMP
52 71 48 71 52 71 48 71 48 74 52 71 51 70 52 70
52 71 48 29 52 29 52 29 48 36 48 71 52 71 51 71

CRC
51 29 49 32 48 29 52 71
48 68 55 6041 3 467 4 758

BYE
239 2

********** Here's the output without any resistor **********

dhtnew_pulse_diag.ino

awake 2 3 4 1
5 6 7

RUN: 1
IDX: 89
WAKEUP
1126 4 18 160 3 78
HUM
45 29 51 30 51 31 49 29 51 30 51 29 49 32 52 32
48 33 48 32 49 32 49 70 52 29 49 70 51 32 52 29

TEMP
51 30 51 29 52 29 52 29 51 30 48 29 52 32 52 29
51 30 51 29 54 26 51 71 49 32 48 71 49 35 49 32

CRC
48 33 48 32 49 71 51 29
52 73 45 32 49 26 55 6776

BYE
171 2

awake 2 3 4 3
2
1
5 6 7

RUN: 2
IDX: 89
WAKEUP
1126 4 22 208 21 190
HUM
23 29 51 29 52 29 51 29 49 74 51 71 48 74 49 71
51 71 49 32 48 29 52 71 55 66 52 71 51 71 52 70

TEMP
49 71 51 71 49 70 49 71 51 73 52 70 49 74 48 71
52 29 51 71 49 71 51 29 49 74 51 70 52 70 52 71

CRC
48 29 52 29 52 29 48 29
52 26 55 6042 4 440 3 368

BYE
119 2

awake 2 3 4 3
2
1
5 6 7

RUN: 3
IDX: 89
WAKEUP
1126 4 16 239 3 182
HUM
22 33 48 29 52 29 52 29 48 74 51 70 52 71 51 71
49 71 51 29 52 29 48 71 52 74 48 73 48 75 48 71

TEMP
51 71 49 70 52 71 48 71 49 74 51 71 51 71 51 71
49 32 48 71 52 71 48 29 52 74 48 74 49 71 50 71

CRC
51 29 52 29 49 32 48 29
52 26 55 6048 3 458 3 363

BYE
131 2

awake 2 3 4 4
3
2
1
5 6 7

RUN: 4
IDX: 89
WAKEUP
1126 4 16 287 28 211
HUM
3 29 49 29 51 29 49 74 52 70 52 71 48 74 49 70
52 29 49 32 50 68 52 74 48 74 48 71 52 71 51 71

TEMP
49 70 52 68 58 63 51 71 52 71 51 71 52 71 48 32
49 71 51 68 51 30 53 71 49 74 48 71 52 71 51 29

CRC
49 32 48 30 51 29 49 29
55 6147 4 297 4 229 3 361

BYE
137 2

awake 2 3 4 3
2
1
5 6 7

RUN: 5
IDX: 89
WAKEUP
1126 4 16 199 35 197
HUM
16 29 52 29 51 30 48 29 52 72 52 71 48 74 49 71
51 71 48 30 51 29 52 68 51 74 50 71 52 71 48 71

TEMP
52 71 48 71 51 71 49 70 49 74 52 69 52 71 51 71
49 32 48 71 52 67 52 29 48 74 52 71 52 69 52 71

CRC
48 32 49 32 49 29 51 29
49 29 55 6053 3 438 3 477

BYE
151 2