简体   繁体   中英

light sensors in smartphones

I would like to know how light sensors in smartphones work?Both the hardware and software side of it. Any good articles regarding the same would be helpful. Any help appreciated.

Hardware side: Most light sensors are Photodiodes . When exposed to light, they create a current. The brighter the light, the higher the current. This current is then "converted" to a sequence of bits.

(Purely theory from now on) This is then sent to the part of the OS handling the light sensor. It will recieve different values (Oh yeah, there's a load of light, here's a value of 64000 for you / Nope, pretty dark right now, have a 200) and do whatever he's supposed to do with these values.

Well sounds like people answered the hardware side. For the software side it's pretty simple.

public class LightTrigger {
private SensorManager mgr = null;

    @Override
public void onCreate(Bundle savedInstanceState) {
        //YOUR CODE HERE
        mgr = (SensorManager) ctxt.getSystemService(Context.SENSOR_SERVICE);
        mgr.registerListener(listener,
    mgr.getDefaultSensor(Sensor.TYPE_LIGHT),
    SensorManager.SENSOR_DELAY_UI);
    }

    private SensorEventListener listener = new SensorEventListener() {
        public void onSensorChanged(SensorEvent e) {
            //Handler code goes here
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
            //I don't usually use this for light
        }
    }
}

What I've found is that the sensor values don't change continuously. I usually see values coming off the sensor like -- BRIGHT (~1000) -- DIM (~600) -- DARK (~100) -- with nothing in between. I think that could be because the light sensor on my phone is inset (recessed from direct light) right next to the phone speaker. It was probably designed mainly to help figure out if I'm holding the phone up to my head.

Hopefully that helps!

Well, I am not sure how helpful this would be, but for the software side, you can look at Qt Mobility (the smartphone related library add-on for Qt).

For eg http://doc.qt.nokia.com/qtmobility-1.0/sensors-api.html lists the Sensors API. I believe the one you are looking for is the Ambient Light sensor.

As for the hardware, a quick search reveals the following wikipedia link: http://en.wikipedia.org/wiki/LED_as_light_sensor#LED_as_light_sensor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM