ESP32 Trail Camera Goes The Distance On AA Batteries

There’s no shortage of things to like about the ESP8266 and ESP32, but if we had to make a list of the best features these WiFi-enabled microcontrollers have to offer, their power management capabilities would certainly be near the top. Which is how we assumed [Mark] was able to take a whopping 23,475 pictures on his ESP32 camera while powered by nothing more exotic than four AA batteries from the grocery store.

But as it turns out, the full story is quite a bit more interesting. As far as we can tell, [Mark] isn’t bothering with the ESP32’s sleep modes all. In fact, it looks like you could pull this trick off with whatever chip you wanted, which certainly makes it worth mentally filing away for the future; even if it depends on a fairly specific use case.

In the most simplistic of terms, [Mark] is cutting power to the ESP32 completely when it’s not actively taking pictures. The clever circuit he’s come up with only turns on the microcontroller when a PIR sensor detects something moving around in front of the camera. Once the chip is powered up and running code, it brings one of its GPIO pins high which in turn triggers a 4N37 optoisolator connected to the gate on the circuit’s MOSFET. As long as the pin remains high, the circuit won’t cut power to the ESP32. This gives the chip time to take the requested number of pictures and get everything in order before bringing the pin low and allowing the circuit to pull the plug.

If you’re looking to maximize runtime without wrangling any MOSFETs, we’ve seen some excellent examples of how the low power modes on the ESP8266 and ESP32 can be put to impressive use.

[Thanks to Jason for the tip.]

34 thoughts on “ESP32 Trail Camera Goes The Distance On AA Batteries

  1. That is very neat the only trouble I see is the length of time between detection and taking a photo, I didn’t time it but it seems to be around 1sec which unfortunately a bit too long. I use a number of trail cams for security purposes and find the 0.3secs they claim is often too long.

    That’s not to say this is a great implementation.

    1. I still have a copy of “Getting Started In Electronics” in the basement. Well, most of it, anyway – it saw a lot of use back in the early 80s… I’ve always liked the way Forrest Mims drew stuff up.

  2. I have that exact same board, and over 100 slightly used AA’s. The batteries would die of old age before running out! I wonder if there’s a way to use an RTC circuit to trigger an hourly wake up instead?

    1. On ESP8266, gpio15 for wakeup.
      do not launch wifi to gain autonomy, when you need WiFi, use the parameters of the last connection to reduce the power consumption by 50%

    1. – Whenever I see a circuit using opto without actually requiring isolation, it tells me that the person have no idea how to do proper level shifting.
      – IO0 can be grounded while Q1 is not enabled leading to current conducting through ESD diode at IO0
      – R4 can be moved to gate of Q1 and R1, R2 and R5 can be eliminated. Q1 is a MOSFET, so it doesn’t require a base resistor to limit current as in the case of a bipolar transistor.

      1. – use a large value for R4. It just need to be large enough to counter the leakage current of the schottky.
        – In the case of IO0, either tie the ground side of the switch to GND pin of ESP32 or at least put a resistor in series to the IO0 pin.

      2. Good point about the resistors – simpler is better, for sure!

        Despite the very few available pins on the ESP32-CAM, I try to stay away from using IO0 for anything other than setting the ESP to programming mode – hence the switch.

        As for the 4N37, I’m not level shifting with it. It’s tied to the GND pin of the ESP (not GND of the whole board) because when the ESP first starts up the pins are in an uncertain state and the signal from the ESP needs to stay off until it boots and takes control of IO13 properly. If the 4N37 is tied to the board ground, it makes the cct (through IO13, ouch) and the ESP gets stuck in a never-boot loop.

        And, like I said in my post, there are better ways to do it but it’s what I had on hand at the time.

        1. You can use a pass transistor for level shifting. (in Cascode commonly used for level shifting)
          P-MOSET: Source to IO13, gate to GND on ESP and drain as output.
          PNP:E to IO13, B with a series resistor to GND on ESP and C as output.

          1. Heh… in my post I actually said “When building this, I was limited to what I had on hand – a P-channel MOSFET might be a better choice”.

            But that’s cool – I appreciate you sharing your knowledge!

      1. The whole system behavior may depend on how fast it takes for the gate charge to leak out – without a pulldown it takes a while. You may even want to add extra capacitance there to control how long it takes to turn off, so you can power down your MCU cleanly before it browns out.

        It can sometimes lead to weird issues like flash corruption, because the CPU executes random commands as it shuts down – which is why it should have the BOD circuitry enabled that shuts it down cleanly when it detects the power supply going down.

      2. Yes, a pulldown resistor is advisable.

        So, the PIR sensor gives you a long enough pulse to reliably hold the ESP32 on long enough for the firmware to latch on with the 4N37?

        btw the opto-coupler is not a terrible thing; it works, and low parts-count!

  3. If you’re interested in circuits like this, then also check out the ubiquitous transistor tester with atmega328 and LCD. It uses BJT’s instead of MOSfets because of lower leakage. I could not really measure leakage current as it’s below my measuring thresshold of a few hundred nA (At room temperature).

  4. average AA battery’s capacity being 1473 mWh (Great AA Alkaline Battery Test – Pt 3 by lui_gough) means the approximate energy for each 1600*1200 photo saved was 250 microWatt-hours

Leave a Reply to elmesitoCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.