Search This Blog

Sunday 14 August 2016

Arduino on Battery...

I've thoroughly enjoyed learning about, and using, small Arduino microcomputers.
My collection includes Nano's (5V, 16MHz, USB, Volt Reg, 328P, china clones) and Micro Pro's (both 3.3V and 5V versions, china clones).

But it is important to find applications for them.  A Little Library became an interest in our family when the grandkids discovered one in their neighbourhood, so we are soon to have one on our lawn.  It seemed reasonable to add a little light to the library to make it easier to use in the evenings, so a small battery powered, solar panel charged light was obtained for this purpose.  Seemed an excellent device; the lamp looks good, offers the equivalent of a 15W bulb at about 150mA, and has an 800mAh LiIon cell to run it.  The included little solar panel (3 x 5 inch) was naked, but a simple 3D printed holder took care of that (another story...)

But the light needed to come on only when the little doors to the library are open, and it is probably a good idea to add a little timer to check if the doors are left open, and turn off the the light to save the battery.  And we don't need to turn on the light if it is daylight outside, right?  And, since we added those little door switches, we should probably keep track of how busy our Little Library is...  And maybe we should report some this data, along with monitoring the battery charging and voltage, somewhere more convenient, perhaps with a radio data link....  So now we have progressed a long way from the little power switch that comes with the original light system...

Wow!! An excellent application for a little Arduino and a few other goodies!!

The interesting catch here is that the Little Library sits at the edge of the street, far away from the usual power sources.  But an Arduino doesn't use much power, and the solar panel should keep that little battery charged; it says so right in the marketing literature.  So we proceeded to build a little interface, to hold a Nano, and some interface circuitry to read switches and voltages, and control the light, and connect to a nice little data radio system running at 2.4GHz. We also added a couple of voltage regulators; a 5V Booster to ensure 5V to the Nano, and a 3.3V regulator to ensure good voltage to the radio.  We got most everything working, then thought it might be useful to take some measurements.  It's not wise to run a LiIon cell down too low, after all...

Well, the electronics I added, minus the radio, draws about 40mA, and if the sun isn't out, the solar panel only supplies about 5mA charge current!!  And the lamp isn't even on yet!!  More work needs to be done!

There is a lot of information available online concerning the use of the Atmel 328P low power, or Sleep modes, and a number of very good Arduino IDE Libraries exist to make it easy to use them.  One confusing aspect of some of the Sleep modes seems to be how long it takes for the 328P uC to Wake Up after being in Sleep mode.  Not a lot of info available, and what there is seems unclear.  Suggestions range from a uS to 65mS+!!!.  Since I am running some contact debounce and voltage filtering logic on a time base presently set to 5mS, It is important to know what is really happening. So I did a little testing, to determine this, and also to see what power savings were possible with my Nano, even though the USB and V Regulator chips have no sleep mode.

The test routine I used is very simple:

#include <Sleep_n0m1.h>
//  Test startup delay for various sleep modes.
// Use Sleep_n0m1  to provide 15mS sleep periods, set, then reset an output bit, then loop.
// measure sleep interval with scope...
Sleep sleep;
unsigned long sleepTime; //how long you want the arduino to sleep
void setup() {
   sleepTime = 15; //set sleep time in ms, max sleep time is 49.7 days
    pinMode(6, OUTPUT);  // pulse to monitor sleep time.
    digitalWrite(6, 0);  // ensure bit is off to start   
}
void loop() {
/* modes of sleep
   SLEEP_MODE_IDLE
   SLEEP_MODE_ADC
   SLEEP_MODE_PWR_SAVE
   SLEEP_MODE_EXT_STANDBY
   SLEEP_MODE_STANDBY
   SLEEP_MODE_PWR_DOWN
   */
  sleep.pwrDownMode(); //set sleep mode
  sleep.sleepDelay(sleepTime); //sleep for: sleepTime  (use delay(15) instead when not sleeping)
//  sleep ends here.  Pulse output bit quickly (about 4uS)
digitalWrite(6, 1);
digitalWrite(6, 0);
}

With this and my scope (Hantek 6022BE DSO), and a meter to measure current draw to the Nano, I got some very interesting results, which might be of use to others:

Sleep Mode:                Loop Time:    mA @ 5V:     mA @ 4.2V
None [use Delay(19)]   19.0mS            21.6                13.5
Idle                               19.0mS           13.7                  8.4
Standby                        18.9mS            7.0                   5.4
Power Down                 19.9mS           6.6                   5.1

Notes:
- Loop time differences of 18.9 vs 19.0 prob. due to accuracy of cursor readings on my DSO
- Power Down mode saves a bit more power, but adds 1.0mS to wake up times
- supply V = 4.2V was also tested, to estimate savings on direct LiIon cell voltage
- Loop time was unchanged when supply V changed.
- using a nominal sleep duration of 15mS on this particular Nano results in almost 19mS of actual sleep time. Since my reading suggests that other sleep mode wake up times, due to hardware, are very very small, this must be due to a substantially different WDT oscillator frequency, which was not affected by supply V.
- the data above suggests that the 328P in the Nano is configured for a "Full Swing Crystal Oscillator Clock", which prevents the CPU from running for 16K clock cycles after startup of the oscillator.  At 16MHz, this will be about 1mS, the added amount in the Power Down sleep mode.
- the no sleep mode case used a Delay function, set to match the sleep loop times, instead of a Sleep function.

A Mini Pro, running at 3.3V would allow additional savings, prob. under 1mA average consumption.  However, since my Library electronics includes a socket for a Nano, and the Mini Pro pinout is substantially different from a Nano, I will operate with the Nano, at 4.2V for a while.  If an additional power savings is needed, I can rewire the electronics to accept a Mini Pro.  I can also remove the 5V Booster (uses about 3mA idling, not included in these measurements ), and look at shutting off the 3.3V Regulator (another 3mA idling), if needed.

Hopefully real world edge of road install tests will show much higher solar panel charge currents on average, and worst case, sufficient to provide enough charge during the day to run the electronics for a 24 hr period...

Now back to my code rewrites, since the millisecond function, and the Bounce2 and SimpleTimer Libraries that depend on it, will no longer work in the Low Power Sleep World...



No comments:

Post a Comment