Raj_Srikar:
My code is all good and working perfectly. I really don't understand why you have to fix it and also you've changed / updated the time. The code has become more complicated now. I just wanted to add a counting variable (as per the explanation above). I tried using your code. But I got an error: "Error compiling for board Arduino/Genuino Uno". And thank you so much for your effort. Please try making it simplified.
My best attempt to this, as a newbie is this:
When I compiled your code the first time I got:
Arduino: 1.8.8 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
sketch_jan20f:1:17: error: dht.h: No such file or directory
compilation terminated.
exit status 1
dht.h: No such file or directory
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Okay. No biggie. Maybe you really do have a file called "dht.h" in your project folder. I had to change it to <DHT.h>. After I did that:
Arduino: 1.8.8 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
sketch_jan20f:4:1: error: 'dht' does not name a type
dht DHT;
^
C:\Use...\sketch_jan20f.ino: In function 'void loop()':
sketch_jan20f:16:8: error: expected unqualified-id before '.' token
DHT.read11(dht_apin);
^
sketch_jan20f:19:21: error: expected primary-expression before '.' token
Serial.print(DHT.humidity);
^
sketch_jan20f:22:21: error: expected primary-expression before '.' token
Serial.print(DHT.temperature);
^
exit status 1
'dht' does not name a type
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
I realized you have dht DHT backwards, so I corrected it to DHT dht; Then:
Arduino: 1.8.8 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
sketch_jan20f:4:5: error: no matching function for call to 'DHT::DHT()'
DHT dht;
^
In file included from C:\User...\sketch_jan20f.ino:1:0:
C:\User...\Arduino\libraries\DHT_sensor_library/DHT.h:41:4: note: candidate: DHT::DHT(uint8_t, uint8_t, uint8_t)
DHT(uint8_t pin, uint8_t type, uint8_t count=6);
^
C:\User...\Arduino\libraries\DHT_sensor_library/DHT.h:41:4: note: candidate expects 3 arguments, 0 provided
C:\User...\Arduino\libraries\DHT_sensor_library/DHT.h:39:7: note: candidate: constexpr DHT::DHT(const DHT&)
class DHT {
^
C:\User...\Arduino\libraries\DHT_sensor_library/DHT.h:39:7: note: candidate expects 1 argument, 0 provided
C:\User...\Arduino\libraries\DHT_sensor_library/DHT.h:39:7: note: candidate: constexpr DHT::DHT(DHT&&)
C:\User...\Arduino\libraries\DHT_sensor_library/DHT.h:39:7: note: candidate expects 1 argument, 0 provided
C:\User...\Arduino\sketch_jan20f\sketch_jan20f.ino: In function 'void loop()':
sketch_jan20f:16:8: error: expected unqualified-id before '.' token
DHT.read11(dht_apin);
^
sketch_jan20f:19:21: error: expected primary-expression before '.' token
Serial.print(DHT.humidity);
^
sketch_jan20f:22:21: error: expected primary-expression before '.' token
Serial.print(DHT.temperature);
^
exit status 1
no matching function for call to 'DHT::DHT()'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Then I saw that you were using this to read humidity (and temperature):
dht.humidity
when the library proper usage is more like:
fHumidity = dht.readHumidity();
I dunno. Maybe you've got a special or downlevel library but your code didn't work out of the box on my machine. The fact that it doesn't compile on yours suggests you do have different libraries or maybe you've somehow been changing your libs...
If the code didn't compile on your machine how do you know that the update time is no longer the same ("...and also you've changed / updated the time...")? Is it because you don't see the dreaded "delay(2000)" at the end of loop()??
Good luck.