Esp32 with Pir sensors going crazy when on PSU

Hello folks,
Sorry if this is not the correct place for this, however im really stuck and I hope someone can help please?

Im trying to use some PIR sensors with an esp32, im using just a basic script in Arduino IDE, ultimately I want to use 5 sensors, however im struggling with even 1 lol the sensors are HC-SR501, basically when I connect the sensor 2 the esp32 using short wires and powered by the esp32 VCC line and GND on the esp32 and output of sensor on Pin 27 all works fine and dandy, however when I try to extend the wires and connect the PIR to a bench power supply it goes crazy keeps showing its been triggered repeatedly, ive measured voltage on the output from Pir to Esp32 pin 27 and it seems to be getting 0.3v or something all the time even when no power is supplied to the PIR and just the Esp32 is powered via USB, ive tried adding some 1k resistors which didnt make any difference, I dont have any others so i tried adding 5 to give 5k which still made the code go crazy and find motion etc. Can someone please give me some help, im not too sure what else to try.
The code I used is

#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, HIGH);

  // 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;
  }
}

Indent your code in the Arduino IDE with ctrl+T, then select all, right click > copy for the forum; finally modify your original post.
Or you can use this button:
immagine

And the power supply info? Like AMPs, a picture of the connections?

Are the grounds connected?

Is it a 5V switching power supply? I that case put an electrolytic and a ceramic cap off the 3.3V pin.

Thank you for your reply :slight_smile:

The power supply is a bench power supply, set to 5V 1AMP, however when connected it does say its not drawing any amps, even though on the multimeter it is saying its giving 5v

I didn't have any caps so would have to order them, its currently connected as the following:-
PIR
GND to Bench PSU
VCC to Bench PSU
Out to 4 * 1k resistors to Esp32 pin 27

Esp32
Pin 27 used
Plugged in through MicroUSB to PC

Just weird it works fine when powered by the ESP32 but stops using a bench power supply, wanted to power a few more PIR connect them to pin 32, 33, 34, 35 etc

What are these "4 * 1k resistors"? A voltage divider?
Are (esp)GND and (p.supply)GND connected?

lol, no I just read somewhere to put a 4.7k resistor or 10k resistor on the output of the PIR, I didnt have a 4.7k or 10k so I put 4 1k ones in series, didnt make a difference with or without...

There is something in your code which doesn't convince me.
Take a look at this article:

Sorry I did try connecting the PSU ground and esp ground and it still didnt make a difference.

The end of the article is the code ive used... :slight_smile: just removed the Led part as I didnt have an LED just using serial monitor to detect movement

The Pir said it operates anything from 4.5v to 20v, so I thought maybe it only works on lower voltages as the VCC of esp32 was giving 3v something so I even tried the bench psu on 3.5v and 4v and 4.5v.

you set an HIGH trigger for the interrupt.

oops sorry I was just messing with trying different things, tried rising, low etc to see if it made any difference lol, was using "RISING"

Next, post a photo of your circuit.

You do understand it is not an "option". The grounds (actually the negative pin which will be a black terminal, not the green) of all the different power supplies must always be connected together.

Sorry everything's a bit of a mess so don't know if the picture will be clear

Black and Red clips Bench PSU > PIR GND and VCC
Black GND of ESP32

Esp32 Pin 27 PIR Output

Yellow & Orange not connected.

That is a mess. Why not try using a breadboard?

Where is the PSU connection?

Why is there a wire connected to GPIO_NUM_17? GPIO_NUM_27 is on the other side of the developer module.

Don't know if this helps ive labelled the image. Sorry I didnt have a breadboard wanted to test the pirs spread out etc

Good luck to you.

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