arduinoprojects

git clone https://git.tarina.org/arduinoprojects
Log | Files | Refs

dhtnew_powerDown.ino (1707B)


      1 //
      2 //    FILE: dhtnew_powerDown.ino
      3 //  AUTHOR: Rob Tillaart
      4 // VERSION: 0.1.0
      5 // PURPOSE: DHTNEW library test sketch for Arduino
      6 //     URL: https://github.com/RobTillaart/DHTNew
      7 //
      8 // DHT PIN layout from left to right
      9 // =================================
     10 // FRONT : DESCRIPTION
     11 // pin 1 : VCC
     12 // pin 2 : DATA
     13 // pin 3 : Not Connected
     14 // pin 4 : GND
     15 
     16 // to see the effect one must apply a voltmeter to the datapin of the sensor
     17 // during the low power mode. Measuring during communication will disrupt the
     18 // data transfer.
     19 
     20 #include <dhtnew.h>
     21 
     22 DHTNEW mySensor(16);
     23 
     24 void setup()
     25 {
     26   Serial.begin(115200);
     27   Serial.println("dhtnew_test.ino");
     28   Serial.print("LIBRARY VERSION: ");
     29   Serial.println(DHTNEW_LIB_VERSION);
     30 
     31   Serial.println("\nstartup");
     32   delay(2000);
     33 
     34   Serial.println("read sensor with 2 second interval");
     35   for (int i = 0; i < 3; i++)
     36   {
     37     int rv = mySensor.read();
     38     if (rv != DHTLIB_OK)
     39     {
     40       Serial.println(rv);  // will print -7 when measuring voltage
     41     }
     42     Serial.print(mySensor.getHumidity(), 1);
     43     Serial.print(",\t");
     44     Serial.println(mySensor.getTemperature(), 1);
     45     delay(2000);
     46   }
     47 
     48   Serial.println("switch to low power (~ 5 seconds )");
     49   Serial.println("measure voltage");
     50   mySensor.powerDown();
     51   delay(5000);
     52 
     53   Serial.println("switch sensor on (and wait 2 seconds)");
     54   mySensor.powerUp();
     55   // wait for 2 seconds.
     56   delay(2000);
     57 
     58   Serial.println("read sensor with 2 second interval");
     59   for (int i = 0; i < 3; i++)
     60   {
     61     mySensor.read();
     62     Serial.print(mySensor.getHumidity(), 1);
     63     Serial.print(",\t");
     64     Serial.println(mySensor.getTemperature(), 1);
     65     delay(2000);
     66   }
     67 
     68   Serial.println("\nDone...");
     69 }
     70 
     71 void loop()
     72 {
     73 }
     74 
     75 // END OF FILE