added code for magnetometer