Skip to content

Commit c801519

Browse files
authored
Merge pull request #132 from RaspberryPiFoundation/dev
Add motion sensor
2 parents bcef471 + ef127fc commit c801519

File tree

10 files changed

+942
-492
lines changed

10 files changed

+942
-492
lines changed

docs/api.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ Button
101101
:inherited-members:
102102
:members:
103103

104+
MotionSensor
105+
------------
106+
107+
.. autoclass:: MotionSensor
108+
:show-inheritance:
109+
:inherited-members:
110+
:members:
111+
104112
Switch
105113
------
106114

docs/changelog.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ Change log
33

44
.. currentmodule:: picozero
55

6+
0.5.0 - 2025-10-31
7+
-----------
8+
9+
+ Introduced ``MotionSensor`` class for PIR sensors
10+
11+
0.4.2 - 2023-05-12
12+
------------------
13+
14+
+ Bug fix relating to DigitalInputDevice bounce times
15+
+ Updated tests after a change in micropython 1.20+
16+
617
0.4.1 - 2022-12-22
718
------------------
819

docs/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ def __getattr__(cls, name):
4343
# -- Project information -----------------------------------------------------
4444

4545
project = 'picozero'
46-
copyright = '2022, Raspberry Pi Foundation'
46+
copyright = '2025, Raspberry Pi Foundation'
4747
author = 'Raspberry Pi Foundation'
4848

4949
# The full version, including alpha/beta/rc tags
50-
release = '0.4.1'
50+
release = '0.5.0'
5151

5252

5353
# -- General configuration ---------------------------------------------------
@@ -101,4 +101,4 @@ def __getattr__(cls, name):
101101
# -- Autodoc configuration ------------------------------------------------
102102

103103
autodoc_member_order = 'groupwise'
104-
autodoc_default_flags = ['members']
104+
autodoc_default_flags = ['members']

docs/examples/motion_sensor.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from picozero import MotionSensor
2+
from time import sleep
3+
4+
pir = MotionSensor(2)
5+
6+
print("PIR Motion Sensor Example")
7+
print("Waiting for motion...")
8+
9+
while True:
10+
if pir.motion_detected:
11+
print("Motion detected!")
12+
sleep(1)
13+
else:
14+
print("No motion")
15+
sleep(0.5)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from picozero import MotionSensor, pico_led
2+
from time import sleep
3+
4+
pir = MotionSensor(2)
5+
6+
# Set up event callbacks
7+
pir.when_motion = pico_led.on
8+
pir.when_no_motion = pico_led.off
9+
10+
# Keep the program running
11+
try:
12+
while True:
13+
sleep(1)
14+
except KeyboardInterrupt:
15+
print("\nShutting down...")
16+
pico_led.off() # Make sure LED is off when exiting

docs/recipes.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@ Turn the :obj:`pico_led` on when a :class:`Button` is pressed and off when it is
145145

146146
.. literalinclude:: examples/button_led.py
147147

148+
Motion sensor
149+
-------------
150+
151+
Detect motion using a PIR (Passive Infrared) sensor:
152+
153+
.. literalinclude:: examples/motion_sensor.py
154+
155+
Use callbacks to respond to motion events:
156+
157+
.. literalinclude:: examples/motion_sensor_callbacks.py
158+
148159
RGB LEDs
149160
--------
150161

picozero/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__name__ = "picozero"
22
__package__ = "picozero"
3-
__version__ = '0.4.1'
3+
__version__ = '0.5.0'
44
__author__ = "Raspberry Pi Foundation"
55

66
from .picozero import (
@@ -28,6 +28,7 @@
2828
DigitalInputDevice,
2929
Switch,
3030
Button,
31+
MotionSensor,
3132

3233
AnalogInputDevice,
3334
Potentiometer,

0 commit comments

Comments
 (0)