0% found this document useful (0 votes)
9 views

Using a PIR sensor _ Physical Computing with Python _ Python _ Coding projects for kids and teens

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Using a PIR sensor _ Physical Computing with Python _ Python _ Coding projects for kids and teens

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

12/24/24, 5:06 PM Using a PIR sensor | Physical Computing with Python | Python | Coding projects for kids and

ng projects for kids and teens

English

Physical Computing with Python


Raspberry Pi Electronic components Python

Project steps

Print this project

Save your progress & collect badges!

Log in or sign up

Using a PIR sensor


Humans and other animals emit radiation all the time. This is nothing to be concerned about,
though, as the type of radiation we emit is infrared radiation (IR), which is pretty harmless at the

https://projects.raspberrypi.org/en/projects/physical-computing/11 1/4
12/24/24, 5:06 PM Using a PIR sensor | Physical Computing with Python | Python | Coding projects for kids and teens

levels at which it is emitted by humans. In fact, all objects at temperatures above absolute zero
(-273.15C) emit infrared radiation.
A PIR sensor detects changes in the amount of infrared radiation it receives. When there is a
significant change in the amount of infrared radiation it detects, then a pulse is triggered. This
means that a PIR sensor can detect when a human (or any animal) moves in front of it.

Wiring a PIR sensor


The pulse emitted when a PIR detects motion needs to be amplified, and so it needs to be powered.
There are three pins on the PIR: they should be labelled Vcc, Gnd, and Out. These labels are
sometimes concealed beneath the Fresnel lens (the white cap), which you can temporarily remove
to see the pin labels.

1. As shown above, the Vcc pin needs to be attached to a 5V pin on the Raspberry Pi.
2. The Gnd pin on the PIR sensor can be attached to any ground pin on the Raspberry Pi.
3. Lastly, the Out pin needs to be connected to any of the GPIO pins.

Tuning a PIR
Most PIR sensors have two potentiometers on them. These can control the sensitivity of the
sensors, and also the period of time for which the PIR will signal when motion is detected.
https://projects.raspberrypi.org/en/projects/physical-computing/11 2/4
12/24/24, 5:06 PM Using a PIR sensor | Physical Computing with Python | Python | Coding projects for kids and teens

In the image above, the potentiometer on the right controls the sensitivity, and the potentiometer
on the left controls the timeout. Here, both are turned fully anti-clockwise, meaning that the
sensitivity and timeout are at their lowest.
When the timeout is turned fully anti-clockwise, the PIR will output a signal for about 2.5 seconds,
whenever motion is detected. If the potentiometer is turned fully clockwise, the output signal will
last for around 250 seconds. When tuning the sensitivity, it is best to have the timeout set as low as
possible.

Detecting motion
You can detect motion with the PIR using the code below:
from gpiozero import MotionSensor

pir = MotionSensor(4)

while True:
pir.wait_for_motion()
print("You moved")
pir.wait_for_no_motion()
https://projects.raspberrypi.org/en/projects/physical-computing/11 3/4
12/24/24, 5:06 PM Using a PIR sensor | Physical Computing with Python | Python | Coding projects for kids and teens

Using an ultrasonic distance sensor

Spotted a mistake? Enjoying the project? Any opinions on the website? Let us know!

Send feedback

Published by Raspberry Pi Foundation under a Creative Commons license.


View project & license on GitHub
Accessibility Cookies Policy Privacy Policy Translate for us

https://projects.raspberrypi.org/en/projects/physical-computing/11 4/4

You might also like