Module esp_ward::peripherals::pir

source ·
Expand description

§Passive Infrared (PIR) Sensor Module

Provides an abstraction for interfacing with a PIR motion sensor. PIR sensors are commonly used to detect movement within a certain range.

§Example

use esp_hal::gpio::GpioExt; // Import traits to split pins
use esp_hal::peripherals::Peripherals;
use your_crate::peripherals::PirSensor;

let peripherals = Peripherals::take().unwrap();
let pins = peripherals.GPIO.split();

// Suppose the PIR sensor is connected to GPIO5
let pir_pin = pins.gpio5.into_pull_up_input(); // Configure the pin as input with pull-up
let mut pir_sensor = PirSensor::new(pir_pin);

// Now you can check for motion
if pir_sensor.motion_detected() {
    println!("Motion detected!");
}

Structs§

  • Represents a PIR motion sensor connected to a single digital input pin.