5266+ reviews
Order by 16:00 for same day shipping
14 days return
DE
EN
Individual
Business
In this project you place the distance sensor pointed at yourself when you are sitting behind your PC or Laptop.
Nothing will happen now, but if you get up and walk away from your PC, the screen will automatically lock.
This RPi Pico project is perfect to get started with the Thonny programming tool and CircuitPython.
You will learn how to connect the Pico to your PC and install programs on it.
A Raspberry Pi Pico is a microcontroller board developed by the same organization responsible for the popular Raspberry Pi single-board computers.
Some features of the Raspberry Pi Pico include:
An HC-SR04 is an ultrasonic distance sensor that is often used in electronic projects, especially in the world of hobby electronics and robotics. This sensor uses ultrasonic sound waves to measure the distance between the sensor and an object. Here is how it works:
HC-SR04 sensors are easy to use and can be connected to microcontrollers such as Arduino or Raspberry Pi to measure object distances and perform obstacle detection. They are popular for projects such as building automatic door openers, robot navigation, distance measurement equipment and more.
We will first install CircuitPython on this Raspberry Pi co.
Download the uf2 file from the website below:
Download and install Thonny on your PC.
( https://thonny.org/ )
Select the MicroPython Interpreter under > Options > Interpreter CircuitPython (Generic)

Now some python modules need to be installed.
Open the Tools > Manage Packages menu.
Now search for adafruit-circuitpython-hid and adafruit-circuitpython-hcsr04 and install them


Connect the sensor to the Raspberry Pi co as shown in the diagram below.

Now you can retype the program below into the Thonny interface.
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
import board
import adafruit_hcsr04
import time
ultrasone = adafruit_hcsr04.HCSR04(trigger_pin=board.GP4, echo_pin=board.GP5)
toggle = 0
time.sleep(5)
while True:
# print((ultrasone.distance,))
if ultrasone.distance > 100 and toggle == 0:
toggle = 1
kbd = Keyboard(usb_hid.devices)
kbd.press(Keycode.LEFT_GUI)
time.sleep(1)
kbd.press(Keycode.L)
time.sleep(0.1)
kbd.release(Keycode.L)
time.sleep(0.1)
kbd.release(Keycode.LEFT_GUI)
time.sleep(1)
kdb.release_all()
time.sleep(10)
if ultrasone.distance < 100:
toggle = 0
time.sleep(1)Explanation of the program:
Then press save, and save the program on your own computer.
Press the red stop sign button to restart the 'backend'.
(Thonny is now reconnecting to your Pico)
Then you could press green button (Run current script).
If the pico is now removed from the computer and reconnected the program will not start.
We only tested the programming code.
To enable automatic start we need to save the program again, but then select the pico.
File > Save As > Raspberry Pi Pico

Save the program with the name main.py . The pico will automatically start the program with this name when you connect the Pico to a USB port.
In this case you will need a connection to your PC and Thonny to see the measured results!
Sit behind your PC or Laptop and point the sensor at yourself.
Nothing will happen now, but if you get up and walk away from your PC, the screen will automatically lock.