Skip to content

Commit f9c3f32

Browse files
Use INPUT_PULLUP
Previously, the mode was configured to INPUT and then written HIGH, which works on AVR but isn't very portable. Instead, this uses the INPUT_PULLUP pin mode (available since Arduino 1.0.1) which is portable.
1 parent 45a20da commit f9c3f32

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

DHT.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) {
2121

2222
void DHT::begin(void) {
2323
// set up the pins!
24-
pinMode(_pin, INPUT);
25-
digitalWrite(_pin, HIGH);
24+
pinMode(_pin, INPUT_PULLUP);
2625
// Using this value makes sure that millis() - lastreadtime will be
2726
// >= MIN_INTERVAL right away. Note that this assignment wraps around,
2827
// but so will the subtraction.
@@ -153,7 +152,7 @@ boolean DHT::read(bool force) {
153152
delayMicroseconds(40);
154153

155154
// Now start reading the data line to get the value from the DHT sensor.
156-
pinMode(_pin, INPUT);
155+
pinMode(_pin, INPUT_PULLUP);
157156
delayMicroseconds(10); // Delay a bit to let sensor pull data line low.
158157

159158
// First expect a low signal for ~80 microseconds followed by a high signal

0 commit comments

Comments
 (0)