   Serial.print(F("BTLE Handlers Setup..."));
   setupBTLEHandlers();
   Serial.println(F("OK"));
+  
+  latchtime = millis();      // We'll keep track of idle time using millis(), and turn the system off if we exceed IDLETIME seconds
 }
 
 void loop(){
+  unsigned long temptime;
+  
   if(sendBlankPending){
     sendBlank();
+    latchtime = millis();    // Reset the base latchtime for the IDLETIME timeout count, since activity has occurred
   }
   
   if(sendDataPending){
     sendData();
-  }
-}
+    latchtime = millis();    // Reset the base latchtime for the IDLETIME timeout count, since activity has occurred    
+  }
+  
+  temptime = millis();
+  if ((temptime - latchtime)>IDLETIME)      // If we've exceeded the max idle time,
+        mcp.digitalWrite(LATCHPIN, LOW);    // we'll reset the latch pin. This will remove power from the system in the final wired version.
+}

  } else {
    sendBTLEString(response, strlen(response));
  }
}

void setupBTLEHandlers(){

#include "Photometer.h"

#include <Wire.h>
#include <SPI.h>
#include "utilities.h"
#include <RFduinoBLE.h>
#include "BTLE.h"
