Reads MPU6050 gyro, accelerometer and temperature via I2C, initializes and returns data on-demand to EZ-Script variables using ControlCommand RunOnce
How to add the MPU6050 Accelerometer Gyro Temperature robot skill
- Load the most recent release of ARC (Get ARC).
- Press the Project tab from the top menu bar in ARC.
- Press Add Robot Skill from the button ribbon bar in ARC.
- Choose the I2C category tab.
- Press the MPU6050 Accelerometer Gyro Temperature icon to add the robot skill to your project.
Don't have a robot yet?
Follow the Getting Started Guide to build a robot and use the MPU6050 Accelerometer Gyro Temperature robot skill.
How to use the MPU6050 Accelerometer Gyro Temperature robot skill
- Accelerometer (detects movement/tilt by measuring acceleration)
- Gyroscope (detects rotation rate)
- Temperature sensor (reports the chip’s temperature)
Before You Start (Beginner Checklist)
-
Hardware connected: Plug the MPU6050 EZ-Bit into the EZ-B’s I2C port.
Important: I2C devices require the correct wiring. If the sensor is not connected properly (or not connected at all), the EZ-B v4 can lock up when a read is attempted.
- Add the skill to your ARC project: Add the MPU6050 control/skill to the ARC workspace.
- Have a way to run a script: Add an EZ-Script control where you will place the example code below.
Key Concept: INIT First, Then Read On Demand
This skill does not continuously read the sensor automatically. You must:
- Run
Initonce to initialize the MPU6050. - Run
RunOnceeach time you want fresh sensor values.
Init, the MPU6050 will not return data.
If you call RunOnce repeatedly, the variables will be updated each time.
Where the Sensor Data Goes (EZ-Script Variables)
Each time you read the MPU6050, this skill updates a set of EZ-Script Variables. The exact variable names can vary by version/configuration, so the easiest way to see them is:
- Click the Config button on the MPU6050 control.
- Look for the list of variables that the skill updates.
- Use the Variable Watcher to watch those values change live.
Example: Read the MPU6050 Every 100ms (10 Times/Second)
The script below initializes the sensor once, then loops forever. Every loop it:
- Requests a new reading from the MPU6050 using
RunOnce - Waits
100milliseconds - Repeats
ControlCommand("MPU6050", Init)
:loop
ControlCommand("MPU6050", RunOnce)
Sleep(100)
Goto(loop)
Sleep(250)).
If you want faster updates, decrease it (example: Sleep(50)). Very fast loops can overwhelm your project if you don’t need them.
Troubleshooting
- EZ-B v4 locks up when running the script: This usually means the MPU6050 is not connected correctly, not powered, or not on I2C. Disconnect power, check the I2C connection, then try again.
-
Variables are not changing: Make sure you ran
Initfirst, and that the loop is callingRunOnce. Also confirm you’re watching the correct variables in the Variable Watcher. - Data looks “noisy” or jumpy: That is common with IMU sensors. Consider averaging values in your script or reading at a steadier rate.
Example Project (Video Mention)
A working example is shown in the video using the JD project with the MPU sensor. You can find it in the EZ-Cloud as: JD With MPU6050 Accelerometer.
How It Works (Learn More)
Want to understand IMU sensors (accelerometer + gyro) in more detail? This is an excellent beginner-friendly article: https://www.starlino.com/imu_guide.html

@Jeremie, thanks for the reply here is a picture of the setup. The ezb4 is being power with 8.4 volts the MPU6050 is being powered by the 3.3V from the i2c port on the ezb4 the wire is about 17inchs long. The SDA and SCL pins have 330 resistors connected to the Vcc pin.
The sda pins on the ezb4 and the MPU connected together and the same goes for the scl pins.
Is there anything else I can provide for you.
In the skill it shows the temp but as soon as I click the int button in the skill it normally makes the red LED light up and stays on and the ezb4 disconnects from the network.
Thanks for the photos! 2 things:
Your wires may be too long I would look at shortening those.
It looks like you used 470ohm resistors in parallel with the onboard pull-ups, I would recommend going lower (220 ohms).
It looks like we have very similar boards. Here's my setup (works solidly):
8 inch cable:
220 ohm Pull-up resistors soldered in place of the original (2.2Kohm resistors) I believe:
Yeah, I also powered it from the EZ-B 3.3V.
I just use the example code from above for testing:
@Jeremie, I installed the 220 ohm resistors and it is working great now thanks for your help!
DJ, Is there anyway I can get the source for this skill I would like to see if I can enhance it for my project. by making a new version that is more feature rich. Please let me know if this is something we can do.
Sure, here you go: MPU6050 Src.zip
This is not a plugin robot skill, which means it's part of ARC native. For you to make it a plugin, the code can be copied into the plugin template. You have to change the namespace.
Follow this tutorial to create a robot skill: https://synthiam.com/Support/Create-Robot-Skill/Overview
DJ, Thanks but it looks like I am not going to be able to do this because my Windows 11 is on an Arm64 and you can only install Visual Studio 2022 Community for ARM64. Based on what is posted there are issues with 2022 Community version. But thank you for providing the source code.
Yeah Microsoft has a pretty big bug that they refuse to fix about that.
DJ, I am trying to understand which MPU6050 class you guys are using and what type of values that class is sending back so if you can provide any information on that class it would be a big help. I just need to understand what type of pre processing the class is doing to the values.
The following code is from the MPU6050.cs file in the source you sent me. Just as an FYI this skill is not returning the correct temp value. I get a value of like 217c in the skill.