diff --git a/README.md b/README.md index f3d0f66..90d3076 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,168 @@ -| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 | Linux | -| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- | -------- | ----- | +# DHT11 Temperature & Humidity Sensor for ESP32-C3 -# Hello World Example +ESP-IDF project that reads temperature and humidity data from a DHT11 sensor and prints it to the serial console. -Starts a FreeRTOS task to print "Hello World". +## Overview -(See the README.md file in the upper level 'examples' directory for more information about examples.) +This project reads data from a **DHT11** digital temperature and humidity sensor using the ESP32-C3 microcontroller. It implements the DHT11 communication protocol in software, reads sensor values every 5 seconds, validates the checksum, and displays: -## How to use example +- Current date and time (derived from compile time) +- Chip information (model, cores, features, flash size, silicon revision) +- Humidity percentage with 1 decimal place +- Temperature in Celsius with 1 decimal place +- Checksum validation status -Follow detailed instructions provided specifically for this example. +## Hardware Requirements -Select the instructions depending on Espressif chip installed on your development board: +| Component | Details | +|-----------|---------| +| Microcontroller | ESP32-C3 | +| Sensor | DHT11 (AM2302) | +| Connection | Single wire + pull-up resistor | +| Data Pin | **GPIO 0** (configurable in `main/main.c`) | +| Resistor | 4.7kΩ - 10kΩ pull-up between VCC and DATA | -- [ESP32 Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/stable/get-started/index.html) -- [ESP32-S2 Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/get-started/index.html) - - -## Example folder contents - -The project **hello_world** contains one source file in C language [hello_world_main.c](main/hello_world_main.c). The file is located in folder [main](main). - -ESP-IDF projects are built using CMake. The project build configuration is contained in `CMakeLists.txt` files that provide set of directives and instructions describing the project's source files and targets (executable, library, or both). - -Below is short explanation of remaining files in the project folder. +### Wiring Diagram ``` -├── CMakeLists.txt -├── pytest.py Python script used for automated testing -├── main -│ ├── CMakeLists.txt -│ └── hello_world_main.c -└── README.md This is the file you are currently reading +DHT11 ESP32-C3 + VCC ------ 3V3 + DATA ----- GPIO0 + GND ------ GND ``` -For more information on structure and contents of ESP-IDF projects, please refer to Section [Build System](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html) of the ESP-IDF Programming Guide. +Add a **4.7kΩ pull-up resistor** between VCC and DATA pin. + +## Supported Targets + +| ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 | +| ----- | -------- | -------- | -------- | -------- | +| ❌ | ❌ | ✅ | ❌ | ❌ | + +## Project Structure + +``` +dht11_reader/ +├── CMakeLists.txt # Project configuration +├── sdkconfig # Build configuration +├── main/ +│ ├── CMakeLists.txt # Main component configuration +│ └── main.c # Application source code +└── README.md # This file +``` + +## Setup & Build + +### Prerequisites + +- [ESP-IDF v6.0](https://docs.espressif.com/projects/esp-idf/en/v6.0/esp32c3/get-started/index.html) +- RISC-V toolchain (riscv32-esp-elf) +- Python 3.13+ with virtual environment + +### Build Instructions + +```bash +# Activate ESP-IDF environment +source "$HOME/.espressif/tools/activate_idf_v6.0.sh" + +# Navigate to project +cd temperature_measure + +# Build the project +idf.py build + +# Flash to device (replace PORT with your serial port) +idf.py -p /dev/ttyUSB0 flash monitor +``` + +## Configuration + +The DHT11 data pin is defined in `main/main.c`: +```c +#define DHT11_GPIO 0 +``` + +To use a different GPIO, change this define and rebuild. + +### Reading Interval + +The sensor is read every 5 seconds: +```c +vTaskDelay(pdMS_TO_TICKS(5000)); +``` + +Note: DHT11 requires at least 1 second between readings. Adjust as needed. + +## How It Works + +### DHT11 Communication Protocol + +1. **Start Signal**: MCU pulls DATA line low for 20ms, then high +2. **Sensor Response**: DHT11 pulls line low for ~80μs, then high for ~80μs +3. **Data Transmission**: 40 bits of data (5 bytes) in the following format: + - Byte 0: Humidity integer part + - Byte 1: Humidity decimal part + - Byte 2: Temperature integer part + - Byte 3: Temperature decimal part + - Byte 4: Checksum (sum of bytes 0-3) + +4. **Bit Encoding**: Each bit starts with a ~50μs low pulse: + - `0`: ~26-28μs high pulse + - `1`: ~70μs high pulse + +### Checksum Validation + +The checksum byte should equal the sum of the first 4 data bytes. If validation fails, the reading is retried after 1 second. + +## Output Example + +``` +Time: 2024-04-24 22:30:00 +This is esp32c3 chip with 1 CPU core(s), WiFi/BLE, silicon revision v0.4, 4MB embedded flash +Minimum free heap size: 283488 bytes +Humidity: 45.2% +Temperature: 23.5°C +Checksum valid: Yes +``` ## Troubleshooting -* Program upload failure +### Common Issues - * Hardware connection is not correct: run `idf.py -p PORT monitor`, and reboot your board to see if there are any output logs. - * The baud rate for downloading is too high: lower your baud rate in the `menuconfig` menu, and try again. +| Issue | Solution | +|-------|----------| +| No sensor readings / checksum fails | Check wiring: DATA to GPIO0, pull-up resistor present | +| Build fails with missing component | Run `idf.py fullclean` then rebuild | +| `driver/gpio.h` not found | Ensure `esp_driver_gpio` is in PRIV_REQUIRES | +| Linker errors with `.riscv.attributes` | Your toolchain may be too new; use ESP-IDF 6.0 compatible version | -## Technical support and feedback +### Debug Mode -Please use the following feedback channels: +To enable debug output: +```bash +idf.py monitor +``` -* For technical queries, go to the [esp32.com](https://esp32.com/) forum -* For a feature request or bug report, create a [GitHub issue](https://github.com/espressif/esp-idf/issues) +### Hardware Connection Check -We will get back to you as soon as possible. +Verify your wiring with a multimeter: +- GPIO0 should read HIGH when idle (via pull-up) +- 3V3 is supplying power +- GND is properly connected + +## Technical Details + +- **Sensor Range**: 0-50°C temperature, 20-90% humidity +- **Accuracy**: ±1°C temperature, ±1% humidity +- **Sampling Rate**: 1Hz maximum (1 reading per second) +- **Resolution**: 1° C, 1% humidity + +## License + +This project is provided under the **CC0-1.0** license (public domain). See the SPDX identifier in the source file. + +## Resources + +- [DHT11 Datasheet](https://www.mouser.com/datasheet/2/718/DHT11-Technical-Data-Sheet-Translated-Version-1137654.pdf) +- [ESP32-C3 Documentation](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/) +- [ESP-IDF Programming Guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/api-guides/index.html)