Skip to content

Support us at

Authors: fire1ce | Created: 2022-04-24 | Last update: 2022-07-13

Motion Sensor Display Control

Python script to control connected display to Raspberry Pi using Motion Sensor (pir).

Official Github Repo

Information

This script uses pin GPIO4(7) to read data from Motion (PIR) Sensor, Any 5v and ground for PIR Sensor

gpio layout

raspberrypi-with-PIR-sensor

Requirements

  • python3-gpiozero

Can be install via apt

sudo apt install python3-gpiozero

Install

This will install the script as service and it will run at boot

curl https://raw.githubusercontent.com/fire1ce/raspberry-pi-pir-motion-display-control/main/install.sh | bash

Uninstall

curl https://raw.githubusercontent.com/fire1ce/raspberry-pi-pir-motion-display-control/main/uninstall.sh | bash

Default Behavior

Condition Behavior
Motion while display is off Turns on display for 60 sec
Motion while display is on Resets the timer for another 60 sec
No motion > 60 sec Turns off the display

Config

File

/usr/local/bin/motion-display-control.py

You can change Data Pin of the PIR Sensor at gpio_pin value You can change Delay at display_delay value

Line

motion = Motion(gpio_pin=4, display_delay=60, verbose=False)

Restart the service to apply changes

sudo systemctl restart power_button.service

Debug

In order to allow verbose debug change the following

File

/usr/local/bin/motion-display-control.py

Line

Set verbose value to True

motion = Motion(gpio_pin=4, display_delay=60, verbose=True)

Restart the service to apply changes

sudo systemctl restart motion-display-control.service

Check if service is running

sudo systemctl status motion-display-control.service

Contributors

Thanks to Boris Berman for the script rewrite from function to classes

Comments