Portal for car enthusiasts

What is a magnetic sensor. Sensors in smartphones: hidden innovations

A modern smartphone can hardly be called just a computer, because it can do much more than its stationary ancestor: it can measure the temperature, and tell the height above sea level, and determine the humidity of the air, and if you suddenly forget your orientation in space or lose gravity, everything will be fixed. And they help him in this, as you probably already guessed, sensors aka sensors. Today we will get to know them better, and at the same time we will check whether we are really on Earth. 😉

All sorts of sensors are needed!

To work with hardware sensors available on Android devices, use the class SensorManager, a reference to which can be obtained using the standard method getSystemService:

SensorManager sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);

To start working with a sensor, you need to determine its type. The easiest way to do this is with the class sensor, since all types of sensors are already defined in it as constants. Let's consider them in more detail:

  • Sensor.TYPE_ACCELEROMETER- a three-axis accelerometer that returns acceleration along three axes (in meters per second squared). The associated coordinate system is shown in fig. 1.
  • Sensor.TYPE_LIGHT- a light sensor that returns a value in lux, usually used to dynamically change the brightness of the screen. Also, for convenience, the degree of illumination can be obtained in the form of characteristics - “dark”, “cloudy”, “sunny” (we will return to this).
  • Sensor.TYPE_AMBIENT_TEMPERATURE- thermometer, returns the ambient temperature in degrees Celsius.
  • Sensor.TYPE_PROXIMITY- a proximity sensor that signals the distance between the device and the user (in centimeters). When the screen goes blank during a call, this sensor is triggered. On some devices, only two values ​​are returned: “far” and “close”.
  • Sensor.TYPE_GYROSCOPE- a three-axis gyroscope that returns the speed of rotation of the device along three axes (radians per second).
  • Sensor.TYPE_MAGNETIC_FIELD- a magnetometer that determines the readings of the magnetic field in microtesla (µT) along three axes (available in smartphones with a hardware compass).
  • Sensor.TYPE_PRESSURE- an atmospheric pressure sensor (in a simple way - a barometer), which returns the current atmospheric pressure in millibars (mbar). If you remember a little physics, then using the value of this sensor, you can easily calculate the height (and if you don’t feel like remembering, you can use the ready-made method getAltitude from object SensorManager).
  • Sensor.TYPE_RELATIVE_HUMIDITY- relative humidity sensor in percent. By the way, the combined use of relative humidity and pressure sensors allows you to predict the weather - of course, if you go outside. 😉
  • Sensor.TYPE_STEP_COUNTER(since API 19) - the counter of steps since the device was turned on (it is reset only after a reboot).
  • Sensor.TYPE_MOTION_DETECT(since API 24) - smartphone motion detector. If the device is in motion from five to ten seconds, it returns one (apparently, a backlog for the hardware anti-theft function).
  • Sensor.TYPE_HEART_BEAT(with API 24) - heartbeat detector.
  • Sensor.TYPE_HEART_RATE(with API 20) - a sensor that returns the pulse (beats per minute). This sensor is notable for requiring explicit permission. android.permission.BODY_SENSORS in the manifest.

The listed sensors are hardware and operate independently of each other, often without any filtering or normalization of values. "To make life easier for developers" ™ Google introduced several so-called virtual sensors that provide more simplified and accurate results.

For example, a sensor Sensor.TYPE_GRAVITY passes the accelerometer readings through a low-pass filter and returns the current direction and magnitude of gravity along the three axes, and Sensor.TYPE_LINEAR_ACCELERATION uses an already high-pass filter and receives acceleration figures in three axes (without taking into account gravity).

When developing an application that exploits sensor readings, it is not at all necessary to run down the street or jump into the water from a high cliff, since the emulator included in the Android SDK can pass any debug values ​​to the application (Fig. 2–3).


Looking for sensors

To find out what sensors are in the smartphone, you should use the method getSensorList object SensorManager:

List sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);

The resulting list will include all supported sensors: both hardware and virtual (Fig. 4). Moreover, some of them will have different independent implementations, differing in the amount of power consumed, latency, operating range and accuracy.

To get a list of all available sensors of a particular type, you must specify the corresponding constant. For example, code

List pressureList = sensorManager.getSensorList(Sensor.TYPE_PRESSURE);

will return all available barometric sensors. Moreover, hardware implementations will be at the beginning of the list, and virtual ones at the end (the rule is valid for all types of sensors).


To get the default sensor implementation (such sensors are well suited for standard tasks and balanced in terms of power consumption), the method is used getDefaultSensor:

Sensor defPressureSensor = sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);

If a hardware implementation exists for the given sensor type, it will be returned by default. When the desired option is not available, the virtual version comes into play, but if, alas, there is nothing suitable in the device, getDefaultSensor will return null .

How to personally choose the implementation of sensors according to the criteria is written in the sidebar, but we are smoothly moving on.

Taking readings

To receive events generated by the sensor, you must register an implementation of the interface SensorEventListener using the same SensorManager. It sounds complicated, but in practice it is implemented in one line:

Sensor defPressureSensor = sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE); sensorManager.registerListener(workingSensorEventListener, defPressureSensor, SensorManager.SENSOR_DELAY_NORMAL);

Here we register the barometer obtained earlier by default using the method registerListener, passing the sensor as the second parameter, and the data update rate as the third.

The SensorManager class defines four static constants that determine the refresh rate:

  • SensorManager.SENSOR_DELAY_FASTEST- maximum data update frequency;
  • SensorManager.SENSOR_DELAY_GAME- the frequency commonly used in games that support the gyroscope;
  • SensorManager.SENSOR_DELAY_NORMAL- default refresh rate;
  • SensorManager.SENSOR_DELAY_UI- frequency suitable for updating the user interface.

It must be said that when specifying the refresh rate, one should not expect that it will be strictly observed. As practice shows, data from the sensor can come both faster and slower.

The left unconsidered first parameter is an implementation of the interface SensorEventListener, where we finally get specific numbers:

Private final SensorEventListener workingSensorEventListener = new SensorEventListener() ( public void onAccuracyChanged(Sensor sensor, int accuracy) ( ) public void onSensorChanged(SensorEvent event) ( // Get atmospheric pressure in millibars double pressure = event.values; ) );

The method onSensorChanged passed object SensorEvent, describing all events associated with the sensor: event.sensor- link to the sensor, event.accuracy- sensor value accuracy (see below), event.timestamp- event occurrence time in nanoseconds and, most importantly, an array of values event.values. For a pressure sensor, only one element is transmitted, while, for example, for an accelerometer, three elements are provided for each of the axes at once. In the following sections, we will look at examples of working with various sensors.

Method onAccuracyChanged allows you to track changes in the accuracy of transmitted values, determined by one of the constants: SensorManager.SENSOR_STATUS_ACCURACY_LOW- low accuracy, SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM- average accuracy, calibration is possible, SensorManager.SENSOR_STATUS_ACCURACY_HIGH- high accuracy, SensorManager.SENSOR_STATUS_UNRELIABLE- the data is unreliable, calibration is required.

After it is no longer necessary to work with the sensor, you should cancel the registration:

SensorManager.unregisterListener(workingSensorEventListener);

Measure pressure and altitude

We have already written all the code for working with the pressure sensor in the previous section, having received the value of atmospheric pressure in millibars in the pressure variable.

Continued available to members only

Option 1. Join the "site" community to read all the materials on the site

Membership in the community during the specified period will give you access to ALL Hacker materials, increase your personal cumulative discount and allow you to accumulate a professional Xakep Score rating!

Gadgets are equipped with a variety of sensors that open up new features and make using phones easier and more comfortable.

We have already compiled the ones that smartphones are equipped with, but did not mention the Hall sensor. What it is, what it is for and how it works - all this can be found in this article.

Why do you need a Hall sensor?

This sensor is able to determine the position and is based on the Hall effect, which was discovered in 1878. The scientist-physicist managed to make a discovery by measuring the voltage of the current in the conductor, which was in a magnetic field.

Our gadgets use a simplified version of the Hall sensor. It is able to determine the presence of a magnetic field, but does not calculate the field strength along different axes. Along with it, smartphones often use a magnetic sensor, which is responsible for the operation of the compass.

Hall sensor in smartphones

The Hall sensor can be found mainly in flagship smartphones, for which special cases with a magnetic latch are available - these are often called smart cases or Smart Cases. The sensor is able to determine whether the cover of the case is closed or open, and in accordance with this, turn on / off the display of the device.

It should be noted that not all manufacturers indicate the presence of this sensor in the characteristics of the device. You can be sure of the presence of this sensor if Smart Case is available as an accessory for the gadget.

The Hall sensor helps navigation programs measure location faster. Previously, it was used in flip phones and helped to activate the screen when the gadget was opened, and turn it off when the device was closed.

Other application

Initially, Hall sensors were used on cars, where they were responsible for measuring the angle of the crankshaft position. The sensor determines the moment when a spark has formed in the car. True, this applies to old cars. Later, proximity switches and liquid level meters began to be equipped with a sensor. They were also used in magnetic code reading systems and even in rocket engines.

The accelerometer measures acceleration and allows the smartphone to determine the characteristics of movement and position in space. It is this sensor that works when the vertical orientation changes to horizontal when the device is rotated. He is also responsible for counting steps and measuring the speed of movement in all kinds of map applications. The accelerometer provides information about which way the smartphone is turned, which becomes an important function in various applications with .

This sensor itself consists of small sensors: microscopic crystalline structures, under the influence of acceleration forces, passing into a stressed state. The voltage is transmitted to the accelerometer, which interprets it into data on the speed and direction of movement.

Gyroscope

This sensor helps the accelerometer navigate in space. He, for example, allows you to do on a smartphone. In racing games, where the control is done by moving the device, just the gyroscope works. It is sensitive to rotation of the device relative to its axis.

Smartphones use microelectromechanical systems, and the first such devices that preserve the axis when turning appeared at the beginning of the 19th century.

Magnetometer

The last in the trio of sensors for orientation in space is a magnetometer. It measures magnetic fields and, accordingly, can determine where north is. The compass function in various map applications and some compass programs work using a magnetometer.

There are similar sensors in metal detectors, so you can find special applications that turn a smartphone into such a device.

The magnetometer works in tandem with the accelerometer and GPS for geolocation and navigation.

GPS

Where would we be without GPS (Global Positioning System) technology? The smartphone connects to several satellites and calculates its position based on the intersection angles. It happens that satellites are not available: for example, when there is a lot of cloudiness or indoors.

GPS does not use mobile network data, so geolocation also works outside the cellular coverage area: even if the map itself cannot be downloaded, the geolocation point will still be there.

At the same time, the GPS function consumes a lot of battery power, so it is better to turn it off when not needed.

Another method of geolocation, although not very accurate, is to determine the distance from cell towers. Your smartphone adds other information, such as mobile signal strength, to your GPS data to help you find your location.

Barometer

Many smartphones, including the iPhone, have this sensor that measures atmospheric pressure. It is needed to register changes in the weather and determine the height above sea level.

Proximity switch

This sensor is usually located near the speaker at the top of the smartphone and consists of an infrared diode and a light sensor. It uses a beam invisible to humans to determine if the device is near the ear. So the smartphone "understands" that during a phone call you need to turn off the display.

Light sensor

As you might guess from the name, this sensor measures the ambient light level, which allows you to automatically adjust the display brightness to a comfortable level.

Sensors with each new generation of smartphones are becoming more efficient, smaller and less energy-consuming. Therefore, you should not think that, for example, the GPS function in a device that is already several years old will work as well as in a new one. And even if the information about new smartphones does not indicate the characteristics of all these sensors, you can be sure that they are the ones that allow you to use many of the impressive features of modern gadgets.

If you remove all sensors from your smartphone, it will lose an impressive part of its functions and turn into a rather primitive device. Even actions familiar to users, such as changing the screen orientation when moving the gadget to a horizontal position and automatically turning off the display during a conversation, would not be performed without sensors.

In an effort to win competition in the market, manufacturers of modern mobile technology equip their devices with a huge number of sensors - because this increases functionality. In this article, we will talk about all known smartphone sensors, including those that are installed in the latest models.

Accelerometer– one of the main sensors of the smartphone; it is also called G-sensor. The function of the accelerometer is to measure the linear acceleration of the smartphone along 3 coordinate axes. Data about the movement of the device is accumulated and processed by a special controller - of course, this happens in a matter of fractions of a second. Places a tiny sensor approximately in the center of the smartphone body. Self-replacement of the accelerometer in the event of a breakdown is excluded - you have to go to the service.

Who should thank developers for accelerometers in smartphones? First of all, fans of racing simulators who are able to drive virtual cars by simply tilting the device left and right. It is the accelerometer that allows the gadget to change the screen orientation from portrait to landscape when the user flips the device.

The first accelerometer appeared on the phone Nokia 5500. This sensor caused a storm of enthusiasm among supporters of an active lifestyle, because it allowed the use of a pedometer.

The accelerometer has one significant drawback: it can only fix the position when acceleration- that is, when the gadget moves in space. The accelerometer is not able to determine the position of the apparatus lying on the table. The “partner” sensor called gyroscope. Such a sensor measures the rate of angular rotation and provides higher data accuracy than an accelerometer. A gyroscope that has gone through the calibration procedure will not have an error of more than 2 degrees.

The gyroscope is actively used in mobile games - in combination with the accelerometer. In addition, this sensor makes possible the optical stabilization of the camera, the creation of panoramic shots (the gyroscope determines how many degrees the smartphone has been turned), and gesture control.

The first smartphone with a gyroscope was iPhone 4. Now the gyroscope is far from exotic; they (as well as the accelerometer) are equipped with most modern devices.

Proximity and light sensors

The presence of a proximity sensor (Proximity Sensor) in a smartphone is an objective necessity. If there were no such sensor, the user would have to endure inconvenience every time they talk on the phone. It would be enough to easily touch the reset button with your cheek - and the conversation is terminated, you need to call the subscriber again. The function of the proximity sensor is obvious: it locks the screen of the gadget as soon as the user brings the device to the ear. This sensor allows the smartphone owner not only to communicate comfortably, but also save battery power.

The proximity sensor "hides" under the front glass of the mobile device. It consists of 2 elements: diode And detector. The diode sends out an infrared pulse (invisible to the human eye), and the detector tries to catch its reflection. If the detector succeeds, the screen "darkens". The sensor is able to register only 2 states: “ foreign object closer than 5 cm" And " foreign object further than 5 cm».

Samsung has achieved amazing results in experiments with the proximity sensor. Based on this sensor, the Korean manufacturer has created gesture sensor, thanks to which contactless control of the smartphone became possible. The first gesture sensor appeared on the Samsung Galaxy S3 - in 2012 it was a real breakthrough.

The Light Sensor is not in vain considered in tandem with the proximity sensor - as a rule, these two sensors are located in close proximity to each other. The light sensor is the "oldest" of all sensors that are used in mobile electronics. It is also the simplest - from a structural point of view, this sensor is a semiconductor that is sensitive to the photon flux. The function of the light sensor is not as responsible as that of the proximity sensor: Light Sensor only adjusts the brightness of the display in accordance with the surrounding conditions.

Some Samsung models (such as the Galaxy Note 3 and Galaxy S5) have RGB sensors. The RGB sensor is able not only to change the brightness of the display, but also to adjust the proportions of red, green, blue and white colors of the image on the screen.

The developers of the Samsung Galaxy Note 4 reached the point of absurdity: they taught the phablet sensor to measure illumination in the range invisible to humans - ultraviolet. Thanks to this curious innovation, the user can, for example, choose the optimal time for sunbathing.

Barometer and temperature sensor

A person with high sensitivity to sudden changes in atmospheric pressure simply needs to have a barometer application in their smartphone. On Google Play, for example, one of these programs is called “Barometer”.

The barometer sensor is able not only to warn the user about the approach of a cyclone - anticyclone; it's not even its main function. The sensor increases the efficiency and accuracy of the gadget's GPS navigator. GPS satellites show where in the world the place you are looking for is located - but not at what height. This shortcoming of their work is eliminated by the barometer. A pressure sensor can help you find, say, the office of a certain company in a multi-story business center building.

Temperature sensors, unlike barometers, are present in most smartphones - however, you cannot measure the temperature on the street with their help. This is about internal thermometers, whose task is to ensure that the gadget does not overheat. One smartphone can have a lot of these sensors: the first controls the graphics accelerator, the second controls the processor cores, and so on. If overheating occurs, the internal thermometer will automatically stop charging or reduce the output amperage.

External thermometers they are also found on gadgets, but they are still “a curiosity”. The first smartphone with a built-in thermometer was the Samsung Galaxy S4. The sensor turned out to be necessary to improve the work of the pre-installed S Health application.

Alas, external thermometers of mobile devices have a significant drawback - low accuracy. The data is distorted due to the heat emanating from the user's body and the insides of the machine itself. So far, the developers have not been able to solve this problem.

For the needs of the S Health application, another curious sensor was installed on the Samsung Galaxy S4 - hygrometer. This sensor measures the level of humidity, giving the user the ability to effectively control the indoor climate.

What sensors allow you to monitor your health?

A person who wants to lead a healthy lifestyle will not hurt to get a gadget that is equipped with the following sensors.

Pedometer (pedometer)

The function of the pedometer is to count the distance traveled by the user based on the number of steps taken. This function is also capable of performing the accelerometer, but the accuracy of its measurements leaves much to be desired. The pedometer as a separate sensor first appeared on the Nexus 5 smartphone.

Pulsometer (heart rate sensor)

The built-in heart rate monitor is one of the innovations of the Samsung Galaxy S5. Samsung developers felt that it was the heart rate sensor that the S Health program lacked in order for it to be considered a full-fledged personal trainer. Among users, the Samsung heart rate monitor has not yet become popular, because it is quite picky. To provide accurate data, the sensor needs close contact with a part of the user's body where blood vessels are shallow, such as the ball of a finger. Jogging while holding your finger on the sensor is a little pleasure.

Blood oxygenation sensor (SpO2 sensor)

This sensor determines the degree of oxygen saturation in the blood. It is present only on 2 Samsung smartphones (Galaxy Note 4 and Note Edge) and is “sharpened” for the S Health application. On devices, the SpO2 sensor is combined with a flash for the camera and a heart rate monitor. It is enough for the user to activate the corresponding application and put a finger on the flash for 30-40 seconds - after which he will see the measurement result as a percentage on the gadget screen.

Dosimeter

The Sharp Pantone 5 smartphone released in Japan is equipped with such a sensor. The function of the dosimeter is to measure radiation. For the Japanese, this function is important, because after the accident at the Fukushima nuclear power plant in 2011, they are forced to more closely monitor the radiation background. There are no smartphones with dosimeters on the European market.

Fingerprint and retinal scanners

Users who believe that the first fingerprint sensor appeared on the iPhone 5S are greatly mistaken. Phones capable of scanning fingerprints have been produced before. Back in 2004, a "clamshell" Pantech GI 100 was sold, equipped with similar technology. 7 years later, Motorola introduced the Atrix 4g model with a fingerprint sensor. In both cases, users reacted to the technology rather cool.

When, in 2013, Apple built a fingerprint scanner into the iPhone 5S Home button, the Apple company was applauded by experts and ordinary consumers alike. Apple was more fortunate with the era: in the "zero" the issue of the security of cashless payments was not so acute.

The fingerprint scanner relieves the user of the need to use digital passwords to protect data stored on the gadget. Passwords are easy to crack; it is much more difficult to deceive the fingerprint sensor (although it is also possible).

Now it has become fashionable to install fingerprint scanners in smartphones. This technology is used not only by long-term market leaders - Samsung, Apple, HTC - but also by promising Chinese manufacturers like Xiaomi and Meizu.

The retinal scanner provides even more security than the fingerprint sensor - in fact, this is the next level of biometric security. Supporters of the technology argue that getting a fingerprint is a doable task (after all, a person leaves them everywhere). There is no way to get a copy of the retina.

Image: iphonefirmware.com

The idea of ​​equipping a smartphone with a retinal scanner is also not new. Back in 2015, Asian manufacturers (Vivo, Fujitsu) experimented with this sensor, in 2016 the trend was supported by a little-known company from China Homtom. However, this technology became discussed only after Samsung turned to it - Galaxy Note 7 installed iris scanner.

The sensor in Note is different from those found in smartphones from Chinese companies. Samsung's idea can be called revolutionary because the Note 7 has a camera that is responsible just for eye scan. The “Chinese” read information from the retina with a selfie camera.

The method used by gadgets from China is ineffective. The fact is that the eye must be scanned with an infrared (IR) beam, but on the front cameras, the IR spectrum, as a rule, is filtered - because it spoils selfies. It turns out that Samsung is so far the only smartphone manufacturer that does not force users to make a choice between high-quality "selfies" and the security of personal data.

Conclusion

Every modern smartphone is equipped with at least 5 sensors. In flagship models, the number of sensors reaches the "damn dozen", and manufacturers are not going to stop there at all. IBM experts predict that as early as 2017 gadgets will have a sense of smell, thanks to which they will be able to warn the user, for example, of a high concentration of fumes and the presence of an influenza virus in the air. We are looking forward to innovations - after all, the continuation should be?

Few people know that smartphones are equipped with numerous sensors, including proximity and temperature light sensors, a barometer, an accelerometer, a gyroscope, and others. They are designed to make the device easier to use.

In this article, we will talk about the Hall sensor (magnetic sensor). About 140 years ago, the American scientist Edwin Hall discovered a phenomenon that was later called the Hall effect. It is still actively used in modern technology.

Purpose of the magnetic sensor

The Hall sensor in the smartphone is designed to detect a magnetic field, which will determine the position of the device itself relative to the cardinal points. Thus, by downloading the Compass application from the Google Play Android store, your smartphone can perform the function of a compass.

The first step in the introduction of this technology was the use of this sensor in cars. Using it, the angle of the camshaft and crankshaft was measured, as well as the moment of spark formation. Later, the Hall effect began to be applied to other technologies, including mobile devices.

The digital compass in phones is used by navigation programs to correct the motion vector and determine the exact coordinates of the phone. Previously, such a magnetometer was built only in flagship phones, but now it is ubiquitous. The functions of such a sensor are very extensive. Let's consider them in more detail.

Functions of the magnetometer

In flip phones, it was used to activate the backlight when the device was opened. Another purpose of the sensor is to synchronize the operation of the smartphone with a case with a magnetic clasp.

If the magnet located on the cover is located at some distance from the device, then the sensor reacts as follows: it stops recognizing it, giving a command to turn on the screen.

When you close the case while the clasp is close, the phone's display will automatically go to sleep. If there is a “window” in the case, then the open space in which the various widgets are located can continue to be active. Thus, when the cover is closed, only the visible part is broadcast on the splash screen, when opened, the entire screen becomes active.

Also, the sensor allows contactless control of a number of functions that are available in the smartphone. The magnet on the case does not in any way negatively affect either the sensor itself or the phone components.

How to activate the sensor?

Now the magnetometer is in many mobile devices, but basically its functions are not fully used due to a number of reasons. For financial reasons - in budget models, as well as in connection with design features (minimum case thickness) and the desire to reduce battery consumption.

The sensor in the vast majority of cases performs two functions: interaction with accessories and a digital compass. It does not need to be turned on and configured, as the sensor starts automatically.

There are two ways to determine the presence of a sensor in the phone: by looking at the technical characteristics of the smartphone or by testing the device using the Compass application, which should start functioning when the Internet is turned off. There is also a second way: attach a magnet to the display. If the screen goes blank, the phone has a built-in magnetometer.