Reading Absolute Rotation with the MLX90316

Reference schematic from the MLX90316 project, credited to Martin Nawrath / KHM.

The MLX90316 project explores magnetic absolute-angle measurement. Its Arduino sketch uses a small software-driven serial interface and a periodic timer to read the sensor, with a circuit drawing, library source and datasheet included for reference.

How the project works

A Metro timer requests a reading every five milliseconds. The MLX90316 library handles the serial transaction and checks the returned status bits before scaling valid angle data.

The library calculates raw angle × 3600 / 16384, so a successful result represents tenths of a degree. For example, 900 corresponds to 90.0 degrees. The main sketch prints only nonnegative results, silently omitting the library’s negative error codes.

Hardware and configuration

ItemIn the supplied code
Chip selectD5
ClockD3
Bidirectional data pinD4
Serial monitor115200 baud

Working with the supplied code

Use the supplied schematic and the exact sensor variant’s documentation to check the wiring and serial-output configuration. The library changes the data pin between input and output during transfers, so this is not simply a standard hardware-SPI pin mapping.

Start by watching the raw returned value while slowly rotating the magnet. During setup, expose the negative return codes too: the library distinguishes invalid data and magnetic-field strength errors. A five-millisecond polling interval is a software setting, not a measurement of achieved angle accuracy or update performance.

Source code and project files

Browse this project on GitHub. The project folder includes the sensor library, Arduino test example and Processing visualization. Keep the visualization’s data folder beside its sketch so the bundled font can be found.

Download the used libraries (ZIP, 14.7 MB). This collection preserves the archived library versions; Wi-Fi settings and API credentials use placeholders for you to configure locally.

The sketch and MLX90316 interface credit Martin Nawrath / Academy of Media Arts Cologne. The sensor datasheet is by Melexis.

These notes describe the archived source and project media. The sketches have not been rebuilt or tested on hardware for this article.

Scroll to Top