Main Content

Controlling Objects in Unity with a 9 DoF Sensor and Arduino

Unity is one of the most widely used game engines for developing video games. In this guide, you’ll learn how to integrate your Arduino based hardware projects with your Unity projects to create interactive experiences.

Data from a 9 DoF sensor is sent over a serial connection from the board to a C# script in Unity. The C# script is set up to affect Unity objects with the incoming data.

Calibrating Your 9 DoF Sensor
The Adafruit LSM6DS3TR-C + LIS3MDL board has an accelerometer, gyroscope and magnetometer onboard, making it a 9 Degrees of Freedom (DoF) sensor. You can calibrate the various sensors for the most accurate movement measurements possible using the How to Fuse Motion Sensor Data into AHRS Orientation Learn Guide.

By following that guide, your chosen Arduino board stores the calibration in non-volatile memory so that it can be accessed going forward. Unity expects Quaternion values for rotation, so that calibration method is the most useful.

There is Arduino code included for using the LSM6DS3TR-C + LIS3MDL sensor without calibration. It takes the accelerometer readings and uses the Arduino map_range() function to map the values between -180 and 180 for Euler readings. It won’t be as accurate as a fully calibrated sensor, but it will demonstrate how to input data into Unity.”

Link to article