I would like to detect an impending human touch on my microcontroller (I use an ESP32) - before it happens and setoff some kind of beeper (nasty humans, yees... touching electronics when you know you shouldn't). TL;TR: How can I reliably detect the presence of a finger within 0-3cm of my device?


  1. it should allow for omnidirectional sensing of 'hand' distance (<3cm would be sufficient)
  2. the device size should ideally remain as small as possible (e.g. size of arduino nano)
  3. should be implementable/interface-able with an arduino-like microcontroller and provide a readout of the range

Here are the methods I could come up with to go about solving this problem practically with some pro's and con's (mostly the latter):

  • sound based: Several ultrasonic sensors (e.g. the hc-sr04) mounted. This would probably have some 'holes' in detection even if one sensor per cardinal direction is mounted. Sensors also tend to be somewhat large.
  • electromagnetic frequency/light based (sorted by typical wavelength band):
    • laser-based: not omnidirectional.
    • IR based: might be affected by daylight
    • far IR based: common sensors don't seem to be optimally suited for short distances, and usually they are quite large (this may also be just due to the Freznel lens, but this would allow omnidirectional sensing to my understanding)
    • microwave or 'radar' based: might be optimal, but common, affordable sensors seem to have issues for omnidirectional sensing (e.g. RCWL-0516). Also seem to have issues with short range detection.
  • capacitive: seems to work well for certain kinds of applications (like the musical instrument theremin). Apparently needs to be calibrated a lot though (imagine chip lying on a metal surface, or you taking your shoes off - apparently this varies signal strength greatly and could lead to false positives - i.e. chip beeping for no reason) - and apparently requires an antenna.


  1. Are there any known methods that I have not discovered (see list above, that I will update), or any ideas that my imagination and googling skills seemed to have lacked to come up with?
  2. Is there any recommended method, from an theoretical engineering principle side (and feasibility/practicality side) to do this? I.e. would you recommend any method listed above for this problem?
  3. currently, I would tend towards a capacitive sensor for this approach - however I seem to be lacking some kind of integrated circuit (IC) that would allow me to do this easily. This, old article a bit more, but it's unclear how much calibration is needed and how well this would work. Then another question remains, can this be optimized using the ESP32 (or any other) touch sensors?
  • 1
    \$\begingroup\$ Farnell - PIR Sensors \$\endgroup\$
    – user103993
    Commented Oct 30, 2020 at 9:28
  • 2
    \$\begingroup\$ Detecting an event before it happens requires time-lord engineering. \$\endgroup\$
    – Andy aka
    Commented Oct 30, 2020 at 9:52
  • 1
    \$\begingroup\$ @Andyaka ehm... well in this case the event is the user approaching the device to a given radius (1-3cm). But, yes, technically speaking, I agree in resp. to time-lord. Take it with a grain of salt, I'm a noob in electronics =) \$\endgroup\$ Commented Oct 30, 2020 at 10:13
  • \$\begingroup\$ The easiest and most reliable fix is by engineering a physical barrier. Why can't you do this? \$\endgroup\$
    – Andy aka
    Commented Oct 30, 2020 at 10:16
  • 1
    \$\begingroup\$ a bit multipurpose here, I was also going to setup some user-interaction, e.g. make beeper sound different the closer you get. I thought first step would be best to just have a 0 or 1 detection. It's possible this is a question that suffers from an XY issues \$\endgroup\$ Commented Oct 30, 2020 at 10:19

1 Answer 1


For capacitive sensor check PIC12F1822/23 from Microchip. You can also try an accelerometer as sensor. I created some device, connecting analog accelerometer module to ADC input MC and it senses even light touch. Also you can try some barometric sensor or electret microphone. It will sense pressure change from air move. Active sensors, like ultrasound and laser may not fit your application because they have dead zone. Infrared sensor like AD8833 can be useful too, but it needs processing image.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.