Using Sensors in your Windows 10 Universal Apps

Using Sensors in your Windows 10 Universal Apps

As sensors are becoming a part of the life nowadays the Windows 10 SDK is filled will lots of new sensors which helps the users from keep the health fit to knowing what the user’s needs. The new sensors that are added to the SDK are

  • Altimeter
  • Barometer
  • Pedometer
  • ActivitySensor
  • ProximitySensor.


Let’s see them in detail. barometer Altimeter: The Altimeter is used to measure the relative altitude. The Altimeter class has an Event called ReadingChanged which gets triggered whenever a new value is sensed by the sensor. The ReportInterval property is used to set the interval at which the sensor has to report.


Altimeter altimeter = Altimeter.GetDefault();
AltimeterReading altimeterReading = altimeter.GetCurrentReading();
altimeter.ReportInterval = 500;
altimeter.ReadingChanged += Sensor_ReadingChanged;
private void Sensor_ReadingChanged(Altimeter sender, AltimeterReadingChangedEventArgs args)
{
AltimeterReading reading = args.Reading;
}

Related Post : Creating an Universal App that Reads Your Heart Rates from Microsoft Band

Barometer: The Barometer is used to measure the atmospheric pressure. The Barometer class has an Event called ReadingChanged which gets triggered whenever a new value is sensed by the sensor. The ReportInterval property is used to set the interval at which the sensor has to report.


Barometer barometer = Barometer.GetDefault();
BarometerReading reading = barometer.GetCurrentReading();
barometer.ReportInterval = 500;
barometer.ReadingChanged += Sensor_ReadingChanged;
async private void Sensor_ReadingChanged (object sender, BarometerReadingChangedEventArgs e)
{
BarometerReading reading = e.Reading;
}

Pedometer: The Pedometer is used to measure the users steps. This Pedometer detects steps both when walking and running. This sensor is highly used for health and fitness. Sensing user’s health information results in having a good healthier life.


Pedometer pedometer = await Pedometer.GetDefaultAsync();
pedometer.ReportInterval = pedometer.MinimumReportInterval;
pedometer.ReadingChanged += Pedometer_ReadingChanged;
async private void Pedometer_ReadingChanged(Pedometer sender, PedometerReadingChangedEventArgs args)
{
PedometerReading reading = args.Reading;
}

ActivitySensor: ActivitySensor is used to detect the user’s activity based on the user’s motion. This sensor set to idle state when the device is set in a table without any movement. Some of the uses of this sensor are saving the power when the user is not using the device.


var activitySensor = await ActivitySensor.GetDefaultAsync();
var reading = await activitySensor.GetCurrentReadingAsync();
activitySensor.ReadingChanged += ReadingChanged;

ProximitySensor: Sensors that are used to detect the presence. This sensor is used to detect weather the user has intentionally touched the screen or it has been accidentally touched and behave as per that. Not only this even the gestures can be detected by this sensor.


ProximitySensorReading reading = proximitySensor.GetCurrentReading();
proximitySensor.ReadingChanged += ReadingChanged;
void ReadingChanged(ProximitySensor s, ProximitySensorReadingChangedEventArgs e)
{
ProximitySensorReading reading = e.Reading;
}

Hope this might have helped.

Arun Kumar

Arun kumar Surya Prakash, is a  Developer  Consultant. He  is a Microsoft Certified Solution  Developer  for Store App Development, and a Azure Solution Developer. His core skills is on developing Windows Store App and Cross Platform App development. You can follow him @arunnov04

One Comment to “Using Sensors in your Windows 10 Universal Apps”

Comments are closed.