Exit screensaver on Raspberry Pi with motion sensor
Hardware
I want to build a smart home display for my living room. Additionally it should go to to sleep/screensaving automatically and I want it to wake up if someone walks by.
So I buyed a cheap infrared PIR motion sensor.
Something like this:
Look at amazon
Then I connected it to 5V, GND and GPIO Pin 4:
Search Google for images
And now the software part
I tried some Python scripts but for my case these were not robust enough. To exit the screensaver you Need to execute some console commands.
First: Configure screensaver
This sets the screensaver and power management to power off after 2 minutes
Second: Exit screensaver from console
xset dpms force on
This code resets the timer and brings on power again.
Third: Do it on GPIO event
After some Fails I found GPIO-Watch, a small utility that watches GPIO events and executes shell scripts.
Preparation
1. Download
2. Unzip
3. Enter Directory
4. Build
sudo make install
Configuration
1. Create a script named „4“ under /etc/gpio-watch because gpio-watch will later execute this on rising on GPIO pin 4.
2. Put your commands into the script
#echo 'set on'
xset s reset
xset dpms force on
3. Let gpio-watch watch your Pins