Another IR solution. Inexpensive with a range of about 3 inches. https://www.instructables.com/id/Make-an-Attiny13-based-IR-proximity-sensor-for-2/
Select as Best AnswerUndo Best Answer
I have the most cheap and perfect way, but it's in portuguese... i guess you could translate on google... ask me if you want the link :)
of course we do
for a very short range you could use a light sensor
would this work?https://www.instructables.com/id/A-very-simple-proximity-detector/
It depends on what the range is you want to measure.
For larger ranges you can use an ultrasonic sonar sensor or a PIR sensor (passive infrared). From my experience, PIR is very good at detecting people, but sometimes not as good at detecting anything else. Sonar can detect most anything pretty accurately.
At shorter ranges you may consider using a capacitance sensor or an IR LED and a phototransistor.
It depends what you are trying to do.