/*
* ESP32 ESP-IDF DHT22 Example
* Author: Tonmoy Roy
* Compatible with ESP32S3
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "esp_rom/esp_rom_sys.h" // for esp_rom_delay_us()
#define DHT_PIN 21 // Connect your DHT22 data pin here
// Simple delay in milliseconds
void delay_ms(int ms) {
vTaskDelay(pdMS_TO_TICKS(ms));
}
// Dummy function for DHT22 reading
// Replace this with actual bit-banging if needed
void dht_task(void *pvParameter) {
while (1) {
float temperature = 25.0; // Dummy temperature
float humidity = 60.0; // Dummy humidity
printf("Temperature: %.1f°C | Humidity: %.1f%%\n", temperature, humidity);
delay_ms(2000); // 2-second delay
}
}
void app_main(void) {
gpio_reset_pin(DHT_PIN);
gpio_set_direction(DHT_PIN, GPIO_MODE_INPUT_OUTPUT);
xTaskCreate(dht_task, "dht_task", 4096, NULL, 5, NULL);
}