Build an Electronic Level with MPU-6050 and Arduino
Today we will be working with the MPU-6050 IMU, and we will use it to build an electronic level with an Arduino.
Article with libraries and code - https://dbot.ws/mpu6050
Today we will be working with the MPU-6050, a low-cost Inertial Measurement Unit, or IMU. This device has a lot of different applications in many fields including robotics, gaming, quadcopters, and IoT devices.
The MPU-6050 has an internal gyroscope and accelerometer. It's an inexpensive device, available in several packages and modules. The module I am using is very common and has a built-0in voltage regulator so it can work with 5-volt logic.
We will start by looking at the MPU-6050 internals, as well as at the pinout of the module I am using.
Next, we will load a couple of libraries into our Arduino IDE and ruins some sample code to display Pitch, Yaw, and Roll.
After that, we will build a small project, an electronic level. Our level will display on an LCD and will also use 5 LEDs to give a good visual indication of how level the surface is.
Here are the contents for today's video:
00:00 - Introduction
02:53 - MPU-6050 Intro
11:20 - MPU-6050 Arduino Experiments
20:29 - Electronic Level
You can get the sketch and the two libraries used in the experiments on the DroneBot Workshop website at https://dbot.ws/mpu6050 <.
"Never trust a computer you can’t throw out a window." — Steve Wozniak
I wanted to see if I could use a MPU-6050 module for a robot arm I'm working on. I don't think anybody has mentioned yet that the New LiquidCrystal library has moved from https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/ to https://github.com/fmalpartida/New-LiquidCrystal
I installed the version from the GitHub repo, and it works fine (after setting the right I2C address for the board I ended up with). Thank goodness for that i2c_scanner example.
I built the Electronic Level as designed, with the omission of the LEDs. My results were pretty much the same as shown in the video. However, I'm seeing a problem that has persisted for me every time I've used any MPU-6050 board (with or without the LCD hooked up). When left still, the sensor will output slightly varying values indefinitely, but if I move the sensor with even the most modest acceleration, the Arduino locks up. Or at least that's what seems to happen. I didn't put a scope on the I2C bus to watch. The same behavior exists with MPU-6050 boards from two different manufacturers, each of which have slightly different hardware designs.
This is perplexing. Is it possible that the accelerometer and gyroscope hardware gets overwhelmed by too much change per tick? I'm going to assume this part isn't robust enough for my intended use. I bought some AS5147 Rotary Sensor boards to see if that's a better fit for my application -- sensing the position of a shaft between 0 and 90 degrees.
@jlamoree I just downloaded the github lib and it doesn't work. Also I see .pde samples so it's very old. POSITIVE isn't declared.
"Don't tell people how to do things. Tell them what to do and let them surprise you with their results.” - G.S. Patton, Gen. USA
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon