File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -93,10 +93,8 @@ boolean DHT::read(void) {
93
93
uint8_t j = 0 , i;
94
94
unsigned long currenttime;
95
95
96
- // pull the pin high and wait 250 milliseconds
97
- digitalWrite (_pin, HIGH);
98
- delay (250 );
99
-
96
+ // Check if sensor was read less than two seconds ago and return early
97
+ // to use last reading.
100
98
currenttime = millis ();
101
99
if (currenttime < _lastreadtime) {
102
100
// ie there was a rollover
@@ -115,6 +113,10 @@ boolean DHT::read(void) {
115
113
116
114
data[0 ] = data[1 ] = data[2 ] = data[3 ] = data[4 ] = 0 ;
117
115
116
+ // pull the pin high and wait 250 milliseconds
117
+ digitalWrite (_pin, HIGH);
118
+ delay (250 );
119
+
118
120
// now pull it low for ~20 milliseconds
119
121
pinMode (_pin, OUTPUT);
120
122
digitalWrite (_pin, LOW);
Original file line number Diff line number Diff line change @@ -25,6 +25,9 @@ void setup() {
25
25
}
26
26
27
27
void loop () {
28
+ // Wait a few seconds between measurements.
29
+ delay (2000 );
30
+
28
31
// Reading temperature or humidity takes about 250 milliseconds!
29
32
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
30
33
float h = dht.readHumidity ();
You can’t perform that action at this time.
0 commit comments