Dear Mam,
As per this project https://rntlab.com/question/esp32-cam-project-without-deep-sleep-mode/, in this, I was using a Magnetic switch but now I am using PIR sensor. Just replacing Magnetic switch with PIR. But I don’t know why the PIR sensor output pin is always HIGH and continuously I am getting the output. So can you please help me with this. What I am missing.
code:https://pastebin.com/sze4ctBV
Thanks
Hi.
I think that is happening because GPIO16 is internally connected to a pull-up resistor. See it here: https://i1.wp.com/randomnerdtutorials.com/wp-content/uploads/2020/03/ESP32-CAM-AI-Thinker-schematic-diagram.png?ssl=1
Additionally, when the PIR motion sensor detects motion, its state stays HIGH for a few seconds. For the PIR sensor we use, it’s usually 7 seconds, if I’m not wrong.
Are you printing in the Serial Monitor the state of the PIR sensor? Does it change?
When using a PIR motion sensor with the ESP32, it is better to use interrupts instead.
A few days ago, I’ve experimented with interrupts on the ESP32-CAM pins, here’s what I found:
GPIO 13: works well
GPIO 15 : works with inverted logic
GPIO 12: Guru meditation error when it gets a HIGH signal
GPIO 14: works well
GPIO 2: works well
GPIO 4: doesn’t work as expected.
If you don’t need to use the microSD card, you’ll have other pins to experiment with the PIR sensor.
I hope this helps.
Regards,
Sara
Hello Mam, Thank you for the detailed response. I tried various pins as recommended by you and using Interrupt. But now I am getting GuruMeditation error and Camera probe error. It might be that I am doing some mistake in implementing Interrupt.
Code: https://pastebin.com/p4KyusaQ
Serial Monitor:https://imgur.com/FxcTjs3
Serial Monitor:https://imgur.com/2BLvBEy
Thanks
Hi.
I spend the last couple of hours trying to implement your project, but no luck. I was not able to use interrupts and the microSD card at the same time.
I’ve implemented the same project, but saving the photos in SPIFFS. Here’s the code:https://pastebin.com/fGW8fXdA
With the ESP32-CAM you need to implement interrupts as follows (in this case in GPIO 14):
esp_err_t err = gpio_isr_handler_add(GPIO_NUM_14, &detectsMovement, (void *) 1); if (err != ESP_OK) { Serial.printf("handler add failed with error 0x%x \r\n", err); } err = gpio_set_intr_type(GPIO_NUM_14, GPIO_INTR_POSEDGE); if (err != ESP_OK) { Serial.printf("set intr type failed with error 0x%x \r\n", err); }
And the callback function:
static void IRAM_ATTR detectsMovement(void * arg) { Serial.println("Motion Detected"); takePicture = true; }
I tested the example I’ve sent you with a PIR motion sensor on GPIO 14 and it worked well.
I hope this helps.
Regards,
Sara
Dear Mam,
Thank you, Mam, for your help. I really appreciate. And I tried the sketch, it is working fine. Thank you so much, Mam.
Hello Mam, as I am new to the SPIFFS file system, and as per me, after a certain limit the flash will be full and I have to delete the files.
So, is it possible within the code, that after sending an email with the attachment we can delete that file from the flash?
I was trying this simple sketch:
#include "SPIFFS.h" void setup() { Serial.begin(115200); if (!SPIFFS.begin(true)) { Serial.println("An Error has occurred while mounting SPIFFS"); return; } Serial.println("\n\n---BEFORE REMOVING---"); listAllFiles(); SPIFFS.remove("/photo.jpg"); Serial.println("\n\n---AFTER REMOVING---"); listAllFiles(); } void listAllFiles(){ File root = SPIFFS.open("/"); File file = root.openNextFile(); while(file){ Serial.print("FILE: "); Serial.println(file.name()); Serial.print(file.size()); Serial.println(" bytes"); file = root.openNextFile(); } } void loop() {}
Please correct me if I am wrong, as it might be a basic question.
Thanks
Hi.
I think that should work.
But if you overwrite the same photo name, I don’t think you’ll have memory problems.
Regards,
Sara
OK, and I found this link https://github.com/pellepl/spiffs/wiki/FAQ#how-long-will-my-spi-flash-live and as I understood, it says if we do one write per second than the flash can survive for 355 days and I think this is sufficient for this device.
Thanks a lot, Mam.