Proximity Switch- Extra Sensitive Time of Flight Sensor

by KT-AT in Circuits > Assistive Tech

266 Views, 3 Favorites, 0 Comments

Proximity Switch- Extra Sensitive Time of Flight Sensor

tof edited.JPG
tof.jpg
tof switch.jpg

My original tutorial is here, and the explanation for both projects is below the line. This version uses a time of flight sensor, which has a bigger range than the original sensor I used. The process to set it up and code it is the same as my original tutorial. The finished product is the same size as in my original tutorial and uses the same housing. Which version you follow depends on your needs/the needs of your user. If possible, I recommend purchasing both sensors and seeing which works best in the environment you/your user are in, since the lighting can affect the accuracy of the sensors.

I found that for a cheek-activated switch, the VCNL4040 from my original tutorial was more accurate at detecting my cheek movement. At further distances, the sensor from this tutorial was great at detecting when my hand moved directly over top of it. The product description will tell you more about the distances you can work with.

_______________________________________________________________________________________________

Proximity sensors are in many kinds of technology, like sinks, water fountains, paper towel dispensers, and automatic doors that activate without having to be touched. This same technology can help individuals with disabilities who struggle to use interfaces such as touchscreens, computers, keyboards, and traditional computer mice. These sensors can send a signal to a computer or tablet to activate an icon (enter keypress or left mouse click) or move to the next icon (tab keypress) when they detect that something is close to it.

In the past year, I have been on a journey with this technology that resulted in a $25, highly customizable proximity switch that gives access to computers and tablets without having to touch them using an access method 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.

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. Step 7 needs a video of transferring the files, pointing out the file name is slightly different from the sensor name
  2. Step 8 needs refined code posted
  3. 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.
  4. Introduction: Needs a video of the switch in action controlling something
  5. 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.
  6. 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!

Supplies

Stemma QT cable.jpg
QT Py.jpg
VL53L0X sensor.jpg

Adafruit QT Py RP2040 printed circuit board

Adafruit VL53L0X time of flight distance sensor- ~30 to 1000mm

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 time of flight 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

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 in 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.

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 Circuit Python 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!

Put Files on QT Py

VL53L0CX files.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_vl53l0x.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. Please note that I haven't built a json file yet but the information is in the code. I will update this tutorial once I build that file, which will make customizing much easier.

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 VL53L0X 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.