DIY: Self-shutting-down Arduino

I have recently finished building my own BB-8 robot (more on that later!) and faced the problem of not wanting to open its body to power it on and off. I came up with the following idea.

self-shutting-down-arduino_schem

Here, the battery is connected to the Arduino’s ground and a simple relay’s ground. The positive lead of the battery is connected to the NO (normally open) pin of the relay, and the Arduino’s VIN pin is connected to the MAIN pin of the relay. So, as long as the relay’s open, no current goes to the Arduino. To start the Arduino, I’ve also connected a push button to the NO and MAIN pins of the relay. When I push the button (in BB-8’s case, it’s a magnetic button), this lets the Arduino boot up.

The only thing needed then, in order to be able to release the button and have the Arduino stay powered, is to close the relay programmaticaly :

 

#define POWER_PIN 2
void setup() {
  pinMode(POWER_PIN, OUTPUT);
  digitalWrite(POWER_PIN, LOW);
}

Then you only need to keep the button pressed during the Arduino’s bootup, and as soon as you hear the relay click, you can release it.

Now, to power off the Arduino, it’s just a matter of setting the relevant pin HIGH on a predefined condition (in BB-8’s case, it’s after 60 seconds of RC signal loss):

void loop() {
  /* do your normal stuff */

  if (now() - rc_signal_lost > 60) {
    power_off();
}

void power_off() {
  digitalWrite(POWER_PIN, HIGH);
}

In my case, the circuit is more complicated, because I’m using a 2S LiPo battery. These things hate being over-discharged, so I added a LiPo battery tester which beeps when the cells’ voltage drop below a certain level. The tester is plugged on the three charge balancing leads of the LiPo battery, which allow to test each cell independantly. So, in my bot I have wired two relays, one of them for each cell’s positive lead. This allows to have the LiPo battery tester without having it draining the power when the bot is off.

Here is the schematics for my bot:

self-shutting-down-arduino_schem