Resolving Device Not Found Error for PIR Sensor on ESP32 with Zephyr RTOS

Am working on a a home automation system that controls water pumps and taps based on motion detection using the Zephyr RTOS on an ESP32 microcontroller, how can i properly detect motion using a PIR (Passive Infrared) sensor with the ESP32? this is what i have tried
include <zephyr.h>
include <device.h>
include <drivers/gpio.h>

define PIR_SENSOR_PIN 23

void main(void) {
const struct device pir_device = device_get_binding(DT_LABEL(DT_NODELABEL(gpio)));
gpio_pin_configure(pir_device, PIR_SENSOR_PIN, GPIO_INPUT);

while (1) {
if (gpio_pin_get(pir_device, PIR_SENSOR_PIN)) {
// Motion detected
printk("Motion Detected!\n");
}
k_sleep(K_MSEC(500));
}
}
include <zephyr.h>
include <device.h>
include <drivers/gpio.h>

define PIR_SENSOR_PIN 23

void main(void) {
const struct device pir_device = device_get_binding(DT_LABEL(DT_NODELABEL(gpio)));
gpio_pin_configure(pir_device, PIR_SENSOR_PIN, GPIO_INPUT);

while (1) {
if (gpio_pin_get(pir_device, PIR_SENSOR_PIN)) {
// Motion detected
printk("Motion Detected!\n");
}
k_sleep(K_MSEC(500));
}
}
But am getting the error Device not found, how can i properly resolve this
2 Replies
wafa_ath
wafa_ath4w ago
Have you verified that the GPIO device is correctly defined and connected to the PIR sensor pin in your device tree (DTS) file? Please double-check the device label and pin configuration.
Boss lady
Boss lady4w ago
yes
Want results from more Discord servers?
Add your server