Raspberry Pi Kiosk with PIR activity detector

Posted by

Subtitle: Automatic flight calendar display for flying club office

Using a Raspberry Pi to display a webpage with current bookings onscreen but only when people are in the office.

Knowing exactly which aircraft are booked and when they are next required is really helpful at a flying club. The calendar changes constantly depending on weather, technical problems and pilot/student availability.

Many clubs, like ours, have an online booking system that holds that information. But you have to login and view it on a computer or phone to check. What I wanted was a constantly updated computer screen showing the current bookings, but one that would only be active when there was a pilot in the office. It shouldn’t require any manual intervention, no need to turn on or off, and be low cost and low power.

We had tried a standalone PC set to be active only during normal working hours but without success – it was either left on all day when no-one was there, or was turned off as people left. The solution suggested by one member was to use a Raspberry Pi to drive a secondhand 17 inch LCD monitor. I expanded the scope by adding a PIR (Passive Infra Red detector) which could determine when anyone was in the office. I had many of the parts kicking around in my electronics cupboard, so it didn’t cost much to put it together.

It’s been a project to work on during the winter downtime and I’ve documented what I did below. It is far from perfect, but works adequately to meet requirements. There are many other and better ways to achieve this, so feel free to optimise and improve.

Hardware required

For the full recipe you will need:

  1. Raspberry Pi Model 2B or later (they are up to Model 4B at the time of writing). While the later models are much more powerful, the Model 2B is more than sufficient to display a fairly static webpage. Price for either model is typically £30-35. You could even use a Raspberry Zero W which costs less than £10 and has built in Wi-Fi.
  2. Power supply. Don’t skimp with a very low cost one because these are often the source of intermittent performance problems. Make sure it’s fully rated 2.5 Amps for Model 2 or 3, or 3 Amps for Model 4. The official ones cost around £7-8.
  3. PIR module. I used the HC-SR501 from Pi Hut for £3. It looks a bit like a golf-ball – see below.
  4. Interface cable. If you want to avoid any soldering, buy some female to female interconnecting leads. You can buy a pack of 10 for £1.50 from PiHut here
  5. Case. You could put both PIR and Pi in the same case but I preferred to separate them. There are many nice looking cases for the Pi. There are also specifically designed enclosures for the PIR module available on eBay for £3. I used a standard ABS project box for the PIR detector which needed some drilling/filing to cut out holes for the module.
  6. Display screen. Ideal either HDMI or DVI, although it is possible to use an older VGA model with an HDMI adaptor cable. I’d recommend something around 17″ although you could drive almost any size with up to 1080 HD. There are plenty of second hand computer screens available on eBay for £20 including delivery. These may or may not include connector cables.
  7. Display cable. The output from a Raspberry Pi is HMDI, so typically a short HMDI to HDMI cable is what you want. Amazon’s Basics range is good and costs less than £5. If your monitor is DVI or VGA then you will need a suitable convertor cable. The Raspberry Pi Model 4 has mini-HDMI sockets, so ensure getting the appropriate cable.
  8. Internet connection: You could use either a wired Ethernet cable or Wi-Fi. If you choose Wi-Fi, then the Model 3 and 4 come with Wi-Fi onboard, whereas the Model 2 would require a small USB Wi-Fi adaptor (cost around £8). During the initial setup phase, I found an ethernet cable to be the easiest but it is possible to setup a Pi using only Wi-Fi.
  9. Software is completely free of charge. You just need Internet access to download it.

Budget price is £75 all in, probably less if you can recycle components from other sources.

You will require a USB keyboard and USB mouse during the initial setup phase only, although these can be avoided by installing a version of the operating system with SSH pre-enabled.

Hardware Setup

Install the Raspberry Pi in its case, connecting the monitor and if required keyboard/mouse.

PIR detector and standard project plastic case. I had to drill out/file holes to suit.

Connect the PIR using the following pinouts.

Firstly, prize off the cap of the PIR detector where you will see the labels for the pins below. Different models do use different pinouts, so worth being extra careful.

The three pins are wired to the GPIO pins on the Raspberry as follows:

  • 5V power Vcc to Pin 2 (top right)- Use a red cable if you have one
  • Ground to Pin 6 – Use a black cable if you have one
  • Sensor output to Pin 11 – Use almost any other colour for this
Image result for raspberry 2 pinout

You can either use pre-manufactured female-to-female connector leads, or solder wires directly. I did the latter, and fitted heat shrink sleeves not shown above).

Software Configuration

You’ll need to create a bootable mini-SDCard on it. I used NOOBS-lite as explained here.

Insert the SDCard, apply power to the Raspberry Pi and Monitor.

Install Raspbian

Select the UK keyboard, English Language and Timezone as required.
The default options may well be correct already

Click on the terminal at the top of the screen

sudo raspi-config

Use option 2 to enable SSH

Optionally, set a static IP address rather than the default dynamic DHCP mode.

Optionally, set a different host name so you can differentiate between Raspberry units if you have more than one.

Change the password (default is raspberry)

exit and reboot

Remote Software Configuration

From now on, you can remotely control and update the Pi from your computer. For Mac users, just open a Terminal screen (it’s a utility in the applications folder). For Windows, use something like PuTTY.

You will need to know what IP address your Pi is using. This can often be most quickly identified by displaying your home router status page.

In the Terminal App on your computer

ssh pi@192.168.xxx.xxx (replace the xxx with the actual IP address of your Pi)

(password) raspberry (replace the default raspberry with your own password if changed earlier)

Install additional software

Install the xdotool package which is used to turn on/off the display

sudo apt-get install xdotool

If you don’t have Chromium installed (it is by default) then install this too.

A couple of Chromium Tweaks

I’ve had an issue with Chromium trying to perform an update that doesn’t exist, so disabled that as follows:

sudo touch /etc/chromium-browser/customizations/01-disable-update-check;echo CHROMIUM_FLAGS=\”\$\{CHROMIUM_FLAGS\} –check-for-update-interval=31536000\” | sudo tee /etc/chromium-browser/customizations/01-disable-update-ch

If you change the hostname of your Pi, then you may get this warning

This is a known issue and you can resolve this by running the following command once:

rm -rf ~/.config/chromium/Singleton* 

Creating the script files

There are a few script and configuration files to insert. I’ve used the nano editor built into the Pi operating system and shown the file contents below. For ease of use, I’ve also uploaded some of these files so they can be accessed directly from the blog. Unfortunately the shell script files cannot be uploaded.

The suffix of the filenames downloaded has been set to .txt for security reasons. You will need to remove or rename the file endings to .py respectively.

Do make sure to leave the formatting/indenting as shown – this does make a difference to the Python operation. More advanced users may be able to use SFTP to upload/transfer these files, but since they are relatively short you may find it easier just to copy and past into Nano.

Nano is quite easy to use, but beware the usual gotcha for Mac users that it requires CNTL rather than CMD key to use the shortcuts.

Add the autostart script to kick things off after boot

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

(the first three lines below should already be present, so just add the extra ones. Replace the your-webpage-url-here with whatever specific page you want to display)

@lxpanel –profile LXDE-pi
@pcmanfm –desktop –profile LXDE-pi
@screensaver -no-splash
@xset s off
@xset -dpms
@xset s noblank
@sed -i ‘s/”exited_cleanly”:false/”exited_cleanly”:true/’ ~/.config/chromium-browser/Default/Preferences
@chromium-browser –noerrdialogs –disable-infobars –kiosk https://your-webpage-url-here.com –incognito

ctrl+X Y return to exit with saving

(note that there are two hyphens “-” and “-” rather than one before each of the arguments in the third from bottom line)

Create three shell scripts for different purposes

Create a shell script to launch with python script that comes later

sudo nano launch-pir-manage.sh

# navigate to this directory, then execute python script
cd /home/pi
sudo python pir-display-manage.py
cd /

Ctrl+X Y return to exit with saving

Create a shell script to modify shell authority

sudo nano xauth_root.sh

touch /root/.Xauthority
xauth merge /home/pi/.Xauthority
export XAUTHORITY=/root/.Xauthority

Ctrl+X Y return to exit with saving

Create a shell script to refresh the browser

sudo nano autorefresh-chromium.sh

DISPLAY=:0 xdotool key ctrl+F5

Ctrl+X Y return to exit with saving

Modify the privileges of these files to make them executable

sudo chmod 755 launch-pir-manage.sh
sudo chmod 755 xauth_root.sh
sudo chmod 755 autorefresh-chromium.sh

Testing the PIR detector

I wrote a short test script that prints a line of text on the console each time the detector is triggered or returns to inactive. The timing for this is set by the hardware of the PIR module itself, so it might be worth reducing the timeouts if they are very long so that the software configuration has full control. In the final project, the actual timeout will be the longer of both hardware and software.

Run the Test-PIR script from the command line and wave in front of the PIR detector to see if it works.

sudo python test-pir.py

Create the python script which runs everything

Create a python script file which runs continuously to supervise the display

sudo nano pir-display-manage.py

import RPi.GPIO a GPIO
import os, subprocess, time os.environ[‘DISPLAY’] = “:0”

displayison = False
last_refresh = time.time()
last_detected = time.time()
print(‘Pi Model is %s’ % GPIO.RPI_INFO[‘P1_REVISION’])
GPIO.setup(17, GPIO.IN)
while True:  
if GPIO.input(17):      
if time.time() > (last_refresh + CHROMIUM_REFRESH_PERIOD):
last_refresh = time.time()       
elif not displayison:
subprocess.call(‘vcgencmd display_power 1’, shell=True)       
displayison = True        
last_detected = time.time()
print(‘display turned on’)
last_detected = time.time()  
elif displayison:
if time.time() > (last_detected + MINIMUM_TIME_ON):
subprocess.call(‘vcgencmd display_power 0’, shell=True)       
displayison = False
print(‘display turned off’)

Ctrl/X Y then return to exit with saving

Then restart the device which should automatically work as designed…

sudo reboot now

Then debug as required.

Pi hidden behind the screen
Raspberry Pi hidden discretely behind the screen. Physically attached to wall with a velcro strip.


The PIR detector has a built in hysteresis of about 3 minutes by default. It also has adjustable threshold to trigger. You can play around with the settings on the PIR device itself.

A constant is defined in the python script to set the minimum time the screen will be on. Typically that’s shorter than the PIR detector but is something to consider if you want it to be very long or short.

There are many ways to implement this application, and no doubt very many other more elegant ways of achieving a similar result. So please do your research and consider alternatives.

For security, set a unique password and hostname for the device, otherwise it can easily be hacked. You should also schedule a cron job that daily checks for and downloads updates. This isn’t quite as trivial as it should be as explained here

The display is set to refresh every 10 minutes. The refresh time is a constant in the python program file, specified in seconds. Many web pages won’t require this and so those lines can be removed or the delay changed to a much longer period.

If you wanted to display different documents etc, rather than make the Pi program more complex, you could use a Google Cloud page which is remotely updated with different content. This can include a revolving slide show, presentation, video or other material and is easier to update remotely from any laptop or other computer.


I’m sharing these details to help anyone interested to develop a similar project on their own, whether related to Flying Club or any other purpose.

This is all shared freely to do with as you wish, including for any commercial purpose.

While I would be interested in feedback from those who have implemented the solution – just comment below. While I am especially keen to hear about errors and any corrections or clarifications, I regret I am unable to offer technical support for those new to Raspberry Pi projects like this. There is plenty of information available online, and Google is your friend to find it!

Thanks to those who have already sent me private feedback and corrections. You know who you are!

Leave a Reply

Your email address will not be published. Required fields are marked *