The Person Sensor from Useful Sensors is a small $10 hardware module that detects nearby faces. In this example I'll show you how to use it to auto-lock your screen when you step away, and minimize the current window if somebody is looking over your shoulder.
To get started plug the port on the end of the Trinkey into the sensor using the cable. Then press the
bootsel button on the Trinkey while plugging into a USB port on your laptop. This should open up a
RPI-RP2 drive in the file viewer.
There's a step by step guide to installing CircuitPython on a Trinkey here but the summary is that you download CircuitPython for the Trinkey, and copy it onto the
RPI-RP2 drive. Once the copying has completed, you should see a new
CIRCUITPYTHON drive appear instead.
We need the adafruit_hid library to do keyboard emulation, so the first step is to download a big bundle of all the CircuitPython libraries from circuitpython.org/libraries. You'll need to find the right bundle for your CircuitPython version.
Once you have that downloaded, unpack the bundle on your local machine. In the file viewer, go to the
lib folder within the unpacked bundle and copy the
adafruit_hid directory into the
lib folder on the
Now you need the CircuitPython code to check the sensor and lock the screen if necessary. If you're familiar with
git, you can use the command line to clone the github.com/usefulsensors/person_sensor_screen_lock repository. If not, you can just download the code as a ZIP archive from this link and unpack it on your machine.
If you're on Windows, the code should work with no changes. On MacOS or Linux you'll need to modify what keys are sent to cause the screen to lock. If you look at the end of
code.py, you should see commented-out options for the different operating systems. Open this in a text editor and add a
# before the Windows line, and remove the
# before the line for your OS.
Now your Trinkey is set up, copy the
code.py file from this repository into the
CIRCUITPYTHON drive. You should notice that the green LED on the Person Sensor lights up when it sees your face. If you point it away from yourself for more than five seconds, you should find that the screen locks! It will also attempt to minimize the current window if it detects somebody looking over your shoulder for more than a second.
The sensor needs to be the right way up, with the connector at the top, and pointing towards you. If you have a long enough Qwiic cable, you can try mounting it on the top of your laptop screen.