Introduction
In Windows 10 the light sensor is a type of environmental sensor that allows apps to respond to changes in the user's environment.
An ambient light sensor is used to extend battery life and enables easy-to-view display that is optimized to the environment in portable devices such as tablets, smartphones, and laptops.
It is very helpful to conserve battery life for mobile phones.
Let’s see the steps:
- Create a new Windows 10 universal app.
- Design the UI according to your wish; here I have created one button to start the light sensor reading.
- Now go to the coding part and write the following code. Firstly, add the following namespace to access the Light sensor API.
- using Windows.Devices.Sensors;
- Create one object for the LightSensor,
- LightSensor mylightSensor;
- Now get the default properties and reading using GetDefault method.
- mylightSensor = LightSensor.GetDefault();
- Then set interval to read the value from certain interval.
- mylightSensor.ReportInterval = 15;
Now create one event light sensor reading changes to handle the readings and assign it to your light sensor.
- mylightSensor.ReadingChanged += MylightSensor_ReadingChanged;
Now start the application and get the values from the light sensor.
- LightSensor mylightSensor;
- publicasyncvoid StartLightSensor() {
- mylightSensor = LightSensor.GetDefault();
- mylightSensor.ReportInterval = 15;
- mylightSensor.ReadingChanged += MylightSensor_ReadingChanged;
- }
- privatevoid MylightSensor_ReadingChanged(LightSensor sender, LightSensorReadingChangedEventArgs args) {
- LightSensorReading read = args.Reading;
- string values = String.Format("Light Sensor Reading:\t{0}\t{1}", args.Reading.Timestamp.ToString(), args.Reading.IlluminanceInLux.ToString());
- }
Read more articles on Windows 10:
Summary
In this article, we learned about How To Use Light Sensor In Windows 10 Universal App.

Asfend YarPosted Feb 27, 2016, 1:53 AM
please upload the gif image of how light sensor works ??
Suresh MPosted Feb 23, 2016, 10:55 PM
Thank you
Kumaresh RajalingamPosted Feb 23, 2016, 8:13 PM
Good one sir
Vignesh ManiPosted Feb 23, 2016, 4:46 PM
Good one
Santhakumar MunuswamyPosted Feb 23, 2016, 2:01 PM
Thanks for sharing
Sibeesh VenuPosted Feb 23, 2016, 9:11 AM
Nice Share
Shubham KumarPosted Feb 23, 2016, 5:49 AM
nice share