ESP32-CAM PIR Motion Detector with Photo Capture (saves to microSD card)

Содержание

In this project, we’re going to make a motion sensor detector with photo capture using an ESP32-CAM. When your PIR sensor detects motion, it wakes up, takes a photo and saves it in the microSD card.

ESP32-CAM Motion Detection with Photo Capture (saves to microSD card)

This project is very similar with a previous one, but after so many requests, we added a PIR motion sensor to the circuit. So, when motion is detected a picture is taken and saved on the microSD card.

Other ESP32-CAM projects and tutorials:

We have a similar project using a Raspberry Pi and a camera module:

Watch the Video Tutorial

You can watch the video tutorial or continue reading for the complete project instructions.

Parts Required

For this project, you’ll need the following parts:

  • ESP32-CAM with OV2640 – read Best ESP32-CAM Dev Boards or power bank (optional)

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Project Overview

ESP32-CAM Motion Detector with Photo Capture Project Overview

Here is a quick overview on how the project works.

  • The ESP32-CAM is in deep sleep mode with external wake up enabled.
  • When motion is detected, the PIR motion sensor sends a signal to wake up the ESP32.
  • The ESP32-CAM takes a photo and saves it on the microSD card.
  • It goes back to deep sleep mode until a new signal from the PIR motion sensor is received.

Formatting MicroSD Card

The first thing we recommend doing is formatting your microSD card. You can use the Windows formatter tool or any other microSD formatter software.

1. Insert the microSD card in your computer. Go to My Computer and right click in the SD card. Select Format as shown in figure below.

Formatting your microSD card Windows

2. A new window pops up. Select FAT32, press Start to initialize the formatting process and follow the onscreen instructions.

Formatting your microSD card Windows

Note: according to the product specifications, the ESP32-CAM should only support 4 GB SD cards. However, we’ve tested with 16 GB SD card and it works well.

Installing the ESP32 add-on

We’ll program the ESP32 board using Arduino IDE. So, you need the Arduino IDE installed as well as the ESP32 add-on:

ESP32-CAM Take Photo with PIR Sketch

Copy the following code to your Arduino IDE.

This code is very similar to one of our previous ESP32-CAM projects, but it enables external wake up on GPIO 13.

To learn more about the code, go to the following project:

ESP32-CAM Upload Code

To upload code to the ESP32-CAM board, connect it to your computer using an FTDI programmer. Follow the next schematic diagram:

Many FTDI programmers have a jumper that allows you to select 3.3V or 5V. Make sure the jumper is in the right place to select 5V.

Important: GPIO 0 needs to be connected to GND so that you’re able to upload code.

ESP32-CAM FTDI Programmer
GND GND
5V VCC (5V)
U0R TX
U0T RX
GPIO 0 GND

To upload the code, follow the next steps:

1) Go to Tools Board and select AI-Thinker ESP32-CAM.

2) Go to Tools Port and select the COM port the ESP32 is connected to.

3) Then, click the upload button to upload the code.

4) When you start to see these dots on the debugging window as shown below, press the ESP32-CAM on-board RST button.

After a few seconds, the code should be successfully uploaded to your board.

Schematic Diagram

ESP32-CAM with PIR Motion Sensor Circuit Breadboard

Assemble all the parts as shown in the following schematic diagram.

ESP32-CAM with PIR Motion Sensor Circuit Diagram

Thanks to David Graff for sharing the schematic diagram for this project

If you prefer, you can follow the Fritzing diagram instead.

ESP32-CAM with PIR Motion Sensor Schematic Diagram Fritzing

To prevent problems during upload, we recommend assembling the circuit only after uploading the code.

Demonstration

After uploading de code and assembling the circuit, insert a formatted microSD card and apply power to your circuit – you can use a portable charger, for example.

Powering ESP32-CAM with powerbank

Then, press the reset (RST) button, and it should start working. When it detects motion, it turns on the flash, takes a photo and saves it on the microSD card.

ESP32-CAM takes photo when detects motion with PIR sensor

Experiment with this circuit several times to make sure that it is working. Then, insert the microSD card to your computer to see the captured photos.

ESP32-CAM takes photo when detects motion with PIR sensor photo demonstration

Here’s an example:

ESP32-CAM photo example captured

Now you can finish this project the way you want, you can either use a dummy camera and insert your ESP32-CAM with the PIR motion sensor, or you can build your own enclosure.

ESP32-CAM PIR Motion Detector with Photo Capture with fake dummy camera

You can also apply the concepts learned in this tutorial in your own projects.

Troublehsooting

  • Failed to connect to ESP32: Timed out waiting for packet header
  • Camera init failed with error 0x20001 or similar
  • Brownout detector or Guru meditation error
  • Sketch too big error – Wrong partition scheme selected
  • Board at COMX is not available – COM Port Not Selected
  • Psram error: GPIO isr service is not installed
  • Weak Wi-Fi Signal
  • No IP Address in Arduino IDE Serial Monitor
  • Can’t open web server
  • The image lags/shows lots of latency

[eBook] Build ESP32-CAM Projects using Arduino IDE

Learn how to program and build 17 projects with the ESP32-CAM using Arduino IDE DOWNLOAD »

Learn how to program and build 17 projects with the ESP32-CAM using Arduino IDE DOWNLOAD »

Wrapping Up

We hope you’ve liked this project. For more ESP32-CAM projects you can subscribe to our newsletter. If you don’t have an ESP32-CAM yet, you can get one for approximately $6.

If there is any project you’d like to see with the ESP32-CAM or if you’d like to share your project with us, write a comment in the comment’s section below.

We have more projects and tutorials about the ESP32-CAM that you may like:

Thank you for reading.

[eBook] Build Web Servers with ESP32 and ESP8266 (2nd Edition)

Build Web Server projects with the ESP32 and ESP8266 boards to control outputs and monitor sensors remotely. Learn HTML, CSS, JavaScript and client-server communication protocols DOWNLOAD »

Recommended Resources

Build a Home Automation System from Scratch » With Raspberry Pi, ESP8266, Arduino, and Node-RED.

Home Automation using ESP8266 eBook and video course » Build IoT and home automation projects.

Arduino Step-by-Step Projects » Build 25 Arduino projects with our course, even with no prior experience!

What to Read Next…

ESP32 ESP8266 Input Data on HTML Form Web Server using Arduino IDE

Input Data on HTML Form ESP32/ESP8266 Web Server using Arduino IDE

ESP32 Web Server – Arduino IDE

ESP8266 NodeMCU Send Emails using an SMTP Server HTML Text and Attachments Arduino IDE

ESP8266 NodeMCU Send Emails using an SMTP Server: HTML, Text, and Attachments (Arduino)

Enjoyed this project? Stay updated by subscribing our newsletter!

148 thoughts on “ESP32-CAM PIR Motion Detector with Photo Capture (saves to microSD card)”

Thank you for this,keep it up!
best regards from saxonia,Germany 👌😀

You’re welcome!
Regards,
Sara

Hello Sara
can i combine sms and picture transmission by your ESP8266 Multisensor Shield with Node-RED project that uses mqtt?
thanks vm
areza alikhani

Sara and Rui, your ESP32 Cam book is great!

Hi.
Thank you.
We’re glad you liked it!
Thank you so much for supporting our work 😀
Regards,
Sara

Hello Sara,
I can not combine ESP32-CAM Take Photo and Display in Web Server project with the ESP32-CAM PIR Motion Detector with Photo Capture to capture and display a new photo when motion is detected.
Help me please;
Regards,
Areza

Hi
Good on you mate!
Is it possible to post the taken picture on a certain IP address?
Cheers
Saman

Hi Saman.
That will be one of our next projects.
But at the moment, we don’t have any tutorial about that.
Regards,
Sara

We are waiting for it 😉
Best regards
Piotr

I have a question, what should I do if I want to take a photo every 1 minute?

Hi.
Instead of enable deep sleep with external wake up ( esp_sleep_enable_ext0_wakeup(GPIO_NUM_13, 0);)
Enable timer wake up with 60 seconds ( esp_sleep_enable_timer_wakeup(TIME TO SLEEP IN MICROSECONDS));
Then, put the ESP32 into deep sleep: esp_deep_sleep_start();
To learn more, you can read our tutorial about deep sleep with timer wake up: https://randomnerdtutorials.com/esp32-timer-wake-up-deep-sleep/
Regards,
Sara

Hi,
That’s a really cool project !
I’ve tried it but there was a problem.
The camera doesn’t stop taking picutres.
I turn the system on and it just takes pictures on its own every 3 seconds.
Do you know what the problem could be ?

Hi.
It’s probably because the PIR motion sensor is being triggered every 3 seconds. Double check the connections of the PIR motion sensor.
To make sure the ESP32-CAM is working properly, you can try attaching a pushbutton instead of the PIR sensor and see if it works as expected.
Also, check with a multimeter if the PIR motion sensor is working as expected.
Regards,
Sara

Hi love all your articles, thought you mite like to do a project using the small e ink modules 1.5 inches type maybe thanks so much .
Jeff.

What is power consumption of this solution? How long this solution can works with 10400mAh powerbank?

Hi Ludovit.
We haven’t tested that yet.
Regards,
Sara

Just curious why you are using the elaborate setup to pull the pin low with the PIR instead of just connecting it directly and pulling it high?

Hi Jeffery.
The part of the setup() you’re referring to is to control the Flash lamp of the board, not the PIR sensor.
Regards,
Sara

How would one do this? What needs to be changed in the code? It makes more sense to do it this way.

That’s a good question. Why not just change the code to expect a high signal from the motion sensor instead of building the transistor circuit?

Is it possible to use only the ESP32-CAM as a motion sensor to send an email when it detects motion? In my case, it won’t be asleep/need to wake up, it will be on power supply and on waiting for a client to connect to stream video.

thank you. nice website.

Hi.
I’m not sure if the ESP32-CAM is powerful enough to detect motion on its own (i’ve never tried it).
Sending an image via email will be one of our next projects.
Regards,
Sara

Yes, it is possible. I realized, with due limits, a motion detector without the aid of the PIR, but processing the images (frame). The purpose was didactic and not professional, but it works 🙂
forum.arduino.cc/index.php?topic=623310.msg4299034#msg4299034

Hi Federico.
It’s very interesting.
Thank you for sharing.
Regards,
Sara

Thanks to you, my idea started from this article.
I’m sorry, it’s the Italian forum, … but the code has no nationality 🙂
Federico

Hello
Is it possible to see the camera live on node red and at the same time It take a photo if it detects movement?

Hi Fernando.
I think it should be possible, but at the moment we haven’t tried it yet.
Regards,
Sara

can the image not saved in sdcard but send to raspberry pi?
before this the esp32 must connect to raspberry pi as wireless.

Yes. It should be possible to achieve, but we haven’t taken the time to make that project yet.
We plan to do something similar soon.
Regards,
Sara

Any possibility of sending the captured image to a telegram bot? This will need wifi connection?

Hi.
We don’t have an example about that yet.
But, it can be done using the Universal Telegram Bot Library: https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot
And yes, you need wifi connection.
Regards,
Sara

Hello! Is there any substitute for the 2n3904 transistor?

The 2N3904 is a very generic small silicon NPN transistor being used as a switch. Almost any cheap silicon NPN transistor ought to work, since you’re not using it for audio or RF purposes. Amazon lists a bag of 200 of them for less than a nickel ($0.05) each

Welldone guys. Is there a way the image captured can be sent to an email address?

Hi.
Thank you!
That will be one of our next projects.
So, stay tuned!
Regards,
Sara

can the image not saved in sdcard but send to database Mysql server?

Hi.
Thank you for the suggestion.
That will be one of our future projects.
Regards,
Sara

Hello.
Is there a way to record video when it detects motion. For example, 5 minute videos….

Hello,
Is it possible to change the code because I will not be using PIR sensor. Im thinking if it is possible that the esp32 can be made to automatically take pictures once it is turn on. and take pictures every 2 seconds. What do I need to change in the Codes. thanks

Hi.
Instead of enable deep sleep with external wake up ( esp_sleep_enable_ext0_wakeup(GPIO_NUM_13, 0);)
Enable timer wake up with 2 seconds ( esp_sleep_enable_timer_wakeup(TIME TO SLEEP IN MICROSECONDS));
Then, put the ESP32 into deep sleep: esp_deep_sleep_start();
To learn more, you can read our tutorial about deep sleep with timer wake up: https://randomnerdtutorials.com/esp32-timer-wake-up-deep-sleep/
Regards,
Sara

Hi, great article.

Question: is it possible in this esp32 board that you plug in directly an e-ink raw display like WaveShare and drive it with the esp-32?

Hi Nik.
Many of the pins exposed in this ESP32 board are being used either by the camera or by the microSD card slot.
So, it can be very difficult and tricky to setup a display like that with this ESP32-CAM.
(I’m not saying it is not possible, but it should be very tricky).
Regards,
Sara

Wow! Nice article, keep going!

Hi there, i am a newbie. The article it is just the Top.
I have this problem:
————————————————————————————
/esp-who/examples/single_chip/esp32-camera-screen/main/app_main.cpp:41:20: fatal error: dl_lib.h: No such file or directory
————————————————————————————-
i just comented the:
//#include “dl_lib.h”
and it work ok.
Any idea?
And it is possible to disable the flash light? Thnx.

Hi.
We had some readers having the same issue.
Some suggested the following:
“for those who are facing the compilation error: dl_lib.h: No such file or directory, just comment out the #include”dl_lib.h” and it should get compiled. (ESP32 boards version 1.03)”.
You can also read the comments section of the troubleshooting guide when some readers suggest fixes for this issue: https://randomnerdtutorials.com/esp32-cam-troubleshooting-guide/
Regards,
Sara

Hi,
Well done !
Any plan to trigger pin after face recognized ?

I can upload the sketch OK but cannot get the camera to work. Just grounding GPIO13 should cause the flash and camera to record a photo but nothing happens. Do you think I have got a faulty ESP32-CAM board?

Hi Don.
I don’t know.
That a look at our troubleshooting guide and see if it helps: https://randomnerdtutorials.com/esp32-cam-troubleshooting-guide/
Regards,
Sara

Is there any way that the camera can remain active all the time without going into deep sleep?

Just thinking about it, to wake up from deep sleep your code indicates that the pin is to be turned low by the PIR when movement is detected. But for this to work it will need an external pullup resistor so that it is normally high. When movement is detected by the PIR it will then pull this pin low and wake it up from deep sleep.
esp_sleep_enable_ext0_wakeup(GPIO_NUM_13, 0);
The pullup resistor would need to connect to 3.3V and not 5V.

Hello, I would like to know if the esp32 cam has rx and tx ports, and if so, where are they

The U0R and U0T are the U(ART)0R(X) and U(ART)0T(X) ports/pins on the ESP32. The ESP32 also has a UART1 (GPIO9/10, neither of which are broken out) and a UART2 (GPIO 16/17 but only GIPO16/RX2 is broken out.)

Hi Micro, if I know that the esp32 has several serial ports, but my question is about the esp32 cam, I want to know if it has more serial ports because seeing the data sheet says it only has one UOT and one UOR is why my doubt.

Also that you recommend me to connect with a sim800l and send commands at from esp32 cam 🙂

Thanks in advance 🙂

hey Sara, is this possible to use the esp-32 cam for a drone camera?

Yes, but it will really depend on what you want to do with the camera.
Regards,
Sara

in the beginning i had problem compiling the code but after reading in the comment section about the l.lib.h that can be commented,i did that and uploaded the code and is working perfect now.thank you guys,i appreciated it.regards.

Hi, how can i fix this error message?

dl_lib.h: No such file or directory
thank you!

Just comment out that library and you’re ready to go… It was already explained in some other comments and even one above yours 😉

Excellent project guys. I’m your fan
One question: is it possible to disable the flash completely?
Thx!

Hi.
I think the only way to completely disable the flash is by unsoldering the LED.
Regards,
Sara

So if I understand correctly , there is nothing in the code that inhibits flash for this project? I really would like to set it up on a warehouse but I need it without flash
Thanks again for all you guys do!

Hi.
To completely disable the flash, you can “unsolder” the LED.
Regards,
Sara

Hi guys,
Trying to run this ESP-Cam motion sensor app. On compile, I get “dl_lib.h No such file or directory”. Your first web server app works fine. Obviously, I’m missing a library or two.
Where do you reference these libraries?

Sorry, I missed the previous question and answer concerning this issue.
Thanks

Hi Sara and Rui,

Can I use the PIR Motion Sensor (HC-SR501) in this project?

If I can use it, do I have to modify the circuit, or the code?

The ESP32 doesn’t stay in sleep mode. Therefore I’m getting numerous photos saved to the SD card because the code is automatically resetting again.
Would this be because the PIR is constantly on LOW and so PIN 13 is always 0. I have kept very still but it goes round again and takes and saves a photo.

Solved. It was a question of a reliable constant power supply. So, instead of using the laptop or a mains 5v adapter plug to power the device I used a YuRobot 545043 breadboard power supply fixed to a 1/4 size (420 points) breadboard. It now works smoothly at a constant 5v and without any glitches. I’ve yet to see how long the 9v battery will last though!
Excellent sketch. I’ve also got it to send me email with photo attachment.

Hi Malcom.
Thanks for sharing that.
Can you tell me what approach did you use to send the photo to your email?
Regards,
Sara

Hi Malcolm. Can we have a code and/ or some explanation with send me email with attachment please.
Thanx.

Hi Sara Kilo
You can get a good idea how to do this with :
youtube.com/watch?v=ywCL9zDIrT0feature=youtu.be
and
bitsnblobs.com/motion-triggered-image-capture-with-email—esp32-cam

Obviously you will need to do a bit of tweaking to suit your own requirements.

Let me know if you get stuck and I’ll see if I can help.

Great!
Thank you so much for sharing that 😀

I would like to know if there is a way to take the photo through a button

Yes.
You can use GPIO 16 por example to attach the button (I’ve tested it and it works well with that pin).
Then, you can simply check if the button was pressed and take a photo if that is the case.
buttonState = digitalRead(buttonPin);
if (buttonState==HIGH) <
(code to take a photo)
>
Regards,
Sara

It is therefore possible to put an HC-SR501 on pin 16 and take a photo when the PIR goes to 1 (HIGH)

Wow, Thank You both for your time, expertise and effort in helping us all out with this great hobby of ours. Please keep up the great work.
From BC, Canada

Hey Guys,
I’m running this code on two AI Thinker ESP-32-Cam modules. Both systems run fine for awhile, taking pictures, storing pics, etc but then error-out when they come out of sleep. i.e.
Saved file to path: /picture157.jpg
Going to sleep now
ets Jun 8 2016 00:22:57

rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8
Starting SD Card
Picture file name: /picture158.jpg
Saved file to path: /picture158.jpg
Going to sleep now
ets Jun 8 2016 00:22:57

rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8
[E][camera.c:1049] camera_probe(): Detected camera not supported.
[E][camera.c:1249] esp_camera_init(): Camera probe failed with error 0x20004

This happens on both systems. Anything similar happening for anyone else??

I have mase this project. For a while I kept getting an error about waiting for VSync when I pressed the reset button. Eventually I discovered that there are at least two common versions of the camera and I had one where the pin allocations for VSYNC and VLCK were reversed from those in your code. When I set VSYNC to 22 and VLCK to 25 this problem disapeared. However I now have a different problem that has me stumped.
I get this message on the serial monitor.
Starting SD Card
Guru Meditation Error: Core 1 panic’ed (Interrupt wdt timeout on CPU1)
Core 1 register dump:
PC : 0x40083e9c PS : 0x00060034 A0 : 0x80082df5 A1 : 0x3ffbe770
A2 : 0x00000000 A3 : 0x3f400f74 A4 : 0x800df868 A5 : 0x3ffb1e80
A6 : 0x00000003 A7 : 0x3ffc0ae0 A8 : 0x00000002 A9 : 0x3ffb843c
A10 : 0x00000000 A11 : 0x00000080 A12 : 0x000b87c8 A13 : 0x3ffb1e60
A14 : 0x00000000 A15 : 0x00000000 SAR : 0x00000016 EXCCAUSE: 0x00000006
EXCVADDR: 0x00000000 LBEG : 0x4000c46c LEND : 0x4000c477 LCOUNT : 0x00000000
Core 1 was running in ISR context:
EPC1 : 0x400e00f1 EPC2 : 0x00000000 EPC3 : 0x00000000 EPC4 : 0x40083e9c

Backtrace: 0x40083e9c:0x3ffbe770 0x40082df2:0x3ffbe7a0 0x40083411:0x3ffbe7c0 0x400e00ee:0x3ffb1ec0 0x400d1b9e:0x3ffb1ef0 0x400d3233:0x3ffb1fb0 0x4008bcd5:0x3ffb1fd0

Core 0 register dump:
PC : 0x400feede PS : 0x00060134 A0 : 0x800e6812 A1 : 0x3ffbc020
A2 : 0x00000000 A3 : 0x00000001 A4 : 0x00000000 A5 : 0x00000001
A6 : 0x00060120 A7 : 0x00000000 A8 : 0x800ea756 A9 : 0x3ffbbff0
A10 : 0x00000000 A11 : 0x40089d48 A12 : 0x00060120 A13 : 0x3ffbb6c0
A14 : 0x00000000 A15 : 0x3ffbbd20 SAR : 0x00000000 EXCCAUSE: 0x00000006
EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000

Backtrace: 0x400feede:0x3ffbc020 0x400e680f:0x3ffbc040 0x4008dbd5:0x3ffbc060 0x4008bcd5:0x3ffbc080

Rebooting…
ets Jun 8 2016 00:22:57
This goes on and on over and over.
Looks like the watchdog timer is rebooting.
Any help would be great.

Hi Dave.
What camera module are you using?
Maybe you can try another pin for the PIR motion sensor. Try GPIO12, it should work.
How are you powering your board?
Regards,
Sara

I’m just wondering if the are still other usable pins available other than GPIO13, after this code is uploaded?

Hi Mike.
You can use GPIO 16.
Regards,
Sara

Hello, I like your tutorials. I request to make the tutorial to Email the Pictures clicked by the CAM module after detecting the motion by PIR sensor.

Hi.
Thanks for the suggestion.
That should be one of our future tutorials.
Regards,
Sara

The schematic doesn’t appear to match the fritzing diagram. The 5 volt + goes to the 5V pin on the ESP32 on the diagram, but the schematic show it going to VCC, which I think is correct.

Hi Bob.
If you’re using a PIR motion sensor like ours, wire it to 3.3V.
Regards,
Sara

Thank you so much, for this nice project !!

Hello, I’m doing a rush school project right now and might want to ask if it’s possible to add something on your project, probably a relay that will turn on light and make an active buzzer ring whenever there is a motion detected from the PIR using only the esp32cam?

Hi.
Yes, that’s possible.
Wire them to available GPIOs, like GPIO16, GPIO1 or GPIO3.
Then, just add the code to turn on a relay and sound a buzzer.
Here’s a tutorial for relay module: https://randomnerdtutorials.com/esp32-relay-module-ac-web-server/
Regards,
Sara

There have been a few questions regarding the flash LED on the ESP32-CAM board and this should help clarify the LED activity. The LED is controlled by GPIO4 which is also used as DATA1 on the SD card. Reading and writing to the SD card will cause the LED to glow brightly. In this program the LED is NOT lit when the picture is taken, so it will not help with the exposure. It IS brightly lit when the frame buffer is written to the SD card, immediately after the picture is taken. This may lead one to incorrectly think that it is a flash to illuminate the subject. When using the SD card, you have no control over the LED. Programs that do not use the SD card may control the LED by setting GPIO4 high or low. If LED illumination is needed for proper exposure, this program could be modified to initialize the SD card after the picture is taken. This would allow you to use GPIO4 to illuminate the LED before taking the picture.

Hi Marshall.
Thanks for clarifying that subject to our readers.
Regards,
Sara

Very awesome ! it works with me…than you very much! &#128578;

but I have one question…Is there any way I can remove the flash light? from the code?

Hi.
The flash light is controlled by GPIO 4. This GPIO is also used by the microSD card. So, when you do something with the microSD card, the flash light will light up – that’s a current limitation.
Alternatively, you may try unsoldering the LED.
Regards,
Sara

You can use the sd card in “1 bit” mode which then does not use pin 4 and so you can still have full control of the flash
see: https://www.reddit.com/r/esp32/comments/d71es9/a_breakdown_of_my_experience_trying_to_talk_to_an/

Hi.
Thanks for sharing, I’ll take a look at that.
Regards,
Sara

Another solution is to make the SD card to use only 1 bit instead of 4, this makes it a little slower writing file to SD card (speed is acceptable) this then doesn’t flash the Led when using the SD card! just initialise the SD card as follows:

Hi Sara,
it´s a very good Projekt.
Sorry for my bad english. I am from Germany.
I need to take a Picture and save ist to sd card in the VoidLoop.
Operation with power adapter then i dont need the sleep mode.
In my Projekt works the ESP32 Cam Modul with WIFI and Blutooth thats why not Sleep Mode.
Can you tell me what´s code i need only for make a Picture and save to sd card.
I try it but i becom some Error over Variable not declared in this scope.
My Problem is, i works not so long with Arduino.

Hi.
You can use the following function to take and save a photo. Copy that function to the end of your code.

void takeSavePhoto(String path) <
// Take Picture with Camera
camera_fb_t * fb = esp_camera_fb_get();
if(!fb) <
Serial.println(“Camera capture failed”);
return;
>

// Save picture to microSD card
fs::FS fs = SD_MMC;
File file = fs.open(path.c_str(), FILE_WRITE);
if(!file) <
Serial.println(“Failed to open file in writing mode”);
>
else <
file.write(fb-buf, fb-len); // payload (image), payload length
Serial.printf(“Saved file to path: %s\n”, path.c_str());
>
file.close();

//return the frame buffer back to the driver for reuse
esp_camera_fb_return(fb);
>

Then, in the loop() you can call it as follows:

String path = “/picture” + String(pictureNumber) +”.jpg”;
Serial.printf(“Picture file name: %s\n”, path.c_str());

// Take and Save Photo
takeSavePhoto(path);
pictureNumber++;
delay(5000);


Источник: randomnerdtutorials.com