Package com.diozero.devices.sandpit
Class MotionSensor
java.lang.Object
com.diozero.api.GpioDevice
com.diozero.api.GpioInputDevice<DigitalInputEvent>
com.diozero.api.AbstractDigitalInputDevice
com.diozero.api.DigitalInputDevice
com.diozero.api.SmoothedInputDevice
com.diozero.devices.sandpit.MotionSensor
- All Implemented Interfaces:
DeviceInterface
,DigitalInputDeviceInterface
,DeviceEventConsumer<DigitalInputEvent>
,AutoCloseable
,Runnable
,Consumer<DigitalInputEvent>
public class MotionSensor extends SmoothedInputDevice
A Passive Infra-Red (PIR) motion sensor.
A typical PIR device has a small circuit board with three pins: VCC, OUT, and GND. VCC should be connected to the Pi's +5V pin, GND to one of the Pi's ground pins, and finally OUT to the GPIO specified as the value of the 'pin' parameter in the constructor.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.diozero.api.SmoothedInputDevice
SmoothedInputDevice.Builder
-
Field Summary
Fields inherited from class com.diozero.api.AbstractDigitalInputDevice
activeHigh
Fields inherited from class com.diozero.api.GpioDevice
pinInfo
-
Constructor Summary
Constructors Constructor Description MotionSensor(int gpio)
Defaults 'threshold' to 1, eventAge t0 20ms and eventDetectPeriod to 10ms.MotionSensor(int gpio, int threshold, int eventAge, int eventDetectPeriod)
MotionSensor(int gpio, GpioPullUpDown pud, int threshold, int eventAge, int eventDetectPeriod)
-
Method Summary
Methods inherited from class com.diozero.api.SmoothedInputDevice
accept, getEventAge, getEventDetectPeriod, getThreshold, run, setEventAge, setThreshold
Methods inherited from class com.diozero.api.DigitalInputDevice
close, getPullUpDown, getTrigger, getValue, isActive, removeListener, setListener
Methods inherited from class com.diozero.api.AbstractDigitalInputDevice
disableDeviceListener, enableDeviceListener, isActiveHigh, waitForActive, waitForActive, waitForInactive, waitForInactive, waitForValue, whenActivated, whenDeactivated
Methods inherited from class com.diozero.api.GpioInputDevice
addListener, hasListeners, removeAllListeners, removeListener
Methods inherited from class com.diozero.api.GpioDevice
getGpio
-
Constructor Details
-
MotionSensor
Defaults 'threshold' to 1, eventAge t0 20ms and eventDetectPeriod to 10ms.
If your PIR sensor has a short fall time and is particularly "jittery" you may wish to set this to a higher value (e.g. 5) to mitigate this.
- Parameters:
gpio
- The GPIO which the motion sensor is attached.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
MotionSensor
public MotionSensor(int gpio, int threshold, int eventAge, int eventDetectPeriod) throws RuntimeIOException- Parameters:
gpio
- The GPIO to which the motion sensor is attached.threshold
- The value above which the device will be considered "on".eventAge
- The time in milliseconds to keep active events in the queue.eventDetectPeriod
- How frequently to check for events.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
MotionSensor
public MotionSensor(int gpio, GpioPullUpDown pud, int threshold, int eventAge, int eventDetectPeriod) throws RuntimeIOException- Parameters:
gpio
- The GPIO to which the motion sensor is attached.pud
- Pull up/down configurationthreshold
- The value above which the device will be considered "on".eventAge
- The time in milliseconds to keep active events in the queue.eventDetectPeriod
- How frequently to check for events.- Throws:
RuntimeIOException
- If an I/O error occurred.
-