A proximity sensor on a smartphone works on the closeness of any object to the smartphone without any physical contact. It detects if something is nearby or not and accordingly triggers a function internally. For majority of the smartphones on the market, this sensor is usually placed at the top nearby the front-facing camera.
Actually, most of the mobile phones use IR-based proximity sensors to detect the presence of your ear. Precisely, this is done for two reasons: To minimize on the power that the smartphone display consumes by turning off the LCD back light, and to disable the touch screen to avoid unintended taps by your body parts like the cheek during a phone call.
If your smartphone has a large screen display to it, you should have realized just how much power it does consume. It is thus a good idea to have it off when not in use especially when the phone is in the pocket. So, if the proximity sensor detects that the phone is held near the wall of your pockets, it will generate a message to your phones processor telling it to switch off your screen.
It does so using the infra red transmitter-receiver pair comprised in it. The transmitter is an LED and emits infrared light. If you place an object close to it, the light will bounce back. This light is picked up by the receiver which responds by turning off the display.
Read About: Future selfie cameras will be ‘under-display’ with no notch, here is the proof
Both Android and iOS systems do have an API for proximity sensor. If you wish, you can customize for any of the apps you use most, such as the flash light, or WhatsApp, to let it switch off if you put your phone in the pocket.
There are a number of types of proximity sensors and each uses a different method for sensing. Some types include capacitive and photoelectric sensors which are more suited to plastic and organic targets, as well as inductive proximity sensors which can only detect metal targets.