From f9c3f323e3d2335164f0787bedaf2450fcaa9307 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Fri, 24 Jul 2015 18:18:01 +0200 Subject: [PATCH] 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. --- DHT.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/DHT.cpp b/DHT.cpp index e75ccfe..c2257d0 100644 --- a/DHT.cpp +++ b/DHT.cpp @@ -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. @@ -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