Rotary Position Sensor MLX90316



The MLX90316BDG is a rotary position sensor which measures the direction of a magnetc field with an SPI interface. It is a substitution for potentiometers or shaft encoders. The resolution ia about 1/10 of a degree with an update rate of 2 ms. A little magnet placed on a shaft or a joint where the sensor is placed next to it is the typical configuration. To obtain the best accuracy the rotation axis of the magnet should be placed over the centre of the chip. The MLX90316 libray helps to read the chip data.






/* MLX90316 Rotary Position Sensor
 * KHM 2010 /  Martin Nawrath
 * Kunsthochschule fuer Medien Koeln
 * Academy of Media Arts Cologne
#include "Metro.h"     //Include Metro library
#include "MLX90316.h"  // Include MLX90316 library

int pinSS = 5;
int pinSCK = 3;
int pinMOSI = 4;
int ii;
Metro mlxMetro = Metro(5);
MLX90316 mlx_1  = MLX90316();
void setup(){
  mlx_1.attach(pinSS,pinSCK, pinMOSI );
  Serial.println(" MLX90316 Rotary Position Sensor");

void loop() {
  if (mlxMetro.check() == 1) {
    ii = mlx_1.readAngle();


Get the MLX90316 library and sample code



Martin Nawrath / KHM 2010