Proximity Switch

by KT-AT in Circuits > Assistive Tech

538 Views, 6 Favorites, 0 Comments

Proximity Switch

PXL_20250227_144411420.jpg

Some people need to send input to an electronic device without physically touching it with their hands. A proximity switch can send input to a device when it detects that something is close to it. This can be very important for someone with a disability who can't access devices using conventional methods. These switches can allow someone to scroll through their computers and select objects to click on without having to touch anything. This access method is called switch scanning. Commercially available proximity switches and adaptors that connect them to computers or tablets can cost hundreds of dollars and have limited customization options in terms of both appearance and function.


This DIY version of a promixity switch costs around $25. The appearance of the switch and how it's mounted are all customizable because the housing is 3-D printed. The code of the switch can be adjusted using free software, meaning the function can be customized as well.


If you're anything like me, you might be thinking that you could never make something like that because you don't know how to code or solder or 3D print.

Do you know how to copy and paste?

Do you know how to left and right click on files and links?

Do you know how to get to your download folder?

Congratulations, you have the skills you need to make a proximity switch!

(The 3-D printing is optional. Making a case for the electronics can keep the wires in place better, protect them, and make them look nicer, but it's not required for them to work.)

Use a printed circuit board (PCB) and a proximity sensor to create a customizable proximity switch that can activate any keypress. No soldering is required or coding is required! You need to know how to download and unzip files, copy, and paste. That's it!


Issues that I know about:

  1. Sometimes there's a line between bullets that I copied and pasted from the PowerPoint and sometimes there isn't. I don't know why. I like the double-spacing better but I don't know how to tell it to that and formatting is a bear.
  2. Introduction: Needs a video of the switch in action controlling something
  3. Supplies is missing a photo of the QT Py housing because a version I like doesn't exist yet despite the best efforts of multiple people, including me.
  4. A customization file is possible to make changing the code easier and I'll do my best to figure that out eventually.


Please leave feedback telling me how to make this better!

Edited 2/28/2025 to add more information and materials about mounting, and add the STL for the mount.

Supplies

QT Py labled.jpg
vcnl4040 labeled.jpg
Stemma QT cable.jpg
USB A to C cable.jpg
vcnl in housing.jpg

Adafruit QT Py RP2040 printed circuit board

VCNL 4040 proximity sensor

STEMMA QT cable to connect the proximity sensor to the printed circuit board

USB A to USB C cable that transfers power AND data (can also be easily purchased from Amazon, just check the listing to make sure it specifies that the cable transfers power AND data)

OPTIONAL

3-D printed case for the proximity sensor

3-D printed case for the printed circuit board (a link to magnets that can be used to close the case is linked on this page)

Modular hose for mounting (the QT Py 2040 is small, but not small enough to thread through modular hose)

See attached file for a clamp with an opening that 1/4 inch modular hose can fit into. Recommended material is ABS.

Industrial twist ties (can loop around the outside of the modular hose to secure the wires and housing)


Plug Everything In

i am still plugged in.jpg

Connect the VCNL 4040 proximity sensor to the QT Py using the STEMMA cable (black cable with the four different colored wires exposed at the ends)

  1. Plug one end into the smaller connector on the QT Py (the word BOOT is written above it) and the other into either connector on the VCNL 4040 proximity sensor (both work the same).

Plug the QT Py into your computer using the metal USB-C cable (small oval end goes into the QT Py, the larger rectangular end goes into your computer).

For Mac users: You might need a USB adaptor, but this setup has been tested and works on Mac!


Put the QT Py Into Bootloader Mode

qt py boot and reset button.jpg
RPI-RP2 screenshot.jpg
  1. connect the QT-Py to your computer with the USB cable.
  2. press and hold the Boot button.
  3. press and release the Reset button.
  4. release the Boot button.

Make sure it worked!


•Look on the left where your list of drives are

•You should see a drive that says RP1-RP2 around where you’d see a USB drive pop up when you plug one of those in.

Downloads

Troubleshoot If Needed

USB A to C cable.jpg
  1. Make sure you are holding down the boot button WHILE you hold down AND release the reset button. Don't release the boot button until AFTER you've pressed and released the reset button.
  2. If you don't see the RPI-RP2 drive, make sure you have a USB cable that transfers power AND data. You can't tell just by looking! If you're not positive that your cable transfers both data AND power, try another cable.

Download Circuit Python

circuit python screenshot.jpg
  1. Go to https://circuitpython.org/board/adafruit_qtpy_rp2040/
  2. You need the most recent version, which was 9x at the time of making this tutorial
  3. Click, "Download .UF2 now"

Put CircuitPython on QT Py

•Open your downloads folder

•Find the file adafruit-circuitpython-adafruit_metro_rp2040-en_US-9.1.3.uf2 (it will probably be at the top for you)

•Click and drag that file down to RP1-RP2, or copy and paste

•You can also right click, go to “send to,” and select RP1-RP2

•The name of the drive will go away, it will beep, and the name of the drive will reappear as CIRCUITPY

Download File Libraries

circuit python libraries.jpg

•Download the Circuit Python libraries from https://circuitpython.org/libraries

  1. Scroll down a little to see the bundle

•Open your downloads file and find adafruit-circuitpython-bundle-9.x-mpy-20240910 (it will probably be at the top of the folder)

•If the number at the end of the file name is different, an updated version may have come out since this tutorial was made

•Unzip it!

Downloads

Put Files on QT Py

circuitpy drive screenshot.jpg

•Using the search function in Windows Explorer, search for the following file inside of the adafruit-circuitpython-bundle-9.x-mpy-20240910 folder :

  1. Adafruit_vcnl4040.mpy

•Drag that file to your CIRCUITPY drive and put it in the lib folder

  1. Make sure you put it inside the lib folder! The computer will be looking for it in that specific location
  2. You can also copy (ctrl + c) and paste (ctrl + v) the files and folders to the lib drive on CIRCUITPY

•Repeat that process for the following folders:

  1. adafruit_bus_device (a folder)
  2. adafruit_register (a folder)
  3. adafruit_hid (a folder)

Put Code on QT Py

Select the code you want, highlight it, and copy it. Click on your CIRCUITPY drive and find the code.py document. Open it and paste your code into it. And you're done! Additional steps are provided for customizing and troubleshooting, but your switch should be working now.

Download Mu Editor to Troubleshoot and Customize

mu editor screenshot.jpg

•Get directions for how to download Mu Editor from https://learn.adafruit.com/welcome-to-circuitpython/installing-mu-editor

•Get Mu Editor from https://codewith.mu

•Choose Circuit Python when prompted at start-up

If your switch is plugged it and set up, it should automatically open up the code. Click serial mode to see exactly what your switch is doing second by second!

Get AI to Help You Customize

It is possible to change the keypress you're simulating, the delay time, and the amount of proximity change. I recommend copying and pasting your code into Chat GPT or your favorite AI. Tell it you've made a proximity switch using a QT Py 2040 connected to a VCNL4040 with a STEMMA QT cable, give it the code, and ask it to alter the code according to your specifications. Then you can copy and paste the altered code back into code.py on Mu Editor to see how it works.

If AI is writing or tweaking your code for you, please note that i2c = busio.I2C(board.SCL1, board.SDA1) MUST be in the code. This tells the computer you have something plugged in the STEMMA QT port instead of wires soldered. Chat GPT left that out during development twice.