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

xset dpms 120 120 120

This sets the screensaver and power management to power off after 2 minutes

Second: Exit screensaver from console

xset s reset
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

wget https://github.com/larsks/gpio-watch/archive/master.zip

2. Unzip

unzip ./master.zip

3. Enter Directory

cd gpio-watch-master

4. Build

make
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

#!/bin/sh
#echo 'set on'
xset s reset
xset dpms force on

3. Let gpio-watch watch your Pins

gpio-watch -e rising 4
Be Sociable, Share!