Video recording with an ESP32 + PIR sensor

Hi everyone. I would like to make a very easy project with an ESP32-CAM and a PIR sensor, but I can't seem to find a basic tutorial for it.
The thing is that I've currently managed to get it to take a picture whenever the PIR sensor is triggered and saves it in the SD card. I was happy with just that, but then I thought, what if instead of a picture, I took a 30 second video? can you point me a simple tutorial to do so?
I don't need it to connect to wifi, send the files to FTPs or emails, or anything like that. I want it super-simple. Just detect motion, shot a 30 second video and store it in the SD card.
Any simple tutorial you know about? All the ones I've found online are overcomplicating things or are time-lapses or things like that.
Thank you

I'm working on this right now - keen to see what replies you get.

I also found that a lot of the examples online were overly complex, and in a lot of cases the code had been copied, and re-copied, from previous examples and now contain a lot of superfluous rubbish code.

Creating a video is not much hard than a photo... an AVI file is really just a bunch of JPEG images. I'm happy to share my code... gimme a week. :slight_smile:

I'd appreciate it, thank you! and of course, no rush

I was looking for something similar but with a probabely different usecase than for most.
I have the HC-SR501 pir to detect animals coming in a shed (strange noises at night) and would like to know where they get in and what animals they are. Would link the pir to the esp32 cam and record for something similar straight to the SD while being able to also check the stream (bandwidth problem?). I have some high power leds available which will also light up as soon as the movement is detected but a bit stuck on where to start with code.

@keukenrol @Assamita

You guys still after some code for a PIR sensor triggered video recorder to SD card?

1 Like

Absolutely!

@Assamita @keukenrol

Code is here. GitHub - red-car-nz/Video_Camera: Arduino repository

To date for the PIR sensor, I just been pulling the GPIO pin high... I have a number to try out.

I haven't done a huge amount of testing, and still need to play around with the various camera settings to get the best picture. Currently uses SVGA frame size, 4fps. Let me know if you have any questions. A good power supply is essential to avoid brown-out issues.

I'll likely build a custom PCB to hold the ESP32-CAM, PIR sensor, and power supply. Probably a few weeks away for that.

Cheers.

2 Likes

Won't 18650 batteries do? I was thinking of using it kind of like a wildcam

You could power with batteries, no problem with that.

If I was going to use batteries however, I would probably design the code a little differently, and put the ESP32 to sleep and only wake up when the sensor detects movement.

1 Like

I currently have that running, just incompatible with the email system which I am trying to get working as well combined. Currently the esp32 gets awakened by a pin from the pir and takes a photo, goes back to sleep.

Cool - thinking about it I might change my version to do the same.

Have you had a chance to try out my code? Be interested in any feedback (good or bad :slight_smile: )

Which pin are you using?

I currently have the same than keukenrol and I have it at pin GPIO_NUM_13.
Also, in the code I use, there's a line to disable brownout, as apparently, is very sensitive:

WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);

Thanks. On my board it looks like GPIO13 is connected to the PSRAM.

What CAM board are you using?

One of those AI thinker (I think it's a knock off though)

Interesting ... I wonder if there are ay situations where you would get a conflict?

I choose GPIO3 as it is only used for the Serial RX... so not used once the sketch is running.

However, I don't think that pin can be used for interrupts, so I might need to rethink.

Pin 13, the ESP32 CAM has an SD card inserted and the HC-SR501 pir connected to pin 13. When the pin goes low it triggers the wakeup.
If you want the code send me a pm.

Yeah sure... keen to have a look.

Not sure a single pic and a video are the same though.

I guess the PSRAM is not doing anything prior to the PIR detecting a movement, so should work initially... but be keen to see what happens when the video is being captured and the PIR sensor is still triggering?

It is set up as photo capturing device, so no video (yet). Would be nice in the long term of course. Right now when movement is detected the pin goes low, esp boots and goes trough its initialization process. Taking picture, connecting to wifi and sending an e-mail + storing the photo locally. Then going back to sleep. I will use this setup to spot some uninvited animal visitors on the attic. It does not really require video, I am mainly interested in where they come from. First movement detection is important here.

I've sent a PM... keen to see your code.

Always interesting to understand why someone decides to build something :slight_smile: