Office Proximity Sensor
I love my QC35s at work. Except when someone sneaks up behind me. This is a proximity sensor project to detect when someone is walking up behind me. The idea is to turn on a led that's in my field of view for a few seconds when someone walks up.
Didn't work very well at first, was flaky and erratic. Turns out, it needs 12V which I didn't have as part of the RPI. ...And I was also too lazy to go get a 12V supply.
Here's the initial prototype of using the range finder to at least detect range.
A few things I wanted to add around the basic structure provided in the tutorial. Once you learn how to use the RPI GPIO they are pretty easy.
- LED for indication
- A method for changing the detection range
A few years ago for Halloween, I bought these LEDs of Amazon. They are pretty cool. All you need to do is bias them an the LED blinks RGB. They will definitely get your attention.
I had an idea of the width of the opening of my cube, but I also figured that once I mounted the sensor, the actual range that a person would be within could change. I went back to my random part bins and found a 6position dip switch. Instead of doing a binary range based on the value of the dip (which is something I might still go back and do) I just used it more like a decade box I add 40cm of range per bit position set. Position 1 = 40cm, 1 and 2 = 80 cm, and so on. Not super complicated, and if you look at the code, it just picks up on the first position it finds so technically if you only set position 2, then you only get 40cm. I agree, lazy, but it's a hobby, not a product.
If you look at the datasheet, the range of the sensor is really around 2m, so that's my max value.
Running on the RPi
On the RPi, this is all running as a python script. for testing, its as simple as navigating to where you have the files tored and running
> python directory/scriptname.py
To get this to run automatically (especially for a headless RPi) I modified /etc/rc.local to include the line above command line.
Proto Card Build
Once the circuit was proven on the breadboard, I moved it to a RPI prototype board for a cleaner fit. Yes, the lid cut outs are kinda hack, but I don't have a CNC yet and it was too late to use the Dremmel without waking the house.
import RPi.GPIO as GPIO
#range select inputs
#configure gpio direction
distance=1000 #set high
detection_Range = 0.00 #distance in centementers
print("DISTANCE MEASUREMENT IN PROGRESS")
print ("waiting for sensor to settle")
print ("gpio status: ", GPIO.input(RANGE4), GPIO.input(RANGE3),GPIO.input(RANGE2), GPIO.input(RANGE1), GPIO.input(RANGE0))
detection_Range = 0
print ("Distance:", distance, "cm")
print ("Distance Range:", detection_Range)
if (distance GPIO.output(21,True)
#zero everything out