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:
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
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...
The end of the article is the code ive used... 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 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.