• If the timer ever expires, then the remote control is
inactive and it's time to power-off the device.

VIN
VOUT

• One minor issue resolved during testing was that the
timer was initially stored in a int variable which on the
Arduino is a 16-bit variable. The circuit kept turning off just
after a minute elapsed; likely because 16-bit variables have a
maximum value of 65,767 — or 65 seconds with a
millisecond timer — before they overflow and wrap around
to zero. Changing to a long variable resolved this.

VIN
VOUT

Conclusion

The Pololu power switch is inexpensive (under $5) and
easy to add to any Arduino robot. It's a good solution
whenever you want to be able to provide a software
controlled power-off for your robot. SV

OFF
GND
GND
GND
GND

Pololu pushbutton power switch.

Wiring/connection diagram.

const int offPin = 7; // The pin connected to the power OFF function unsigned long nPowerOffTime; void resetPowerOffTimer() { // This function resets the time when CPU // should be powered off // If there is activity on the robot, then // call this function to reset the time to // power off const int kInactivityPeriodForPowerOffSeconds = 120; nPowerOffTime = millis() + (kInactivityPeriod ForPowerOffSeconds 1000); return; } void setup() { // In Arduino, the "setup" function is called // once when user program starts // Setup the "offPin" to be an output. Initial // value is low. pinMode(offPin, OUTPUT); digitalWrite(offPin, LOW); resetPowerOffTimer(); return; } void sendRemoteControlMsgToRobot() { ...Send Wireless message to remote containing joystick and button values...
if (...Joysticks or buttons have changed value...) resetPowerOffTimer(); }
void loop() { // In an Arduino application, the loop // function is called continuously. // The user's application should do its work // and return. Between calls to to the "loop" // function other housekeeping functions are // performed. int nCurrTime = millis(); { // Every 50 msec send a wireless message to // robot with joystick values const int kTimeBetweenRCMessages = 50; static int nTimeForNextRemoteControlMessage = 0; if (nCurrTime >= nTimeForNextRemote ControlMessage) { nTimeForNextRemoteControlMessage = nCurrTime + kTimeBetweenRCMessages; sendRemoteControlMsgToRobot(); } } // Check to see if CPU should be automatically // powered off { if (nCurrTime >= nPowerOffTime) digitalWrite(offPin, HIGH); } }