From: rtrimana Date: Mon, 16 Apr 2018 16:09:07 +0000 (-0700) Subject: Powering up sensor using an I/O pin to turn it off when PHOTON goes into deep sleep. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=8a8d3e2306c65c48a575bacefe511b63ff365191;p=iotcloud.git Powering up sensor using an I/O pin to turn it off when PHOTON goes into deep sleep. --- diff --git a/version2/src/C/Sensor-Arduino.ino b/version2/src/C/Sensor-Arduino.ino index 48614b2..214447e 100644 --- a/version2/src/C/Sensor-Arduino.ino +++ b/version2/src/C/Sensor-Arduino.ino @@ -6,10 +6,11 @@ // 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); @@ -33,6 +34,13 @@ void setup() { // 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); @@ -86,6 +94,9 @@ void loop() { iKeyA->releaseRef(); iValueA->releaseRef(); + + // Turn off sensor + digitalWrite(PWRPIN, LOW); System.sleep(SLEEP_MODE_DEEP, SLEEP_TIME); }