Motion Sensor

Motion Sensor - is a device that detects movement.


MotionSensor(slot) -> Pin

To create MotionSensor object call MotionSensor(slot).

Also you can use short alias Motion(slot).

Args:

  • slot (string | int | tuple) - slot label ("A", "B", "C", "D", "E", "F", "G", "H"), pin port (0, 2 and etc.), tuple (0, Pin.IN).

Returns: Return a digital output Pin for slot.

from pibody import MotionSensor

motion = MotionSensor("A")

.read() -> int

Returns 1 or 0 depending on its state.

motion.read()
from pibody import Motion  # short alias

motion = Motion("A")

while True:
    if motion.read():
        print("Motion is detected")
    else:
        print("Motion is not detected")

.value() -> int

Same as .read(), returns 1 or 0 depending on its state.

value = motion.value()
print(value)