Dear Power Bank, Don't Switch Me Off

Since 2001, we have a zoo of different power banks, ment for recharging our mobiles and everything else. But they also can be used to drive modules like Arduinos. But if you really do this you will encounter a strange problem: after some time the electronics of the power bank will shut down, and your Arduino stops working. So, why does this happen? The answer is: if the current that is drawn falls below a certain threshold for some good reason it decides to cut the line.
And the Arduino NANO only draw something between 10 and 20 milli Amperes which makes most power banks think there is no load at all.

How can you prevent the power bank from cutting the line? Well, you have to draw some current above the threshold before the time-out is passed. Unfortunately, all the power banks have different specs, so you simply have to check.
We found two modules shipped by LOGILINK
PA0126: time-out: 30 seconds
PA0145: time-out: 60 seconds

One way to solve the problem would be to develop a circuit that draws some extra power every now and then.
But actually, the Arduino can do it on its own given you have at least one spare pin.

In the picture you can see some resistors of 150 Ωs connected to pins 8 to 11 and all of them to GROUND. In case you need pins 8 to 11 for other purposes you have to adapt some lines in the software.

In this example we misuse TIMER-0 for this purpose. As the overflow interrupt of TIMER-0 is already installed by the Arduino system we activate its COMPA interrupt which is activated at the same frequency as the overflow interrupt. As this much too fast there has to be a counter to only activate the extra load at rare moments.

  // TIMER-0 is called 1000 times per second
  const word TIMEOUT = 30000; // milli seconds
  const word PULSE = 1000; // milli seconds
  byte stat;
  static word cnt;
  switch (cnt) {
    // all on:
    case TIMEOUT-PULSE: stat = 15; break;
    // all off:
    case TIMEOUT: stat = 0; break;
    // time-out: every 30 seconds
    case TIMEOUT+1: cnt = 0; return;
    default: return;
  PORTB = stat;
  digitalWrite(LED_BUILTIN, stat);

To install that ISR you only need some lines of code

void setTimer() {
  TIMSK0 = 3; // Timer0 COMPA Interrupt Enable
  // if you need pins 8 to 11 for some purpose
  // certain changes are required
  DDRB = 15; // all pins 8 - 11 = OUTPUT

and this has to be called somewhere during setup:


In any case, check your power bank and modify the constants to suit your requirements.

contact: nji(at)