5.2. Motion and Position#
Motion and position sensors tell your microcontroller how something is moving or where it is located.
5.2.1. Accelerometers and Gryoscopes#
An accelerometer measures proper acceleration, which is the acceleration of the object relative to an observer who is in free fall. If someone magically free falls into the Earth next to you then you would appear to be moving upwards to them. Therefore your acceleration direction would be outwards from the Earth’s surface.
Modern accelerometers use tiny mechanical structures called Micro-electromechanical systems (MEMS) that shift slightly when a sensor is moved or tilted. The structures will shift in the direction of the proper acceleration. This shift is turned into an electrical signal.
Accelerometers measure:
fixed acceleration due to gravity
local movements of a device in x, y, z axes.
A gyroscope measures angular velocity, which is how fast something is turning. Just like accelerometers, modern gryoscopes use MEMS technology but to detect the Coriolis effect.
Gyroscopes measure:
angular rate in degrees per second
For reliable local orientation sensing, both accelerometers and gyroscopes are required. To understand this, consider that an accelerometer’s data does tell us the angle of a device relative to gravity, it can also include dynamic accelerations from translations (movement), bumps and vibrations. On the other hand, a gyroscope only provides angular rate, which we can convert to an orientation by integration. However the gyroscope is provided without reference to a fixed orientation. Therefore by fusing both accelerometer and gyroscope data we can accurately estimate orientation of a device.
Examples use cases:
Phone screen auto-rotation.
Measuring vibrations or impacts.
Detecting if a device has tipped over.
5.2.2. Magnetometer#
A magnetometer detects magnetic fields and is used as a digital compass. Typically these devices rely on either MEMS or the Hall effect, which is when a voltage is created due to the interaction of a electrical current and magnetic fields.
Magnetometers are capable of measuring the current magnetic field in three axes, which can be converted to a heading relative to Earth’s magnetic north.
Magnetometers are used to augment accelerometer and gyroscope data to know which way a device is orientated on the Earth’s surface.
Attention
Magnetometers can be disturbed by nearby metal or electrical noise. They usually require frequent calibration due to local variations in magnetic conditions.
5.2.3. Optical Encoders#
An optical encoder measures rotation of a wheel or shaft. A slotted disk spins between a light source and sensor. Each slot lets light through, creating an electrical pulse.
These encoders can measure:
incremental position or speed
absolute position
Optical encoders are commonly used to measure speed on machinery, distance that a vehicle has moved or for precise control of motors.
5.2.4. Magnetic Encoders and Distance Sensors#
Magnetic encoders used to measure rotational position and speed in mechatronic systems. They work by detecting the orientation of a magnetic field produced by a permanent magnet fixed to a rotating shaft. As the shaft turns, the encoder’s sensing element outputs electrical signals corresponding to angular displacement. This data can be processed to provide precise shaft angle, direction of rotation, and velocity.
In addition to encoders, Hall effect distance sensors extend the same principle to measure distance or proximity. Instead of tracking angular rotation, these sensors detect changes in the magnetic field strength as a magnetic target moves closer or farther from the sensor.
Because magnetic encoders and distance sensors are contactless they are robust against dust, grease, and vibration. For this reason they are often favored over optical encoders in harsh industrial environments.