Power Bank - Keep Alive With Arduino Nano in Deep Sleep

by Happe Hippo in Circuits > Arduino

1516 Views, 1 Favorites, 0 Comments

Power Bank - Keep Alive With Arduino Nano in Deep Sleep

Miady_Powerbank1.png

I was doing an ESP32 data logging project and thought I'd use a power bank to power it rather than my computer. The power bank turned off after 60 s because the ESP32 project wasn't drawing enough power. I started to get the parts together to build a hardware keep alive circuit based on the 555 timer chip. There are several examples of this on internet, including in Instructables. But then I realized that I have several power banks and they turn off at different times and may need different levels of power to stay awake. So I thought it would be better to use a microcontroller instead. It would be easier to change the calibrations for different power banks. In this case I used an Arduino Nano. The "deep sleep" mode for the Nano was also used to minimize the current drained by the circuit.

Supplies

Arduino Nano

Breadboard

USB A Female boards (2)

BC547 transistor

25 Ohm resistor (1 W)

330 Ohm resistor (1/4 W)

LED (red)

Jumper Wires

Build Circuit

PowerBank_KeepAlive_Breadboard.png
PowerBank_KeepAlive_Circuit.png

The circuit is very simple. The power bank is plugged into the the USB connector. It powers the Nano at the 5V pin. Digital Pin #7 is used to turn on a transistor. The transistor allows a discharge to take place through a 25 Ohm resistor (four 100 Ohm 1/4 Watt resistors in parallel are shown on the breadboard). There is also a LED to indicate when the discharge is happening. The project that is to be powered is connected to the other USB connector (not shown on breadboard).

Write Code Using Arduino IDE

The sketch for the Arduino IDE is attached below. Digital Pin #7 is used to control the transistor. The LowPower library is used to put the Nano into a deep sleep state. The library allows a maximum sleep time of 8 s. So, the command needs to be repeated if longer sleep times are needed. A delay was added between each sleep time request because it seemed sequential sleep time requests didn't work.

The LowPower library can be found at https://github.com/rocketscream/Low-Power.

Calibrate the PowerBank

It is required to determine what parameters are necessary to keep the power bank alive. The key variables are: the amount of current discharged through the transistor, the length of time the discharge occurs, the length of time the power bank will shut off with low power. Since no specification sheets are available for power banks, the calibrations need to be determine by trial and error. For the setup used, the discharge through the transistor is about 160 mA, the current used by the Nano in regular mode is about 30 mA, the current used by the Nano in deep sleep mode is about 12 mA. All the power banks I tested seemed to be OK with the 160 mA discharge load. If you need to change this, you'll have to use a different resistance. Note that in this project, I used 4 100 Ohm resistors in parallel for the 25 Ohm resistor. An excerpt of the code is shown below. For the power bank in this example, it was programmed to sleep after about 60 s of low power. I was able to determine that it still remained on with only 250 ms discharge. This delay(250) command will need to be changed if a power banks is not OK with this. Since the power bank sleep time is about 60 s, six sequential deep sleep commands for 8 second deep sleep were used. A 500 ms delay time was used after each deep sleep command. The number of deep sleep commands may be different among power supplies, depending on how long they are programmed to stay awake with low current.


  digitalWrite(trans, HIGH);  // switch transistor pin on

  delay(250);            // keep transistor pin on for this time in ms

 digitalWrite(trans,LOW);    // switch transistor pin off

 LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); //go into deep sleep for 8 seconds

 delay(500);

 LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

 delay(500);

 LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

 delay(500);

 LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

 delay(500);

 LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

 delay(500);

 LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

 delay(500);

Areas for Optimization

The average current used by the circuit is about 14 mA. This project is not optimized. To further reduce the current drain used by the circuit the following things could be investigated:

1) the minimum discharge current needed to keep power bank alive (160 mA was used in this example using 25 Ohm resistance

2) the minimum amount of discharge time the power bank needs to keep alive (250 ms used here)

3) the minimum delay required between each deep sleep command (500 ms used here)

4) the maximum number of deep sleep commands that can be used (six 8 s commands used here, the library also allows for 1,2,4 seconds deep sleep time and some shorter durations as well)

Other Areas to Explore

The results shown in this project were acceptable. However, if lower current is needed to prolong the power bank use even further, other things could be investigated.

1) Taking unnecessary components off the Nano (e.g., power LED, DC/DC converter, etc)

2) Using a lower power microcontroller or using bare chips (e.g., bare ATMega328 chip)

Conclusion

By using this circuit, which imparted an additional average current drain of about 14 mA, the ESP32 project was able to be continuously running without the power bank timing out. The key to this was to utilize the "deep sleep" mode for the Arduino Nano.