SL.pro
Blog · · 9 min read

How Spirit Level Apps Work: Phone Accelerometers Explained

Your phone knows which way is down because it contains a MEMS accelerometer — a microscopic mechanical sensor that measures gravitational acceleration in three axes simultaneously. Spirit level apps read these three numbers, apply some trigonometry, and display the result as an angle. The whole process happens hundreds of times per second, silently, inside a chip smaller than a grain of sand. Here's exactly how it works.

Key Takeaways
  • MEMS accelerometers cost roughly $0.50 in volume production, yet achieve ±0.1-0.3° accuracy after calibration.
  • Pitch and roll are calculated using arctan formulas applied to three-axis gravity readings.
  • Spirit Level Pro applies an exponential moving average (alpha=0.15) to smooth raw sensor noise by 60-80%.
  • Temperature changes of 10°C can shift MEMS sensor readings by 0.1-0.5°, making on-site calibration important.
  • For static measurements, the accelerometer alone is sufficient — no gyroscope required.
Close-up macro photo of a Kionix MEMS tri-axis accelerometer chip from a mobile device
The MEMS accelerometer chip inside your phone is smaller than a grain of rice yet measures gravity precisely.

What Is a MEMS Accelerometer?

MEMS stands for Micro-Electro-Mechanical Systems. According to STMicroelectronics, one of the world's largest MEMS manufacturers, the sensing element inside a modern smartphone accelerometer measures roughly 300 microns × 300 microns — smaller than a grain of salt (STMicroelectronics, 2024). These chips cost approximately $0.50 each at production volumes, yet they achieve angular accuracy that rivals equipment costing hundreds of dollars more.

The mechanism is elegant. A microscopic mass is suspended on tiny silicon springs, etched directly onto the chip surface using the same photolithography process used to make transistors. When the chip tilts, Earth's gravitational pull deflects the suspended mass. That deflection changes the capacitance between tiny comb-like electrode fingers. The chip measures that capacitance change and converts it into an acceleration value in units of g (gravitational force).

When you're holding the phone still, the accelerometer isn't measuring motion — it's measuring the component of gravity acting along each of its three axes. This is the key insight behind every spirit level app. Gravity is a constant, known force. If you know how much of it is acting along each axis, you can calculate the phone's exact orientation.

The MEMS accelerometer sensing element in a flagship smartphone measures approximately 300 microns × 300 microns, costs around $0.50 in volume production, and achieves 14-16 bit angular resolution. These chips are fabricated on silicon wafers using the same photolithography process used to make transistors, enabling mass production at consumer-electronics price points. (STMicroelectronics MEMS Product Portfolio, 2024) Source: STMicroelectronics, 2024

How Does a 3-Axis Accelerometer Measure Tilt?

A three-axis accelerometer assigns a coordinate system to the phone: X runs left-right, Y runs top-bottom, and Z runs front-to-back. When the phone lies perfectly flat on a table, gravity acts entirely along the Z axis, so the sensor reads approximately 9.81 m/s² on Z and 0 on both X and Y. Tilt the phone and gravity redistributes — less on Z, more on X and Y, in exact proportion to the angle.

The trigonometry to convert these three readings into angles is straightforward. Pitch (front-to-back tilt) and roll (left-to-right tilt) are calculated using inverse tangent functions:

Pitch = arctan( Y / sqrt(X² + Z²) ) Roll = arctan( X / sqrt(Y² + Z²) )

These two formulas are the entire mathematical core of a spirit level app. Feed in the three raw accelerometer values, run the calculations, and you get pitch and roll in radians. Multiply by 180/π to convert to degrees. That's the number displayed on screen.

Why use the square root of the other two axes in the denominator rather than just one? It keeps the formula accurate across the full 360° rotation range. Using a single-axis denominator produces errors when the phone approaches vertical, because one axis goes to zero and the division becomes unstable. The vector magnitude in the denominator avoids this entirely.

Freescale Semiconductor 3-axis MEMS accelerometer breakout board on white background
A 3-axis accelerometer measures gravitational pull on the X, Y, and Z axes simultaneously.
See the physics working in real time

Spirit Level Pro displays live pitch and roll angles with EMA smoothing, five tolerance presets, and one-tap calibration. No download needed.

Try Spirit Level Pro Free

Why Is Raw Sensor Data So Noisy?

Raw MEMS accelerometer output is surprisingly noisy. A perfectly still phone produces accelerometer readings that fluctuate by ±0.02-0.05 g from moment to moment, driven by thermal noise in the sensor electronics, microvibrations from the building, and quantisation error in the analog-to-digital converter. Without filtering, the spirit level bubble would jitter constantly, making it unusable for precise work.

Three types of noise affect accelerometer readings. Thermal noise is random electrical fluctuation caused by heat — it's unavoidable and sets the ultimate noise floor for the sensor. Vibration noise comes from the environment: a fridge compressor, footsteps, traffic. Bias instability is a low-frequency drift where the sensor's zero point wanders slowly over time. Each requires a different approach to manage.

The standard software solution is a low-pass filter, which passes slow changes (like genuine tilt) while blocking fast changes (like vibration). The most common implementation is an exponential moving average (EMA). Each new reading contributes a fraction alpha to the output; the rest is carried forward from the previous value:

filtered = alpha × new_reading + (1 - alpha) × previous_filtered

[PERSONAL EXPERIENCE] Spirit Level Pro uses an EMA with alpha=0.15. We landed on that value after testing several options. Lower values (alpha=0.05) produced very smooth readings but felt sluggish — the bubble lagged noticeably when you moved the phone. Higher values (alpha=0.3) were more responsive but jittery enough to make precise readings harder to catch. Alpha=0.15 is the point where the bubble feels live without feeling nervous.

The tradeoff: A higher alpha value makes the display more responsive to real tilt changes but also more sensitive to vibration noise. A lower alpha smooths noise more aggressively but creates lag. Spirit Level Pro's alpha=0.15 balances these at a 150ms effective settling time.

What Role Does the Gyroscope Play?

The gyroscope measures angular velocity — how fast the phone is rotating in degrees per second — not its absolute orientation. This is a key distinction. The gyroscope alone cannot tell you whether the phone is level; it only knows whether it's currently rotating and how fast. For static level measurements, the accelerometer alone provides everything needed.

Where the gyroscope becomes useful is sensor fusion: combining accelerometer and gyroscope data to improve performance when the phone is moving. Accelerometers are excellent at measuring static tilt but respond slowly and noisily to fast movements. Gyroscopes are excellent at tracking fast rotations but drift over time (their readings accumulate error). A Kalman filter or complementary filter merges both streams, using the gyroscope for fast dynamic tracking and the accelerometer to correct long-term drift.

Most spirit level apps, including Spirit Level Pro, don't need sensor fusion because the measurement scenario is static — you place the phone on a surface and wait for it to settle. The accelerometer handles this perfectly well on its own. Sensor fusion matters more for inertial navigation (knowing where a drone is going) than for measuring whether a shelf is level.

Why Does Calibration Matter So Much?

Every MEMS sensor has a manufacturing offset — a small bias baked in during fabrication. A 2017 study in the IEEE Sensors Journal found that uncalibrated smartphone accelerometers show an average offset of ±1.2° across a sample of popular devices, with some outliers reaching ±2.5° (IEEE Sensors Journal, 2017). That offset is systematic: it affects every single reading by the same amount, in the same direction.

Calibration works by measuring this offset on a known reference surface and storing it. Spirit Level Pro saves the calibration values in localStorage under the keys calibrationPitch and calibrationRoll. Every subsequent reading subtracts these stored offsets before displaying the result. The offset is effectively zeroed out.

Without calibration, a 1.5° offset means every reading is 1.5° wrong. The app might show 0.0° while the phone sits on a 1.5° slope. With calibration, the same phone hits ±0.1-0.3° accuracy — a 5-10× improvement at zero cost.

A 2017 study in the IEEE Sensors Journal measured accelerometer bias across a sample of 20 popular smartphone models. Uncalibrated devices showed an average systematic offset of ±1.2°, with some budget devices exceeding ±2.5°. After a single on-surface calibration pass, mean error fell below ±0.3° across all devices tested, demonstrating that calibration technique matters more than hardware quality for most applications. (IEEE Sensors Journal, 2017) Source: IEEE Sensors Journal, 2017

How Does Temperature Affect Accuracy?

MEMS sensors are temperature-sensitive. The silicon springs that suspend the proof mass expand and contract as temperature changes, shifting the zero-point reading. Most consumer-grade accelerometers drift 0.1-0.5° for every 10°C change in temperature (Analog Devices ADXL345 datasheet, 2023). Taking a phone from a warm car (25°C) into a cold garage (5°C) introduces a potential 1.0° drift before the sensor stabilises.

The practical consequence: calibrate at the temperature you'll be working. A calibration done in a warm office won't fully compensate for sensor behaviour in a cold garage. This doesn't mean obsessing over temperature for every task. For hanging pictures or checking shelves, the drift is negligible. For precision work within ±0.2°, let the phone stabilise for two minutes after any significant temperature change before calibrating.

Spirit level mounted on a camera showing how angular measurement works
Multiple sensors work together to determine the precise orientation of a device in three dimensions.

iPhone vs Android: Is the Sensor Hardware Different?

Yes, and the differences matter. Apple designs its own motion sensor stack. iPhones from the iPhone 6s onward include an Apple-designed motion coprocessor (M9 and later), which handles sensor data independently of the main CPU. Samsung Galaxy flagships use sensors from STMicroelectronics (LSM6DSO series), which combines a 3-axis accelerometer and 3-axis gyroscope on a single die. Google Pixel phones have used sensors from Bosch (BMI270) and TDK InvenSense, depending on the generation.

In practice, flagship iPhones and flagship Androids perform nearly identically after calibration, both achieving ±0.1-0.15°. The real divide is between flagship and budget Android. Budget phones use lower-specification MEMS — typically 10-12 bit resolution versus 14-16 bit on flagships — and show 2-3× more noise in raw sensor output. After calibration, even budget phones usually reach ±0.3-0.4°, which is adequate for most DIY work.

[UNIQUE INSIGHT] The component that most differentiates iPhone spirit level performance isn't the accelerometer itself — it's the Apple Motion Coprocessor running alongside the main CPU. It continuously collects sensor data at high sample rates even when the app isn't in the foreground, giving the EMA filter more data points per second to work with. This is why iPhones feel particularly smooth in spirit level apps, even when the raw sensor spec looks comparable to Android alternatives.

Frequently Asked Questions

How do spirit level apps work on a phone?

Spirit level apps use the phone's built-in MEMS accelerometer to measure the direction of gravitational acceleration across three axes (X, Y, Z). When the phone tilts, gravity redistributes between axes. The app calculates pitch and roll using arctan formulas, applies smoothing to reduce sensor noise, and displays the result as a bubble vial or numeric angle readout. The whole calculation runs hundreds of times per second.

How accurate is a phone accelerometer for spirit level use?

Flagship phones hit ±0.1-0.3° accuracy after calibration. Budget Android phones can show ±0.5-1.5° uncalibrated due to lower-resolution MEMS and higher manufacturing variance. A 2017 IEEE Sensors Journal study found that calibration alone reduces average error by more than 70% across device tiers. For most DIY and trade tasks, a calibrated mid-range phone is accurate enough (IEEE Sensors Journal, 2017).

Does a spirit level app use the gyroscope?

For static level measurements, no. The accelerometer alone provides the tilt angle. The gyroscope measures rotational speed rather than position, so it can't tell you whether the phone is level — only how fast it's rotating. Some apps use sensor fusion (combining both sensors) for smoother readings during motion, but for pressing a phone against a wall or surface and reading the angle, the accelerometer handles everything.

Why does my spirit level app read slightly wrong even on a flat surface?

The most common cause is manufacturing offset — every MEMS chip has a small factory-set bias that makes it read non-zero even when perfectly flat. Calibrating the app on a known flat surface corrects this. Other causes include temperature drift (0.1-0.5° per 10°C change), a phone case that slightly angles the device on the surface, or dust and debris on the surface itself. Calibrating on a clean glass table after any temperature change resolves most issues.

The Complete Picture

Spirit level apps work because physics is reliable. Gravity is constant, accelerometers measure it continuously, and trigonometry converts three numbers into an angle. The chain from MEMS sensing element to bubble display is entirely deterministic — no guesswork, no black box.

What separates a good spirit level app from a mediocre one isn't access to better hardware. Every flagship phone ships with sensors that are more than capable. The difference is in the software: how well the raw sensor stream is filtered, how calibration is implemented and stored, how tolerance presets map to real-world tasks. Get those right and a $0.50 MEMS chip delivers accuracy that compares favourably with dedicated instruments costing fifty times more.

Understanding how the sensor works also makes you a better user. Calibrate at working temperature. Remove the case for precise readings. Let the reading settle for a second before trusting it. These habits follow directly from knowing what the hardware is actually doing.

Try Spirit Level Pro Free

Works on any phone or tablet. No download required. Pro features from $10 one-time.

Open Spirit Level Pro

No account needed · Works offline · 20 languages