distance detection and prevention methods
Consider using a Passive Infrared sensor for the purpose:



Images from eBay listings.

You can find a prebuilt module like the one above on sites like eBay, for as little as US$1.50 including international shipping. 

The module linked above has sensitivity adjustment, so it can be tuned to react to motion within a specific range. 10 cm may be too small a distance, beyond the lowest sensitivity setting, as per an experiment I just did. The minimum sensitivity setting seems to represent about 90 cm.

False positives are very low at the low sensitivity you would operate this module at.

Using such PIR modules is very simple: They need a DC supply of (typically) 3.3 to 5 Volts, very low current required, and the signal line goes high when motion is detected, falling back to low after an adjustable period (the second preset on the module). 

Coding for it is simple too: There are several open source examples for using these modules with Arduino, MSP430 Launchpad, and various PIC, ATmega and ATtiny microcontrollers .