3D Motion Cube
A Three.js cube mirrors your board's orientation in real time — tilt or rotate the Arduino and the cube follows.
The sketch streams both onboard motion sensors at about 25 Hz: each notification carries 24 bytes — the accelerometer (x, y, z in g) and the gyroscope (x, y, z in deg/s) as six float32 values.
Neither sensor alone can track orientation well. The gyroscope measures rotation speed precisely but integrating it accumulates drift; the accelerometer knows which way gravity points but is noisy and confused by any shake. The browser fuses both with a complementary filter: it integrates the gyro every sample and gently nudges the estimate toward the gravity direction, getting the best of each sensor.
The fused roll/pitch/yaw is applied to a Three.js cube rendered with WebGL, smoothed a little each frame so the motion looks fluid. Yaw (spinning flat on the table) has no gravity reference, so it slowly drifts — that is a physics limitation, not a bug; use "Reset orientation" to re-zero the cube.
Goals
- Stream fused accel + gyro samples over BLE
- Understand complementary-filter orientation in the browser
- Drive a Three.js cube that mirrors the physical board
Materials
- Arduino Nano 33 BLE Sense (onboard LSM9DS1)
- USB cable
- Arduino IDE with ArduinoBLE and Arduino_LSM9DS1