An MPU6050 accelerometer simulator you tip by hand
Mokxi is a free online accelerometer simulator that runs in your browser, with nothing to install and no account needed. An Arduino Uno reads an MPU-6050 over I2C with nothing but the Wire library and prints its raw acceleration, temperature and rotation twice a second. Tip the board on the canvas and gravity moves from one axis to the next.
- 455parts on the bench
- 43boards running now
- 1.00xreal time, on every board
What you can do here
In the circuit above, or in the editor it opens.
- Read the MPU-6050’s raw registers with Wire
- Tip the board in pitch and roll and watch X, Y and Z share gravity
- Turn the readings into an angle, as the tilt meter project does
- Watch the gyroscope move only while the board is moving
- Try an ADXL345 or an analog ADXL335 instead
- Build a balancing robot on the same sensor
What the running circuit shows
An accelerometer at rest measures gravity.
The MPU-6050 wakes up asleep, so the sketch first writes 0 to its power register, 0x6B. After that, fourteen bytes starting at register 0x3B hold three accelerations, the temperature and three rotation rates, each a 16-bit number sent high byte first. On the default ±2 g range, 1 g is 16384 counts.
In the engine the board starts flat and the serial monitor reads AcX = 0, AcY = 0 and AcZ = 16384: all of gravity on Z. Tip it 30 degrees in pitch and X takes half of it, AcX = -8192, while Z falls to 14189, which is 16384 times the cosine of 30 degrees. Roll it 90 degrees as well and Z drops to 0 while Y takes the 14189. The temperature reads 25.0 °C, the part’s setting.
How the sensor is modeled
The register map, the ranges and the sleep bit.
The MPU-6050 part answers at I2C address 0x68, or 0x69 with AD0 pulled high, powers up asleep, and returns its readings from the registers the datasheet names, scaled by the range a sketch picks for the accelerometer and the gyroscope. WHO_AM_I reads 0x68 whichever address it is on, as on the real chip. The gyroscope reads how fast the board is being turned, so it sits at 0 at rest and moves only while you drag.
What it leaves out: a real MPU-6050 has offsets and noise to calibrate away, which is half the work of a real project, and here a flat board reads exactly 0 on X and Y. There is no yaw to drag on a flat canvas, so the Z gyro always reads 0, and there is no magnetometer on this chip to find north.
Questions
Is it free?
Yes. The circuit on this page, every part in it and the editor it opens in are on the free plan, with no card.
Do I need an account?
No. The circuit runs the moment the page does, and the editor opens without one. A free account is only for saving a project to the cloud and sharing it by link.
How do I get an angle from an MPU6050?
At rest, the angle is the arctangent of two acceleration axes: pitch from X against Z. Tipped 30 degrees, X reads -8192 and Z 14189, and the arctangent of 8192 over 14189 is 30 degrees. The tilt meter project works it out on the Uno.
Does it need an MPU6050 library?
Not this sketch: it uses only Wire, so every register it reads is in view, and the same sketch runs on a real Uno with a GY-521 board.
Which accelerometers can I simulate?
The MPU-6050 on its GY-521 board, the ADXL345 on I2C and the analog ADXL335, among the sensors in the parts bin.
More simulators
Each one opens on a circuit that is already running.
Tip a sensor
Open the circuit, tip the board and press Run. Nothing to install, and no account needed.