File tree 1 file changed +16
-8
lines changed
1 file changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -148,27 +148,35 @@ bool DHT::read(bool force) {
148
148
149
149
// Go into high impedence state to let pull-up raise data line level and
150
150
// start the reading process.
151
- digitalWrite (_pin, HIGH );
151
+ pinMode (_pin, INPUT_PULLUP );
152
152
delay (1 );
153
153
154
- // First set data line low for 1 millisecond.
154
+ // First set data line low for a period according to sensor type
155
155
pinMode (_pin, OUTPUT);
156
156
digitalWrite (_pin, LOW);
157
- delay (1 );
157
+ switch (_type) {
158
+ case DHT22:
159
+ case DHT21:
160
+ delayMicroseconds (1100 ); // data sheet says "at least 1ms"
161
+ break ;
162
+ case DHT11:
163
+ default :
164
+ delay (20 ); // data sheet says at least 18ms, 20ms just to be safe
165
+ break ;
166
+ }
158
167
159
168
uint32_t cycles[80 ];
160
169
{
161
- // Turn off interrupts temporarily because the next sections are timing critical
162
- // and we don't want any interruptions.
163
- InterruptLock lock;
164
-
165
170
// End the start signal by setting data line high for 40 microseconds.
166
- digitalWrite (_pin, HIGH);
167
171
pinMode (_pin, INPUT_PULLUP);
168
172
169
173
// Now start reading the data line to get the value from the DHT sensor.
170
174
delayMicroseconds (60 ); // Delay a bit to let sensor pull data line low.
171
175
176
+ // Turn off interrupts temporarily because the next sections
177
+ // are timing critical and we don't want any interruptions.
178
+ InterruptLock lock;
179
+
172
180
// First expect a low signal for ~80 microseconds followed by a high signal
173
181
// for ~80 microseconds again.
174
182
if (expectPulse (LOW) == TIMEOUT) {
You can’t perform that action at this time.
0 commit comments