// System defines
// Arduino
-#define DHTPIN 2 // what pin we're connected to
+#define DHTPIN 2 // Data pin
+#define PWRPIN D5 // Power pin
#define DHTTYPE DHT22 // DHT 22 (AM2302)
// IoTCloud
-#define SLEEP_TIME 1800 // Sleep time in seconds
+#define SLEEP_TIME 10 // Sleep time in seconds
// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);
// firmware onto the Particle board.
// e.g. sudo screen /dev/ttyACM0
+ // We use one I/O pin to power the sensor so
+ // that we can make it go to sleep when we go into
+ // deep sleep.
+ pinMode(PWRPIN, OUTPUT);
+ // Turn on sensor
+ digitalWrite(PWRPIN, HIGH);
+
// Prepare device key from MAC (just last 2 of 6 digits)
byte mac[6];
WiFi.macAddress(mac);
iKeyA->releaseRef();
iValueA->releaseRef();
+
+ // Turn off sensor
+ digitalWrite(PWRPIN, LOW);
System.sleep(SLEEP_MODE_DEEP, SLEEP_TIME);
}