Hi,
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 :
//variable
const byte pinPIR = 13;
//setup()
pinMode(pinPIR, INPUT_PULLUP);
//loop()
Serial.print(digitalRead(pinPIR));
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:
pinMode(pinPIR, INPUT);
digitalWrite(pinPIR,LOW);
But.. no success
Hi.
Can you show me the code snippet that reads the PIR? Are you using interrupts?
Regards,
Sara
Hi Sara
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.println(“Interrupt”);
pirSensor=true;
}
void enableInterrupt()
{
esp_err_terr=gpio_isr_handler_add(GPIO_NUM_13,&detectsMovement,(void*)13);
if(err!=ESP_OK)
{
Serial.printf(“handler add failed with error 0x%x \r\n”,err);
}
err=gpio_set_intr_type(GPIO_NUM_13,GPIO_INTR_POSEDGE);
if(err!=ESP_OK)
{
Serial.printf(“set intr type failed with error 0x%x \r\n”,err);
}
}
//And run enableInterrupt() behind : esp_camera_init(&config);
//Finally in loop() :
void loop()
{
if(pirSensor)
{
digitalWrite(pinLED,HIGH);
// public a mqtt message to my broker
mqtt_pir();
pirSensor=false;
digitalWrite(pinLED,LOW);
}
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
Cheers
Hi.
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.
Regards,
Sara