You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"DHT 11 Sensor - Temperature: {} °C, humidity: {} %",
50
54
sensor_reading.temperature,
51
55
sensor_reading.humidity
52
56
),
53
57
Err(error) =>log::error!("An error occurred while trying to read sensor: {:?}", error),
54
58
}
59
+
60
+
matchdht22.read() {
61
+
Ok(sensor_reading) =>log::info!(
62
+
"DHT 22 Sensor - Temperature: {} °C, humidity: {} %",
63
+
sensor_reading.temperature,
64
+
sensor_reading.humidity
65
+
),
66
+
Err(error) =>log::error!("An error occurred while trying to read sensor: {:?}", error),
67
+
}
68
+
69
+
log::info!("-----");
55
70
}
56
71
}
57
72
```
58
73
59
-

74
+

60
75
61
76
62
77
## Implementation Specification
@@ -68,30 +83,43 @@ We have gathered all the information you need to understand in order to implemen
68
83
69
84
### Step 1
70
85
71
-
After powering on the DHT11 (once powered, allow 1 second to pass during which the sensor stabilizes; during this time, no commands should be sent), it measures the temperature and humidity of the surrounding environment and stores the data. Meanwhile, the DATA line of the DHT11 is kept high by a pull-up resistor. The DATA pin of the DHT11 is in input mode, ready to detect any external signals.
86
+
After powering on the DHT11/DHT22 (once powered, allow 1 second to pass during which the sensor stabilizes; during this time, no commands should be sent), it measures the temperature and humidity of the surrounding environment and stores the data. Meanwhile, the DATA line of the DHT11/DHT22 is kept high by a pull-up resistor. The DATA pin of the DHT11/DHT22 is in input mode, ready to detect any external signals.
72
87
73
88
### Step 2
74
89
75
-
The microprocessor's I/O pin is set to output mode and pulled low, holding this state for at least 18 milliseconds. Then, the microprocessor's I/O is switched to input mode. Due to the pull-up resistor, the microprocessor’s I/O line and the DHT11 DATA line will remain high, waiting for the DHT11 to respond with a signal, as illustrated below:
90
+
The microprocessor's I/O pin is set to output mode and pulled low, holding this state for at least 18 milliseconds. Then, the microprocessor's I/O is switched to input mode. Due to the pull-up resistor, the microprocessor’s I/O line and the DHT11/DHT22 DATA line will remain high, waiting for the DHT11/DHT22 to respond with a signal, as illustrated below:
76
91
77
92

78
93
79
94
80
95
### Step 3
81
96
82
-
The DHT11’s DATA pin detects an external signal and goes low, indicating that it is waiting for the external signal to complete. Once the signal ends, the DHT11’s DATA pin switches to output mode, producing a low signal for 80 microseconds as a response. This is followed by an 80-microsecond high signal, notifying the microprocessor that the sensor is ready to transmit data. At this point, the microprocessor's I/O pin, still in input mode, detects the low signal from the DHT11 (indicating the response) and then waits for the 80-microsecond high signal to start receiving data. The sequence of signal transmission is illustrated below:
97
+
The DHT11/DHT22’s DATA pin detects an external signal and goes low, indicating that it is waiting for the external signal to complete. Once the signal ends, the DHT11/DHT22’s DATA pin switches to output mode, producing a low signal for 80 microseconds as a response. This is followed by an 80-microsecond high signal, notifying the microprocessor that the sensor is ready to transmit data. At this point, the microprocessor's I/O pin, still in input mode, detects the low signal from the DHT11/DHT22 (indicating the response) and then waits for the 80-microsecond high signal to start receiving data. The sequence of signal transmission is illustrated below:
83
98
84
99

85
100
86
101
### Step 4
87
102
88
-
The DHT11 outputs 40 bits of data through the DATA pin, and the microprocessor receives these 40 data bits. The format for a data bit "0" consists of a low level lasting 50 microseconds, followed by a high level lasting 26-28 microseconds, depending on changes in the I/O level. For a data bit "1," the format includes a low level of 50 microseconds followed by a high level lasting up to 70 microseconds. The signal formats for data bits "0" and "1" are shown below.
103
+
The DHT11/DHT22 outputs 40 bits of data through the DATA pin, and the microprocessor receives these 40 data bits. The format for a data bit "0" consists of a low level lasting 50 microseconds, followed by a high level lasting 26-28 microseconds, depending on changes in the I/O level. For a data bit "1," the format includes a low level of 50 microseconds followed by a high level lasting up to 70 microseconds. The signal formats for data bits "0" and "1" are shown below.
89
104
90
105

91
106
92
107
### End signal
93
108
94
-
After outputting a low signal for 50 microseconds, the DHT11 completes sending the 40 bits of data and switches the DATA pin back to input mode, which, along with the pull-up resistor, returns to a high state. Meanwhile, the DHT11 internally re-measures the environmental temperature and humidity, records the new data, and waits for the next external signal.
109
+
After outputting a low signal for 50 microseconds, the DHT11/DHT22 completes sending the 40 bits of data and switches the DATA pin back to input mode, which, along with the pull-up resistor, returns to a high state. Meanwhile, the DHT11/DHT22 internally re-measures the environmental temperature and humidity, records the new data, and waits for the next external signal.
110
+
111
+
112
+
113
+
## Comparison of DHT11 and DHT22 40-Bit Data Formats
0 commit comments