ESP32-CAM Low Power Trail Camera

I’ve been spending a lot of time lately working with the ESP32-CAM module. It doesn’t produce the best pictures I’ve seen, but for the cost (I’ve found them for $9, including the OV2640 camera!) and the number of features and horsepower, they’re tough to beat.

One of the things I want to do with them is put a couple outside and get pictures of the different kinds of animals that wander through the yard and leave footprints in the snow. When I mentioned this to a buddy of mine, he immediately wanted to know if they could be used to watch for motion and take pictures in case someone was trying to break into his shed or cabin. Sure, I told him – I didn’t see any reason why not. His response was to immediately ask me how many I could make for him and how quickly I could do it.

Unfortunately, it was just an idea at the time and I hadn’t actually tried to do it. I figured it wouldn’t be too tough – after all, the ESP32-CAM AI-Thinker modules I use have several GPIO pins broken out. I was wrong.

Turns out some of the GPIO pins are used by the camera, and the rest are used by the uSD card slot that’s on the board. One of them (D4) seems to be used by BOTH the camera (camera flash) and the uSD card slot (data line).

I tried a bunch of things and didn’t have much luck, and when I looked around for information, there were lots of links but I couldn’t find any information that quite fit what I was doing.

Finally, I found a link to some ESP documentation, which got me started. Looking into the various ESP libraries for the SD card, using a FAT32 filesystem, the camera, and the on-board EEPROM took a while but after I figured one or two of them out, the others were easier.

After going through my various parts bins, I cobbled together a circuit that seems to reliably work. Here’s the schematic of the whole thing:

Trailcam v1 schematic

+V on the schematic is the power supply you want to use. Power for the ESP32 first goes to an AMS1117-3.3 regulator. According to the AMS1117 datasheet, it will run to where the input is only 1V higher than the output. The output is 3.3V, so it should be able to run down to 4.3V. The absolute maximum input voltage is 15V, so powering it from 4xAA/4xC/4xD alkaline batteries (6V) is fine. Even 9 or 12V should be OK, but check the regulator on your board first to make sure.

Remember that if you want to power it from rechargeable NiCd or NiMH batteries, those are 1.2V, not 1.5V, so you’d probably want to use five of them, instead of four alkalines. Same with those long-life lithium batteries – they’re 1.2V too.

The block labelled “OPTIONAL” is there if you want a switch that will keep the MOSFET (and ESP) turned on while programming. You can also just move the ESP GND pin from the MOSFET drain to ground while programming. Or… if your PIR will remain on while motion is present, you can just wave your hand above the sensor until programming is done. That’s what I do.

R1 and R2 are necessary, particularly if you have a MOSFET with a high input capacitance. They keep the MOSFET gate from momentarily pulling a large amount of current which could damage the PIR or ESP.

Why the 4N37? Because the ESP is not connected to the ground rail when the MOSFET is turned off, so GPIO13 does a very noisy “high-ish” float which leads to unpredictable results. Note that the 4N37 diode side circuit goes from GPIO13 to the anode, the cathode goes to R3, and R3 goes back to the GND pin on the ESP – NOT the ground rail from the power supply!

This circuit works best with low-Vf Schottky diodes that can tolerate a reverse voltage at least 2x the highest possible voltage in your circuit. Tested and works with BAT41 and 11DQ06. Tested and works with old-school 1N34 germanium diodes (but I probably wouldn’t use them for real-world applications). It seems to mostly work but not as reliably with typical 1N914 and 1N4001 diodes. It does NOT work with anything with a Vf larger than about a volt, like LEDs.

This circuit also works best with MOSFETs that are fully on at a low voltage, like 2.5 to 4.5V, and have a very low drain-source resistance when on (tens to a couple hundred milliohms). Tested and works with IRLI640G and DMN1019USN-7.

Normally I’d put bypass capacitors across the 5V and GND pins of the ESP, but here’s the ESP32-CAM power circuit:

ESP32-CAM power supply circuit
From: https://github.com/SeeedDocument/forum_doc/raw/master/reg/ESP32_CAM_V1.6.pdf

Note the abundance of capacitors, which is pretty great. A 0.1uF capacitor probably wouldn’t hurt, but I don’t think it’s necessary unless you’re using a very noisy power supply.

So that’s the schematic. Breadboarded up, this is how it looks:

Trailcam v1
That loose wire is connected to GPIO0 and is connected to GND to program the ESP32
Trailcam v1
That little chunk of PCB with a blue wire on it is a nasty but functional tiny-surface-mount-to-breadboard converter

Here’s how it works:

  • When power is applied to the circuit, the gate of the MOSFET is low and doesn’t conduct, so the ESP is disconnected from the ground rail. The circuit pulls about 16uA at this time.
  • When the PIR sensor detects motion, its trigger pin goes high for two seconds. This signal is sent through a diode and 47k resistor to the gate of the MOSFET, which turns it on.
  • With the MOSFET turned on, the ESP now has power and boots. As soon as it can, it sets GPIO13 high. This turns on the input of a 4N37 optoisolator, which turns on its output transistor. The output transistor is also connected to the gate of the MOSFET through a diode and a 47k resistor. This keeps the MOSFET turned on even after the PIR trigger line goes low.
  • The ESP goes through the paces of checking for and mounting the uSD card, starting up the camera, and checking the EEPROM and reading the number from it that indicates the last picture that was taken (PIC_COUNT) prior to the previous shutdown.
  • If there is a problem at any point in the startup, the ESP will set GPIO13 low, which will turn it off and wait for the next trigger to boot again. I know it’s 2020, but sometimes a reboot still fixes things.
  • If there are no problems, it gets to the main loop, which takes the number of pictures specified by a while loop that increments the variable COUNTUP (in the program here it takes five pictures). Each time through, the picture counter (PIC_COUNT) is increased by 1. The circuit pulls about 130-140mA at this time.
  • Once COUNTUP reaches the maximum set in the while loop, the ESP saves the current value of PIC_COUNT to the EEPROM and then sets GPIO13 low. This should turn off the MOSFET and remove power from the ESP.
  • If there is still power, the ESP waits for 500ms after it tried to shut itself down. If it’s still awake, then that means the PIR has either re-triggered or is still triggered so it’s a good idea to get more pictures. The ESP sets GPIO13 high again and loops back to take another five pictures.

Here’s what it looks like when it’s running. Note the camera flash LED on the board glowing faintly instead of blazing like a million suns like it usually does. When the LED is on, the ESP is communicating with (and hopefully writing an image to) the uSD card.

You may be wondering why it works, though. After all, there don’t seem to be any usable free GPIOs when using both the camera and the uSD card, so what’s with GPIO13? Well, it comes down to changing this line:

SD_MMC.begin("/sdcard")

to this:

SD_MMC.begin("/sdcard",true)

Selecting “true” tells the ESP to talk to the uSD card in 1-bit mode instead of the usual 4-bit mode. This frees up a couple of GPIO pins, one of which is GPIO13. The disadvantage to using 1-bit mode is that it’s slower, but I’m pretty sure the ESP itself is going to be the bottleneck here. Plus, the OV2640 and lens aren’t super-high quality so setting the JPEG image quality high and making huge files isn’t necessary (or useful).

Here’s the program in its entirety (it looks kind of mangled but if you copy and paste it into a text document or the Arduino IDE it comes out properly):

/* ESP32-CAM Low Power Trail Camera v1
 * Mark's Bench (http://marksbench.com)
 * Uses ESP32-Cam AI-Thinker with OV2640 camera to take pictures and save to SD card when triggered by PIR
 * ESP32 is connected to power rail via MOSFET. MOSFET is initially turned on by PIR trigger and kept on by setting pin D13
 * on the ESP32 high as soon as ESP starts up.
 *  
 * ESP then takes 5 pictures and saves them to the SD card, after which it sets D13 low, which turns the MOSFET off,
 * cutting the ESP off from the GND rail.
 * 
 * If the PIR trigger remains high or goes high again during when the ESP32 would shut down, then take another five
 * pictures and try shutting down again.
 * 
 * Advantage to this scheme is a power savings - power draw is less than 20uA when the MOSFET
 * is off and the ESP32 is shut down. Power draw is around 130-140mA when pictures are being taken and saved.
 * 
 * Disadvantage is that when using both the camera and the SD card, there are no easily usable GPIO pins available.
 * To get around this, use 1-bit SD card access instead of the usual 4-bit. 
 * It slows things down but you can still get an image with ok quality about once a second
 * at full resolution (1600x1200) on the OV2640.
 * 
 * 
 * Information on and code examples for using the ESP32-CAM library:
 * https://github.com/yoursunny/esp32cam
 * https://github.com/espressif/esp32-camera
 * https://github.com/espressif/arduino-esp32/tree/master/libraries/ESP32/examples/Camera/CameraWebServer
 * 
 * Information on and code examples for using the ESP32 SD_MMC library:
 * https://github.com/espressif/arduino-esp32/tree/master/libraries/SD_MMC
 * 
 * Information on using the ESP32 EEPROM (the Preferences library):
 * https://github.com/espressif/arduino-esp32/tree/master/libraries/Preferences
 * 
 * VERY useful ESP32 documentation:
 * https://www.espressif.com/en/support/download/documents
 * In particular, the "ESP32-WROOM-32 Datasheet", "ESP32 Datasheet", and "ESP32 Hardware Design Guidelines".
 * Also, the schematic at:
 * https://github.com/SeeedDocument/forum_doc/raw/master/reg/ESP32_CAM_V1.6.pdf
 * And the specification page (which has some errors) at:
 * https://github.com/raphaelbs/esp32-cam-ai-thinker/blob/master/assets/ESP32-CAM_Product_Specification.pdf
 * 
 * 
 * ***TO PROGRAM: Set Board to "AI Thinker ESP32-CAM"***
 */

 
#include <esp_camera.h>
#include <FS.h>
#include <SPI.h>
#include <SD_MMC.h>
#include <Preferences.h>

// The ESP32 EEPROM library is deprecated. Use the Preferences library instead.
Preferences preferences;

// The following defines are for the ESP32-Cam AI-THINKER module only. I haven't tried any others.
#define CAM_PIN_PWDN    32
#define CAM_PIN_RESET   -1
#define CAM_PIN_XCLK    0
#define CAM_PIN_SIOD    26
#define CAM_PIN_SIOC    27
#define CAM_PIN_D7      35
#define CAM_PIN_D6      34
#define CAM_PIN_D5      39
#define CAM_PIN_D4      36
#define CAM_PIN_D3      21
#define CAM_PIN_D2      19
#define CAM_PIN_D1      18
#define CAM_PIN_D0       5
#define CAM_PIN_VSYNC   25
#define CAM_PIN_HREF    23
#define CAM_PIN_PCLK    22


// Create a variable to hold the picture number. Since the SD card is formatted FAT32, the maximum number of files
// there can be is 65534, so a 16-bit unsigned number will be fine.
uint16_t PIC_COUNT = 0;

void setup(){
  pinMode(13, OUTPUT);    // GPIO13 available when using SD_MMC.begin("/sdcard",true) for 1-bit mode (set below)
  digitalWrite(13, HIGH); // Hold the gate of the MOSFET high as soon as possible after boot to keep the power on
                          // after the PIR is done triggering.
                          
  //Serial.begin(115200); // Uncomment for troubleshooting

  preferences.begin("trailcam", false); // Open nonvolatile storage (EEPROM) on the ESP in RW mode
  PIC_COUNT = preferences.getUShort("PIC_COUNT", 0);  // Get the stored picture count from the EEPROM.
                                                      // Return 0 if it doesn't exist.
                                                      // getUShort() fetches a 16-bit unsigned value

  // Now, configure the camera with the pins defined above and recommended settings for xclk, led_c, and format.
  camera_config_t config;
  config.pin_d0 = CAM_PIN_D0;
  config.pin_d1 = CAM_PIN_D1;
  config.pin_d2 = CAM_PIN_D2;
  config.pin_d3 = CAM_PIN_D3;
  config.pin_d4 = CAM_PIN_D4;
  config.pin_d5 = CAM_PIN_D5;
  config.pin_d6 = CAM_PIN_D6;
  config.pin_d7 = CAM_PIN_D7;
  config.pin_xclk = CAM_PIN_XCLK;
  config.pin_pclk = CAM_PIN_PCLK;
  config.pin_vsync = CAM_PIN_VSYNC;
  config.pin_href = CAM_PIN_HREF;
  config.pin_sscb_sda = CAM_PIN_SIOD;
  config.pin_sscb_scl = CAM_PIN_SIOC;
  config.pin_pwdn = CAM_PIN_PWDN;
  config.pin_reset = CAM_PIN_RESET;
  config.xclk_freq_hz = 20000000;
  config.ledc_timer = LEDC_TIMER_0;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.pixel_format = PIXFORMAT_JPEG;
  
  // Make sure there is PSRAM available (the AI-Thinker module has PSRAM). Otherwise, don't go any further.
  if(psramFound()){
    config.frame_size = FRAMESIZE_SXGA; // If there's PSRAM then there's enough memory to capture up to 1600x1200
                                        // The following resolutions are available:
                                        // 96x96 (96x96)
                                        // QQVGA (160x120)
                                        // QQVGA2 (128x160)
                                        // QCIF (176x144)
                                        // HQVGA (240x176)
                                        // 240x240 (240x240)
                                        // QVGA (320x240)
                                        // CIF (400x296)
                                        // VGA (640x480)
                                        // SVGA (800x600)
                                        // XGA (1024x768)
                                        // SXGA (1280x1024)
                                        // UXGA (1600x1200) **Full-resolution for OV2640
                                        
    config.jpeg_quality = 10; // Valid: 0-63, with 0 being highest quality and largest file size.
                              // Anything lower than 8 creates large file sizes that take a long time 
                              // to save to the SD card. 
                              // The camera and lens aren't the best quality, so huge files
                              // won't get you a better picture beyond a certain point.
    config.fb_count = 2;  // With the PSRAM, there's enough memory for two framebuffers, which speeds captures.
  }
  else{
    while(true){
      // The AI-Thinker module has PSRAM. I haven't tried any module without PSRAM.
      //Serial.println("NO PSRAM FOUND"); // Uncomment for troubleshooting
      delay(500);
    }
  }

  // Start up the camera with the configuration settings made earlier in the "config." statements.
  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK){
    // If we're here, there's a problem communicating with the camera.
    // Turn the ESP off and wait for the next trigger.
    digitalWrite(13, LOW);
    //Serial.println("CAM FAIL"); // Uncomment for troubleshooting
    while (true){
      // Need this loop to wait in case the PIR is keeping the power on.
    }
  }

  // Start up the SD card, using 1-bit xfers instead of 4-bit (set the "true" option). Frees up GPIO13.
  if(!SD_MMC.begin("/sdcard",true)){
    // If we're here, there's a problem with the SD card.
    // Turn the ESP off and wait for the next trigger.
    digitalWrite(13, LOW);
    //Serial.println("SD FAIL 1");  // Uncomment for troubleshooting
    while (true){
      // Need this loop to wait in case the PIR is keeping the power on.
    }
  }

  // Query the card to make sure it's OK
  uint8_t SD_CARD = SD_MMC.cardType();
  if(SD_CARD == CARD_NONE){
    // If we're here, there's a problem with the SD card.
    // Turn the ESP off and wait for the next trigger.
    digitalWrite(13, LOW);
    Serial.println("SD FAIL 2");  // Uncomment for troubleshooting
    while(true){
      // Need this loop to wait in case the PIR is keeping the power on.
    }
  }  
}


// We are now done the setup and should be ready to take pictures in the main loop() function.

void loop(){
  uint8_t COUNTUP = 0;  // Create variable to take multiple pictures.
  while (COUNTUP <=4){  // Take 5 pictures before shutting down.

    // Take picture and read the frame buffer
    camera_fb_t * fb = esp_camera_fb_get();

    if (!fb){
      // If we're here, there's something wrong with the data in the frame buffer.
      // Turn the ESP off and wait for the next trigger.
      digitalWrite(13, LOW);
      while(true){
        // Need this loop to wait in case the PIR is keeping the power on.
      }
    }

    // If we're here, the image was captured. Begin the process to save it to the SD card.
    // First, create the file name and path. Currently set to make files like /pic123.jpg
    String path = "/pic" + String(PIC_COUNT) + ".jpg";
    
    fs::FS &fs = SD_MMC;

    // Now, create a new file using the path and name set above.
    File file = fs.open(path.c_str(), FILE_WRITE);
    if(!file){
      // If we're here, there's a problem creating a new file on the SD card. 
      // Turn off the ESP and wait for the next trigger.
      digitalWrite(13, LOW);
      while(true){
        // Need this loop to wait in case the PIR is keeping the power on.
      }
    } 
    else 
    {
      // If we're here, the file was created. Now write the captured image to the file.
      file.write(fb->buf, fb->len); 
      PIC_COUNT = PIC_COUNT + 1;  // Increment the picture count number each time there's a successful write.
      if(PIC_COUNT >=65500){
        PIC_COUNT = 0;  // FAT32 has a limit of 65534 files in a folder
      }
    }
    file.close(); // Done writing the file so close it.

    // Free the memory used by the framebuffer so it's available for another picture
    esp_camera_fb_return(fb);

    COUNTUP = COUNTUP + 1;  // We are done an image capture cycle. Increment the count.
  }
  

  // If we're here then we've taken the pictures and we are ready to shut down. Write the current file number to
  // the EEPROM, then set D13 low.
  preferences.putUShort("PIC_COUNT", PIC_COUNT);  // Store the picture count number in the EEPROM
  // Normally you'd want to do a preferences.end() to properly close the EEPROM but since the intent is to
  // shut the ESP down, it's not needed, and not having to open and close it every capture cycle speeds things
  // up and saves some wear on the EEPROM.

  //Serial.println("Shutting down."); // Uncomment for troubleshooting
  digitalWrite(13, LOW);
  delay(500);
  
  // The ESP should be shut down at this point. If the PIR is still triggered or has re-triggered and is keeping
  // the MOSFET on, then set D13 high and allow the program to loop again to take another five pictures.
  digitalWrite(13, HIGH);
  //Serial.println("Looping back.");  // Uncomment for troubleshooting


}

Hopefully there are enough comments to make heads or tails of it. A few notes:

  • This is for the AI-Thinker module with the OV2640 camera only. It’s the only one I’ve tried. It will probably work with other models of ESP32-CAM, but you will need to check the #define for each pin, see how much of what kinds of storage are available, and what settings the camera you’re using requires.
  • The ESP32 Arduino-compatible “EEPROM” library is deprecated; the new way to do things is with the “Preferences” library.
  • Before programming, set the board type to “AI Thinker ESP32-CAM”. Again, this is for the AI-Thinker module only.

If you’re looking for documentation on the ESP32-CAM or the libraries I used to get this working, it’s all in the following links. For the libraries, be sure to check out the examples and .h files for options and how various things work:

I haven’t put it outside yet, but as a test of the ESP and circuit, I changed the program so the ESP would take and save as many 1600×1200 JPEGs at compression level 9 as quickly as possible. The circuit was powered by four grocery-store branded AA alkaline batteries that were unused but of unknown age. It ran for 16 hours 21 minutes and took 23475 pictures before the batteries died. Not bad!

I know there is a lot of room for improvement – both in the circuit and in the program. When building this, I was limited to what I had on hand – a P-channel MOSFET might be a better choice, and I’m sure there’s a better way to do things than with the 4N37. For now, though, I’m pretty happy that it works reliably. Now I need to put it in a box and get some pictures of those critters in the yard.

If you made it this far, congratulations! If you build this or have a better way to do this, I’d be curious how it turned out! Feel free to drop a comment here or send me a message using the contact form!

30 thoughts on “ESP32-CAM Low Power Trail Camera”

  1. Mark, thank you for sharing your experience with ESP32 and a cam-module. That is interesting; I think I will try playing with it too. Thank you for sharing!

    1. Hello Roman – thanks for the comment!

      Most of my tinkering nowadays is with the typical Arduinos but the ESP32 has been really growing on me. For the price, it has a lot of power and many features, and I really like having all of that memory and horsepower to work with!

      If you do decide to give it a shot, good luck! I hope it works out well for you!

    2. I am a newbie, I would appreciate more simple direction kind Sir. Could you please provide the exact name or link to the capacitors you are using. The picture is good but I cannot see the band colors to find the resistor or capacitor types you are using. I also see a possible capacitor soldered from the esp32 negative connector that is a brown square on the bread board not mentioned? Maybe edit the picture in windows paint or (snipping tool) and draw an arrow matching the capacitor type or color band.
      I also would like to know in your opinion. Is this worth my time or is it better to purchase a cheap trail camera. I am a very traditional and do not need all the bells and whistles, All I want is a long battery life and still pictures you can see if it is a buck or doe with a good motion sensitivity range. I also do not need night pictures and I will make a on off light sensor switch. I can also forgive the common hiccup delays once in a while for such a cheap ESP32 unit.

      1. Hi BlueSkys!

        All of the component values are listed in the schematic (the hand-drawn one). The resistors are all 1/4W. The brown square on the breadboard is actually the MOSFET – it’s a little surface mount one, so I soldered it to a piece of PCB and put some pins on it so I could use it on a breadboard.
        As for whether it’s worth your time, that’s really up to you. Keep in mind that the ESP32-CAM is a ten dollar part that comes with a camera, so the quality of the images probably won’t match those of a cheap trail cam. However, using the ESP also gives you some flexibility to put the camera wherever you want and into whatever kind of enclosure or hiding spot you’d like. It also has the advantage that if something happens to it and it’s ruined or you lose it, you’re out a lot less money.
        I also find it gratifying to build something that works, so if you are like that too then why not go ahead and build it? You can always use the parts for something else if you’re not happy with it down the road.

        Thanks for the comment!

  2. Nice work, cool to see a power switch circuit that actually works and seems to work quite well! I’d suggest using AP2114 instead of AMS1117 – it’s a drop-in replacement with much better parameters (you can just desolder AMS1117 and solder in the AP2114), its drop-out voltage is much lower than 1V, so it can empty out the batteries better (or perhaps let you use less batteries). Also, it’s very cheap and easy to get.

    1. Hi Arsenijs!

      That’s a great idea – any way of improving the efficiency and squeezing a bit more life out of the batteries makes this more useful. I’m going to try doing that with one of my ESPs soon.

      Thanks for the comment!

  3. Hello, this is really the thing I was hoping for somebody will do. Is some pcb drawing available or on your TO-DO list? I would definitely build this one in a few pieces to see who is stealing my fire wood from our cottage.

    1. Hello Owar!

      Unfortunately I don’t have a PCB layout for this yet but it is on my list for sometime in the future. If you have a weatherproof container, just breadboarding it should be good enough for a while. You can also buy pre-made PCBs that are laid out just like breadboards, so you could always do it up on a breadboard first, then if you’re happy with it, transfer it to the pre-made PCB and solder it in.

      Thanks for the comment, and good luck catching the firewood thief!

  4. Pingback: Shadow news
  5. I’ve been thinking about putting together a time lapse cam with this same board, which I bought last year and haven’t touched since. I’ve bookmarked this. I’ve got over 100 slightly used AA batteries to work with, so I could make it last a nice long time.

    1. Hey Ryan!

      Thank you for the comment! I was surprised how long the ESP lasted on the batteries, if you’ve got over 100… well, you might fill up the SD card before the batteries fail. 🙂

  6. Hey! thanks a ton for sharing this project. I really like your style of describing a design. e.g. indicating which parts worked, and which didn’t. The challenges you faced and how you overcame them. And, honesty about the limitations. The step-by-step “how it works” makes everything clear. Excellent.

    1. Hi Mike!

      Thanks for the comment and the kind words! I’m a big fan of documenting projects so when I come back to it in a month or two I don’t have to figure it out all over again. 🙂

      Have a good day!

    1. Hi Curt!

      The PIRs that I used with this project have an AS312 sensor. I’m not sure if it’ll help with your project, but sometimes what I’ve done when getting a lot of triggers outside is make a cardboard or plastic cone and put the sensor in it like one of those dog cones the vets use. Depending on how wide an area you want to keep track of, you can even put it at the back of a short tube.

      Good luck and thanks for the comment!

  7. Hi Mark, thanks for sharing your design – I have been looking for something like this for quite a while. My simple project is quite different -ESP32S Dev board with HC-SR04 to take a daily distance measurement and using deep sleep for 23h a day to conserve power – which is working flawlessly). Being able to use AA batteries to power the ESP32S would make my project much more practical.
    I am hoping to use the principles of your power design, but wondering if you could advise on how I would adjust it for my project? For example, I don’t need the PIR, so not sure of the impact of removing that.
    Any help would be greatly appreciated.

    1. Hello Barry!

      Anything that will present a high enough voltage on the gate of the MOSFET for long enough for the ESP32 to boot and assert control over the GPIO line should work. The trick will be finding something that will use less power than the ESP32’s deep sleep mode, while giving you the timing accuracy you need for your project. Something like a 555 already pulls way more current than the ESP32 does, so that’s out. Some of the 12F series of PIC microcontrollers are very good at sipping tiny amounts of current while still counting but off the top of my head I’m not sure how they compare to the ESP32’s deep sleep.

      Are there any other things in the environment where your project sits that could be used to help? Foot traffic at a particular time, sound, light levels… there may be a way to use something like that to trigger your circuit.

      Thanks for the comment – good luck with your project!

  8. Hi Mark, thanks for the great write up.

    If switching the USD card to 1 bit mode frees up a few IO pins, wouldn’t that then allow you to use the PIR sensor directly on one of those pins to wake the ESP32 from deep sleep mode?

    1. Hello Pete!

      You’re absolutely right – as long as the output of your PIR is no more than 3.3V, you can use it to trigger one of the RTC GPIO pins. GPIO13 is one of the pins that is freed up with 1-bit mode, and if I’m reading things right, it’s also connected to RTC GPIO14. That would simplify the circuit but it would still take about the same amount of time to respond when it detects motion, and it would use a bit more power when idle. An extra 10-100uA isn’t too bad, though!

      Thanks for the comment!

  9. Hi Mark, thanks for sharing. Your circuit works, but I want to run a some other bits (solenoid IR Cut Filter (using small motor controller), and IR LED ring (300ma load when on)), but I find as soon as I connect the ESP32 cam (on its own), the voltage drops to circa 1.5V (measuring VCC / grnd on ESP32)? Have I done something wrong?

  10. I am not an electronics genious, but 47K seems like a really high value for the gate resistor. The data sheet uses an example value of 4.6 ohm?

  11. I think the 3.3v from the PIR (HC-SR505) trigger is not enough to fully drive the gate hard on. Will try adding another 4N37 on the PIR trigger to raise the voltage up to circa 8v..

  12. I built something like this in the past. with they help of that guy that makes tutorials on esp32 with his girlfriend. think his name was Rio

    I am going to make a simple esp32 cam thats battery powered. I will start with the power source this time around. I am thinking the 14430 Lifpo4 batteries will be what I use.

    Not sure where to find a battery holder however. May just have to make one 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

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