Raspberry Pi in the Wild ! Extended Timelapse With Battery Power




Posted in TechnologyRaspberry-pi

Introduction: Raspberry Pi in the Wild ! Extended Timelapse With Battery Power

Motivation: I wanted to use battery powered Raspberry Pi camera to take once-a-day photos outdoors to create long term time-lapse videos. My particular application is to record ground cover plant growth this coming spring and summer.

Challenge: Design low current Raspberry Pi power control to ensure long battery life.

My Solution: I use a hacked alarm clock, Attiny85 circuit & Pimoroni OnOff shim to completely cut power to Raspberry Pi when not in use. While the Attiny85 and alarm clock continues running in standby mode, current draw is only 5 microAmps. Two AAA batteries power both Attiny and alarm clock, while a USB power bank powers the Pi.

Basic Operation: When to alarm clock goes off it wakes a sleeping Attiny circuit, which then signals Pimoroni OnOff shim to apply power from USB power bank to Raspberry Pi. The Pi executes a run-at-boot script (take a photograph). After sufficient time has passed (60 seconds in my application), the Attiny circuit again signals Pimoroni OnOff shim and then the Attiny enters sleep mode. Based on the signal from Attiny, the Pimoroni OnOff shim executes Pi shutdown command, and after Pi shutdown process completes, cuts power from USB power bank to Raspberry Pi.

Step 1: Parts and Tools


Raspberry Pi Zero or Raspberry Pi Zero W (draws more power)

Raspberry PI Camera Module

Raspberry Pi Zero Case



Battery Operated Digital Alarm Clock Target

ATtiny85 8 DIP Digikey

(2) CAP ALUM 100UF Digikey

DS3231 RTC Module AliExpress

(2) 68 ohm resistor

Short (about 6 inches) micro USB cable

Clear Box Amac SKU#: 60120. 4" x 4" x 5-1/16" h The Container Store

Kmashi 11200 mAh USB Power Bank # k-mp806 or similar

Double stick tape

Small self-tapping screw

(2) 1 X 8 pin female stacking headers - commonly sold a Arduino UNO stacking headers AliExpress

Perf or strip board about 1 1/4" by 2"

5 1/2 by 5 /12 by 3/4 thick pine or plywood

1 1/4 PVC pipe about 15 " long

1 1/4 PVC coupler

(2) short bungee cords about 10" long

(4) 1/4" dia. wooden dowel pins about 1"long

UltraDeck Natural Post Sleeve Cap Menards


Wire Cutters and Solder Iron

Arduino UNO or other way to program ATtiny85

Hook up wire and jumpers

Keyboard, mouse, HDMI monitor, USB port and Ethernet Hub , OTG cable


Step 2: Install Raspberry Pi OS, Pimoroni OnOff Shim, DS3231 RTC, and Pi Camera Module

Pi Zero setup. Prepare SD card for Raspberry Pi with the distribution of your choice. During initial setup process, being sure to enable I2C interface, camera, and boot to CLI with auto login, set the correct local time and change your password. I also recommend setting up a Static IP Address to make things easier down the road. Solder male header to Pi Zero. You can use either the standard 2 x 20 header or a shorter 2 x 6 header, as all 40 pins are not required for this project - just the first 12 pins.

Camera Install. Snap Pi Zero into its case and use the included short ribbon cable connect camera module to Pi Zero routing the cable out case end slot. Fit the GPIO slotted top cover and attach the camera to the cover with double stick tape (see photo).

Prepare Pimoroni OnOff Shim, DS3231 RTC. Although the Pimoroni OnOff Shim comes with a 2 x 6 female header I instead used two 1 x 6 female "stacking headers commonly sold for Arduino UNOs, The header pins need to extend above the Pimoroni OnOff Shim at Raspberry Pi pin locations 1, 3 ,5, 7, 9, the other pins can be cut down to standard pin length. Push the DS3231 RTC onto the extended pins as shown in the photo and then push the Pimoroni OnOff Shim & DS3231 RTC sub-assembly onto the Raspberry Pi header pins as shown.

Install Pimoroni OnOff Shim software with:

curl https://get.pimoroni.com/onoffshim | bash

For additional info on installing Shim look here

Install DS3231 RTC software per these instructions

Initial Tests - Camera,Pimoroni OnOff Shim, DS3231 RTC

Connect local keyboard and monitor to Pi Zero. Ensure you have a network connection (ethernet cable or Wifi). Connect USB power cable Pimoroni OnOff Shim.

a. Press Pimoroni OnOff Shim push button for 3 seconds and then release - this toggles the Pi Zero on or off. Observe the bootup and shutdown process on the monitor. Your Pi Zero now has a advanced technology upgrade - an on/off switch!

b. Set DS3231 time and verify it reads out the correct time with:

sudo hwclock -w 

sudo hwclock -r

c. Test camera function per these instructions.

Step 3: Setup Up Raspberry Pi Run-At-Boot Script and Test Camera

Create and move into new zerocam subdirectory

mkdir zerocam
cd zerocam

Use nano editor to create new script file

nano photo.sh

Then copy and paste the below code into the nano editor. The close nano with Ctrl+X, Y then Return.

DATE=$(date +"%Y-%m-%d_%H%M")
raspistill -o /home/pi/zerocam/$DATE.jpg convert -pointsize 80 -fill yellow -draw "text 570,1800 '$(date)'" /home/pi/zerocam/$DATE.jpg /home/pi/zerocam/$DATE.jpg

Since this script uses the convert command, you'll need to install ImageMagick on the Raspberry Pi

sudo apt-get update
sudo apt-get install imagemagick

Make the file executable

chmod +x photo.sh

Open /etc/rc.local (commands in this file run at boot)

sudo nano /etc/rc.local

Near the bottom of the file, just before exit 0 statement add this new line and then close nano with Ctrl+X, Y then Return.


With a local monitor connected, test that it works

sudo reboot

The Pi should reboot and take a photo. There will be a new .jpg file in directory /home/pi/zerocam

Also test turning the Pi on and off with Pimoroni push button. Measure and record the Pi boot up time. It should less than 60 seconds.

Step 4: Hack Alarm Clock

Observe as produced operation - Install two AAA batteries in alarm clock, and practice setting time and alarm per the included instructions. In particular observe the alarm sounding - you should see the (1) the display's little alarm symbol flashing, (2) the buzzer sounds for 1 minutes then shuts off and (3) the back light LED illuminates for 5 seconds then turns off.

Disassemble - Remove the four screws from clock back to separate the two halves, then remove four more screws to free the main PCB.

Hack - Cut the LED leads at the front of the PCB as shown and solder to 5" long wires to the remaining leads on the backside of the PCB (see illustration). Desolder the buzzer as shown.

To the battery compartment terminals add two additional wires (red and black) plus an 100MFD electrolytic capacitor as shown (observe polarity).

Reassemble the clock making sure to route LED and new battery leads out the rear cover retention slots as shown.

Retest - Install batteries and test the alarm function - now when the alarm goes off you should see the display's little alarm symbol flashing - but no buzzer and no backlight. Connect a mulitmeter to LED leads you should detect about 3 VDC when the alarm goes off of a period of about 5 seconds..

Step 5: Build Attiny85 Circuit Board

Referring to the photo and Attiny85 Schematic.pdf construct the circuit board on a small piece of perf or strip board. Notes:

  • Be sure to use a 8 pin DIP socket for Attiny85 chip as it needs to be removed for programming.
  • Assure correct orientation of the Optos before soldering.
  • Jumper leads to Pimoroni Shim should be at least 4 inches long with female headers to attach the the Shims BTN male pins.
  • Observe Polarity when making connections with alarm click - circuit has no reverse polarity protection

Step 6: Upload Code to Attiny 85 Chip

Using an Arduino Uno or other means, upload the code (AttinyPiPowerControl.ino file attached) to your Attiny85 chip. Note - this code allows 60 seconds for the PI to boot up, take a photo and get to terminal command prompt before starting the shutdown process. You can then install the Attiny85 chip in its circuit board socket - double check orientation.

Note: If you need more or less Pi runtime, just edit this line near the bottom:

delay(60000); // let Pi boot and run for a time

Step 7: Wiring and Initial Test and Downloading Photo Files From PI


Connect USB power bank to micro usb port of Pimoroni shim. Connect jumper leads from Attiny85 circuit board to Pimoroni shim, ensure the black lead connects to the outermost edge BTN pin on Pimoroni shim.


Install 2 AAA batteries in alarm clock, and set clock time. I recommend also connecting Pi's HDMI port to a local monitor.

Turn the Alarm on and set an alarm a few minutes into the future. When the alarm goes off, you should see:

    a. Clock alarm icon starts flashing

    b. After about 5 second the Pimoroni Shim red LED comes on for 5 seconds

    c. The Pi starts booting up

    d. After about 20 seconds the camera LED comes on and a photo is taken. If you have a local monitor connect, you'll see a brief preview of the photo taken.

    e. After another 40 seconds or so, the Pi boots all the way up to terminal command prompt

    f. Pi starts the shutdown process, after about 20 seconds the Pimoroni Shim red LED flashes indicating power is cut to the PI

    Downloading photo files from PI

    I connect the PI to my network using OTG cable, and USB to ethernet adapter, powering Pi from wall wart. Then use WinSCP to download files to my PC.

    Step 8: Assemble Electronics Enclosure

    Attach Attiny85 circuit board to back of alarm clock using a small self-tapping screw. Attach PI to clock using double stick tape as show.

    Attach clock left side to display case bottom with double stick tape.

    Attach USB power bank to display case bottom with double stick tape as shown.

    Place the top case over the display case bottom as shown.

    Step 9: Construct Mounting Stake, Final Assembly and Release PI Into the Wild

    Bottom piece: In a 5 1/2 X 5 1/2 piece of wood, cut 4 slots 3/4" inward from each side as shown. I used a 1/4 router bit, but you can also drill and saw. In the center make a hole for 1 1/4 PVC coupling. Ideal hole size is 1 5/8", but since I only had a 1 3/4" hole saw, I used that and built up coupling OD with duck tape. Glue coupling in place with epoxy.

    Center the electronics enclosure above the wood block and mark its outline. Then drill four 1/4 holes along each side as shown. Glue four 1" long 1/4" dia wood dowels in these holes - this will help keep the enclosure centered.

    Top piece: drill four 3/16" holes near the lower edge of each size and insert 3/4" long S-hooks in each hole bending the ends closed so they won't fall off. On the inside edges hot glue 4 four 1/2 thick scraps of wood - these will help keep the top piece centered above the enclosure.

    Final Assembly: Sandwich the electronics enclosure between top and bottom pieces and secure with two bungee cords as shown.

    Release PI into the Wild: Make a mounting stake by cutting 1 1/4" PVC pipe of a length suitable to your purposes, cut one end at a 45 degree angle to make it easier to pound into the ground. In my case I'm interested in ground cover plant growth (Vinea minor) this spring and, so my PVC stake is only 15" long. Double check that AAA batteries are fresh,USB power bank is fully charged and alarm clock is properly set - then pound stake into the ground and slip assembly on top of mounting stake - see photo.

    Step 10: Current Measurements and Accelerated Battery Life Test

    I measured current using Radio Shack RS-232 Multimeter (22-812) and companion Meter View software. Not the beast choice, but it's what I have.

    Measurement of current draw from two AAA batteries power Attiny85 board and alarm clock

    To "series connect" multimeter, I used dummy batteries and 3 VDC bench power supply (see photo). See graph of current measured during the "active" period (begins with alarm event - ends with Attiny85 returns to sleep mode). Non-alarm draw was constant 0.0049 mA. Summary -

    Active Period = 78 seconds

    Active Period Avg. Current = 4.85 mA

    Non-Alarm Current = 4.9 microA (0.0049 mA)

    I calculated an average daily current draw of 0.0093 mA from the two AAA (750 mAh/each) considering the sleeping and active modes, and theoretical battery life > 8 years using this method .

    Measurement of PI current draw from USB powerbank.
    To "series connect" multimeter I used a modified usb cable (see photo). See graph of current measured during the "active" period (PI boot up - PI shutdown). During non-active period the Pimoroni ONOFF shim completely cuts power to Pi, so current draw ~ zero. Summary -

    Active Period = 97 seconds

    Active Period Avg. Current = 137 mA

    Assuming a 11200 mAh power bank the theoretical number of active period cycles is > 3000.

    Accelerated Battery Life Test

    I temporarily controlled the PI with Arduino UNO programmed for rapid cycling - the time between alarms was 2 minutes vs. the normal 24 hours.

    Test #1: 11200mAh power bank. Started at 10 PM and I halted at 1 PM the following day. Results: 413 photos taken, 3 of 4 charge level LEDs still on at test's end.

    Test #2: 7200mAh power bank. Started at 7:30 PM and I halted at 4:30 PM the following day. Results: 573 photos taken, 2 of 4 charge level LED still on at test's end.

    Conclusion: I believe the above results indicate at least a year's operation taking 1 per photos is likely.



      • Spotless Contest

        Spotless Contest
      • Microcontroller Contest

        Microcontroller Contest
      • Space Challenge

        Space Challenge

      We have a be nice policy.
      Please be positive and constructive.


      2 Questions

      On the build I have gotten up to Step 3 and the camera is working. Have followed Step 3 but the rc-local script doesn’t run on reboot. I have installed ImageMagick and I have checked to code several times but keep getting this error message in reboot.

      [ 22.823744] rc-local [301]: Invalid command line option (convert)

      [FAILED] Failed to start /etc/rc-local Compatibility.

      Do you know what I am doing wrong. thank you.

      Show some resulting videos?


      Interest project, I have thought of similar type of remote data collection schemes myself. Like jom123 mentions above, the Pi might be a little more horsepower than what you really need to do this. For single photos, those cameras can work with Arduino or esp32 can maybe do video. Why the clock/alarm when you have a RTC chip? That's redundant clocks. Having it turn on wifi to report back to a router/pc would be way better to keep your data safe.

      Your accelerated battery life test has one flaw that will get you. Those packs have internal current draw, so you need to crack it open and measure quiescent current at the battery and add that in. Also, LiPo's lose power in cold conditions. I would add a solar shield around at least the southern half of your enclosure, a hole cut in plastic and glued glass over the lens for lower distortion, and a wide angle lens to cover the whole yard. If you do the latter, use a bigger hole and optical circular polarization or UV filter for 35mm camera. Those are cheap on Amazon because its standard kit for SLR lenses.

      2 replies

      A Raspi zero is $5 at Micro Center near me and clone Camera module about $7 on AliExpress. The advantage of the Alarm clock is that it come with display and buttons for setting alarm. The RTC module module was only $1.5. I couldn't figure out how to "share" RTC between both Attiny85 and Pi. Your point regarding quiescent current is a good one, but I rarely it included in battery life estimates. Thanks for optics improvement suggests.

      Firstly, please don't take my suggestions as criticism. I'm a senior level guy, and I'm just trying to help you. You have shown me that you have a good comprehension for electronics along with creativity, so if you are not on that career path, you should really consider it.

      On the issue of using the real time clock with both ATTiny85 and RPi0 a matter of one needing 5vdc logic and the other needing 3.3vdc logic? If so, put a 100ohm series resistance between a 5vdc logic output to the 3.3vdc logic input. Also add a 3.3vdc Zener diode at the 3.3vdc logic input to ground. You can also set you RTC to output multiple pulses, like every minute or hour that either use a different pin or two pins such that you get two simultaneous pulses every hour. Make the Pi look for the dual pulse, and the tiny look for the single one.

      On battery packs, the BMS circuit almost always puts a drain of some sort on the cells. Also, anything with a tact switch (momentary on/off) has either a load directing chip or a built-in micro-controller consuming some quiescent current. It may not seem like much, but a few ma builds up over months, and can really throw your calculations off. Also, LiPo packs with tact switches have been known to turn themselves off from an ESD event or nearby lightning strike. I would suggest you either crack your LiPo pack open and rewire it, or procure 3 or 4 matched (mandatory!!) 18650 cells, and connect them in parallel using battery holders made for that. You can then use an off-the-shelf Chinese step up controller PCB to give you 5vdc. But you need a way to turn this circuit on only when needed. For that, I would suggest using an output from the RTC chip, which should have its own battery, and a N-MOSFET to turn everything else on at the ground connection, including the step down regulator. You may need to add a one-shot multi-vibrator to stretch the RTC pulse out long enough to make everything stay on long enough. A simple large R and 10-22uF film cap from the MOSFET gate to ground might do this trick, but it will delay the turn on of everything. If your RTC doesn't have a battery, consider getting one that does.

      I don't have a Pi zero in front of me right now, but if it has a linear voltage regulator to take 5vdc -> 3.3vdc you should replace that with a switching type step down regulator module from China. This will require removing the regulator IC and soldering 3 wires in it's place to the step down board. This is some that you should always do for projects that need long life, and if any of your other parts have linear regulators, which are grossly inefficient for battery powered circuits, then I would consider replacing those as well.

      A couple of other possible things to try:

      Consider using a solar array from several dead landscaping lights. Measure their current/voltage output in full daylight as well as on a cloudy day, to get a range of what they can provide. Step-up or down as needed. Always point those to the south, like mounting them to the south facing side of your "roof." If you stick with LiPo, you could charge it up during the daytime and possibly get a net zero current charge input to output. If you can make it unity like that, then a smaller LiPo can be used, and super-capacitors are now a possibility. You would not need the big Maxwell 3000F widow-makers. A couple of 100F, or maybe even 10F, might work. These are usually 2.7vdc so you need two in series, with the positive of the first connected to the negative of the second. Putting caps in series cuts the capacitance down to original(F)/(n), where n is the number of caps used. No extra circuitry would be required as long as you don't connect them backwards.

      You need a way to measure small currents. For this, a quick and dirty solution is using a 1ohm 1watt, .1% shunt resistor. Place it in series with the circuit in question, and then measure the voltage drop across it with a good DVM. 1mV = 1mA. Another option is Davy Jones (EEVBlog) uCurrent tool. Don't use DVMs that have current settings of mA or uA to measure current directly because their burden voltage will skew your results. See the Davy Jones EEVBlog YouTube video to see what I mean.

      Consider adding a 1 ohm current sense resistor running into a standard 4-resistor single op-amp differential amplifier with gain. Use 100K for your input resistors, and 500-1000K for you gain resistors. This will allow you to measure the current going into and out of the battery. These resistors need to be .1% and if wire the gain resistor that normally connects to ground so that it sees Vref/2 of the Pi's A/D analog input pins, then you can data log this current. If you use a low power dual op-amp, use one for the differential amplifier, and the second one as a voltage follower for the Vref/2. A voltage divider can be made by putting two equal .1% resistors in series from Vref to ground. Connect the middle point to the voltage follower, its output replaces ground on the differential amplifier gain resistor that is normally grounded. This moves your zero current point up to mid-scale, which will allow you to measure both positive and negative currents.

      BTW- you can usually "hack" a WiFi module that uses a "F" style PCB trace antenna to add a SMA connector for an antenna. On the receiver side, use a high gain/power USB WiFi adapter that has a directional or long omni-directional high gain antenna. You can also use a Yagi if you only have one thing to look at.

      If your enclosure is sealed up airtight, drill a small (.030") hole in the very bottom to create a weep hole. This will prevent condensation build up.

      Good luck!

      I am a complete electronics newbie but I have got to have a go at making this. To help me can you give me the Digikey part number for the Cap Alum 100uF's you used. Thanks

      What is the timing of photos "... taking 1 per photo"?

      Have you considered using WiFi to auto-download photos?

      2 replies

      I meant to say 1 photo taken per day. I wnated to allow of operation beyond Wifi range.

      Thanks. Very nice project!! I'd buy one. :-)

      Very cool project. Can you tell me the total cost of the poject and how much time it took to complete? Thanks,

      1 reply

      I estimate cost at $30-$50. The work was done over several weeks with a good deal of trial and error. I replicate is probably a weekend project,

      very good job but I don't know why you aren't use arduio or esp32 instead raspberry pi

      1 reply

      A Raspi zero is $5 at Micro Center near me and clone Camera module about $7 on AliExpress.

      You did a terrific job describing your project! My favorite part is your battery life run time tests. That's a real bonus to an already stellar instructable.

      1 reply

      Thanks. While I know the method isn't completely representativre of "real world," it's still seems useful.