Skip to content

Commit

Permalink
Use INPUT_PULLUP
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
matthijskooijman committed Jul 24, 2015
1 parent 45a20da commit f9c3f32
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions DHT.cpp
Expand Up @@ -21,8 +21,7 @@ DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) {

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

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

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

0 comments on commit f9c3f32

Please sign in to comment.