The DHT11 sensor uses a proprietary single-wire protocol to communicate with a microcontroller. This protocol involves specific timing sequences for data transmission. Here's a detailed explanation of the DHT11 communication protocol:
Communication Sequence
Start Signal:
- The microcontroller sends a start signal to the DHT11 sensor to indicate it is ready to receive data.
- The microcontroller pulls the data line low for at least 18 milliseconds to ensure the DHT11 detects the start signal.
- The microcontroller then pulls the data line high for 20-40 microseconds.
Sensor Response:
- The DHT11 responds to the start signal by pulling the data line low for 80 microseconds.
- It then pulls the data line high for another 80 microseconds, indicating it is ready to send data.
Data Transmission:
- The DHT11 sends 40 bits of data, divided into 5 bytes. Each byte consists of 8 bits, representing:
- Integral part of the humidity.
- Decimal part of the humidity (always 0 for DHT11).
- Integral part of the temperature.
- Decimal part of the temperature (always 0 for DHT11).
- Checksum (used for error detection).
Bit Timing
Each bit starts with a 50-microsecond low signal, followed by a high signal. The length of the high signal determines whether the bit is a '0' or a '1':
- 0 Bit: 26-28 microseconds high.
- 1 Bit: 70 microseconds high.
Detailed Protocol Steps
Initialization:
Microcontroller sends a start signal:
- Pulls the data line low for at least 18 milliseconds.
- Pulls the data line high for 20-40 microseconds.
DHT11 Response:
- Pulls the data line low for 80 microseconds.
- Pulls the data line high for 80 microseconds.
Data Transmission:
For each bit (total 40 bits):
- Starts with a 50-microsecond low signal.
Followed by a high signal:
- 26-28 microseconds for a '0'.
- 70 microseconds for a '1'.
Error Checking
Checksum Calculation:
The checksum is calculated by adding the first four bytes (humidity integer, humidity decimal, temperature integer, temperature decimal) and taking the last 8 bits of the result.
The transmitted checksum must match the calculated checksum to ensure data integrity.
0 Comments