Motion sensor very low range issue

Hello,

I have an ESP32 with MH-SR602 motion sensor connected (GND, 3V3, D27). Everything works fine with the exception that it only detects movement within 10cm from it. According to specs it should do 3-5m. Using sample code below. Appreciate any pointers to why this can be happening.

/*********
  Rui Santos
  Complete project details at https://randomnerdtutorials.com  
*********/

#define timeSeconds 10

// Set GPIOs for LED and PIR Motion Sensor
const int led = 26;
const int motionSensor = 27;

// Timer: Auxiliary variables
unsigned long now = millis();
unsigned long lastTrigger = 0;
boolean startTimer = false;

// Checks if motion was detected, sets LED HIGH and starts a timer
void IRAM_ATTR detectsMovement() {
  Serial.println("MOTION DETECTED!!!");
  digitalWrite(led, HIGH);
  startTimer = true;
  lastTrigger = millis();
}

void setup() {
  // Serial port for debugging purposes
  Serial.begin(115200);
  
  // PIR Motion Sensor mode INPUT_PULLUP
  pinMode(motionSensor, INPUT_PULLUP);
  // Set motionSensor pin as interrupt, assign interrupt function and set RISING mode
  attachInterrupt(digitalPinToInterrupt(motionSensor), detectsMovement, RISING);

  // Set LED to LOW
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW);
}

void loop() {
  // Current time
  now = millis();
  // Turn off the LED after the number of seconds defined in the timeSeconds variable
  if(startTimer && (now - lastTrigger > (timeSeconds*1000))) {
    Serial.println("Motion stopped...");
    digitalWrite(led, LOW);
    startTimer = false;
  }
}

Thanx!

Code looks OK. I don't see any reason that the code is causing the device external to the ESP32 to operate below specs.

Operating parameters: Human body pyroelectric infrared sensor module, Model: SR-602 Response distance: up to 5 m; 0-3. It depends on what you are trying to sense. It DC power supply is rated at: 3.3 V-15 V, what voltage are you operating it at. I would assume at the low end the range will be shorter and it does have a built in 2+ second delay.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.