Skip to main content
Associate II
July 8, 2025
Question

interfacing DHT22 sensor with stm32f411re

  • July 8, 2025
  • 6 replies
  • 1053 views

I am trying to interface DHT22 sensor with STM32F411RE board. When initially I interfaced I was able to see data (i.e., Temp and Humidity) I am giving 3.3v power supply, data pin connected to PA0 ground and set clock frequency to 50MHZ using Internal oscillator. But when now I am trying to check values, I am not able to get values I haven't change anything in code still I am facing this issue. The code is stuck in while loop of DHT22_response function where it is waiting for pin to be low. I have attached coding file please can anyone help me regarding this??

6 replies

Technical Moderator
July 8, 2025

Hello @Reva1605,

Have you tried connecting a pull-up resistor to the data line? Without it, the DHT11 may not be able to pull the line HIGH.

Best regards,

To improve visibility of answered topics, please click 'Accept as Solution' on the reply that resolved your issue or answered your question.
Reva1605Author
Associate II
July 8, 2025

Yes tried connecting pull-up resistor of value 4.7k still not working

Technical Moderator
July 8, 2025

So, to understand correctly, you created a project and added the functions to interface with the DHT22 sensor. Initially, it worked, but after rebuilding and testing the project again, it got stuck in the DHT22_response function? Have you tried supplying 5V to the sensor or using a different GPIO pin instead of the wakeup pin PA0?

To improve visibility of answered topics, please click 'Accept as Solution' on the reply that resolved your issue or answered your question.
Reva1605Author
Associate II
July 9, 2025

I have tried supplying 5v to sensor. I haven't tried using different GPIO pin I will try that once.

Reva1605Author
Associate II
July 10, 2025

I tried using different pin but still it is not working

Andrew Neil
Super User
July 8, 2025

Welcome to the forum.

Please see How to write your question to maximize your chances to find a solution for best results.

In particular, please describe:

  • What board you are using
  • Show schematic of how the DHT22 is connected
  • Show some good, clear photos of your setup
  • Describe what testing/investigation/debugging you've done so far;
    eg, have you looked at the signal line on an oscilloscope?

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Reva1605Author
Associate II
July 9, 2025

As mentioned, I am using STM32F411RE board and interfacing DHT22 sensor. So previously I was testing dht22 sensor with 3.3v power supply I was giving me correct values of humidity and temperature but now when I am trying get values it is stuck in DHT22_response () .
About setup it is just simple connection between stm32 board and dht22 sensor.IMG20250709092058.jpg

KnarfB
Super User
July 9, 2025

The following worked here with a DHT11:

int main(void)
{
 __HAL_RCC_GPIOA_CLK_ENABLE();

 GPIO_InitTypeDef GPIO_InitStruct;

 GPIO_InitStruct.Pin = DHT11_DAT_PIN;
 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
 GPIO_InitStruct.Pull = GPIO_PULLUP;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 HAL_GPIO_Init(DHT11_DAT_PORT, &GPIO_InitStruct);

 HAL_GPIO_WritePin( DHT11_DAT_PORT, DHT11_DAT_PIN, GPIO_PIN_SET);
 delay_us(1000*1000); 	// wait after power on

 for(;;) {
 HAL_GPIO_WritePin( DHT11_DAT_PORT, DHT11_DAT_PIN, GPIO_PIN_RESET);
 delay_us(20*1000);		// wait >18ms
 HAL_GPIO_WritePin( DHT11_DAT_PORT, DHT11_DAT_PIN, GPIO_PIN_SET);
 ReadDHT11();
 delay_us(2*1000*1000); 	// wait 2s for next reading
 }
}

 Differences:

- the pin is never pushed high

- the pin is read while in output mode  

- give it time to start-up after power-on

hth

KnarfB

Reva1605Author
Associate II
July 9, 2025

I am using DHT22 so will it work with my sensor?

KnarfB
Super User
July 9, 2025

The translated english data sheets show pretty much the same diagrams, copied from the chinese originals. There are some differences in electrical and environmental conditions: Overview | DHT11, DHT22 and AM2302 Sensors | Adafruit Learning System

As theres are quite old parts, there are dozends of tutorials around...

hth

KnarfB