Powering up sensor using an I/O pin to turn it off when PHOTON goes into deep sleep.
authorrtrimana <rtrimana@uci.edu>
Mon, 16 Apr 2018 16:09:07 +0000 (09:09 -0700)
committerrtrimana <rtrimana@uci.edu>
Mon, 16 Apr 2018 16:09:07 +0000 (09:09 -0700)
version2/src/C/Sensor-Arduino.ino

index 48614b21c8ff16ce01220b21ddf6e3c6978463bf..214447e6368c2e91887ec2033405074871deb3b2 100644 (file)
@@ -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);
 }