Proximity sensor
Proximity sensors are also known as position sensors and allow you to determine how close your smartphone is to an object (such as your face). The distance can be measured in cm. However, most proximity sensors only return Far
/Near
information. Therefore, the return value will be 0
or 1
, where 0
/LOW
is Far
and 1
/HIGH
is Near
.
As usual, you can add a Proximity Sensor widget to your project canvas from the Widget Box (Figure 6.19):

Figure 6.19: Proximity Sensor widget
Configuring the Proximity Sensor widget
The following steps will show you how to configure the Proximity Sensor widget with a virtual pin:
- Tap the Proximity Sensor widget to open the
Proximity Sensor Settings
page. - Under
INPUT
, tapPIN
and from the list view, selectVirtual
followed byV1
. Keep theWRITE INTERVAL
as100 ms
. - Then, tap
OK
. YourProximity Sensor Settings
page should look like this (Figure 6.20):

Figure 6.20: Virtual pin configuration for proximity sensor
- Tap the back arrow on the toolbar to go to the canvas...