Currently having trouble testing the hc-sr501 PIR sensor on a esp32-c3-mini microcontroller. Haven't been able to properly test it, since i haven't managed to figure out to which pin the sensor should be connected to. (I've tried all of them and haven't gotten any kind of response on the serial monitor)
Current code on the IDE:
#define PIN_SENSOR 5
const int PIN_TO_SENSOR = 5; // GPIO19 pin connected to OUTPUT pin of sensor
int pinStateCurrent = LOW; // current state of pin
int pinStatePrevious = LOW; // previous state of pin
void setup() {
Serial.begin(9600); // initialize serial
pinMode(PIN_TO_SENSOR, INPUT); // set ESP32 pin to input mode to read value from OUTPUT pin of sensor
}
void loop() {
pinStatePrevious = pinStateCurrent; // store old state
pinStateCurrent = digitalRead(PIN_TO_SENSOR); // read new state
if (pinStatePrevious == LOW && pinStateCurrent == HIGH) { // pin state change: LOW -> HIGH
Serial.println("Motion detected!");
// TODO: turn on alarm, light or activate a device ... here
}
else
if (pinStatePrevious == HIGH && pinStateCurrent == LOW) { // pin state change: HIGH -> LOW
Serial.println("Motion stopped!");
// TODO: turn off alarm, light or deactivate a device ... here
}
}
if you mean the datasheet i don't have the link anymore since i already downloaded the pdf file, and since i'm a new user on the website i can't upload files
Alright, new problem, i was about to try the code but now my IDE can't find the port i'm connected to. This didn't happen before and reinstalling ch341ser.inf did not fix it.