• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

pins in ESP32-CAM I can use

Q&A Forum › Category: ESP32 › pins in ESP32-CAM I can use
0 Vote Up Vote Down
Carlos Pascual asked 4 years ago

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

Question Tags: camera
5 Answers
0 Vote Up Vote Down
Carlos Pascual answered 4 years ago

This could be the solution:

pinMode(pinPIR, INPUT);
digitalWrite(pinPIR,LOW);

But.. no success

0 Vote Up Vote Down
Carlos Pascual answered 4 years ago

Any clue?, tip?

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.
Can you show me the code snippet that reads the PIR? Are you using interrupts?
Regards,
Sara

0 Vote Up Vote Down
Carlos Pascual answered 4 years ago

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

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

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):

  • https://forum.arduino.cc/t/problem-with-esp32-cam-pir-motion-connected-to-telegram/879854/16

 
I hope this helps.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.