Using one of yours proyects, this for example :Video Streaming Web Server, (with ESP32-CAM) I just want to add a PIR (Mini AM312 PIR Motion Sensor) to test.
The pin I´ve chosen is the 13 (I tested 12 also) and added :
const byte pinPIR = 13;
The behaviour is odd, the first one is that the pin 13 start HIGH, so PIR never works. Is this normal?
I´ve tested, same board, same pin in a simple sketch to test the PIR and work fine.
Any help will be a appreciated
This could be the solution:
But.. no success
Can you show me the code snippet that reads the PIR? Are you using interrupts?
I have also tried with interrupts, the way to use interrupt is in the esp-way not arduino-way I supose there is a conflict with esp-camera software.
The snippet is below:
static void IRAM_ATTR detectsMovement(void *arg)
Serial.printf(“handler add failed with error 0x%x \r\n”,err);
Serial.printf(“set intr type failed with error 0x%x \r\n”,err);
//And run enableInterrupt() behind : esp_camera_init(&config);
//Finally in loop() :
// public a mqtt message to my broker
Well, the behavoir is odd, each 6,7 seconds an interrupt arrive with any movement on my part. When Mini AM312 PIR Motion Sensor detect some movement, send HIGH during 5 seconds, this can be a clue.
If I load a sketch with just the PIR code with interrupts o without interrupts works fine, same board ESP32-CAM, same PIR.
Thanks in advance
I’m not sure what can be wrong. How are you powering the PIR motion sensor? Does it require 3.3V or 5V to operate?
Either there is a conflict with the PIR code and the video streaming code, or the ESP32-CAM can’t provide enough power while it is streaming video.
Meanwhile, I found a discussion about using the ESP32-CAM with PIR, video streaming, and Telegram. They share the code. Here it is (you can ignore and comment the Telegram part):
I hope this helps.