Experiment: Proximity Stopwatch
The experiment "Proximity Stopwatch" reacts to changes of the distance reported by the proximity sensor and measures the time inbetween. The acuracy depends on the speed of the proximity sensor in your device, but it typically does not get better than 200ms. The Experiment: Acoustic Stopwatch and Experiment: Motion Stopwatch achieve more acurate results, but react to motion and sound.
Note that on iPhones the sensor only works in portrait orientation (i.e. while holding the phone upright). Also, we cannot prevent the iPhone from turning of the screen when the proximity sensor is triggered.
Also note, that even though you can set a threshold, almost every proximity sensor only gives two distinctive readings, corresponding to near and far.
There are no special requirements.
There is no specific setup.
The analysis is not too complicated, but uses a few if-modules to decide how many events have already been counted. Otherwise, chunks of data are analyzed for their maxima and compared to the threshold. If the threshold is exceeded, we use the time of the maximum.
Problems and resolutions
- The screen turns off when the proximity sensor is triggered. This behavior is normal for iPhones and cannot be prevented.
- The proximity sensor does not work. If you are using an iPhone, this can be the case when the phone is in landscape mode (i.e. when the screen is turned sideways). In this orientation, the iPhone simply does not allow to read the sensor.