Today we will study about the best available IMU (Inertia Measurement Unit) sensor and find out how it can be interfaced with an Arduino. Later in our next tutorial we shall try and visualise the motion sensing in 3D.
IMU sensor module that we'll be using is centered around an MPU-6050 sensor.
The MPU-6050 devices combine a 3-axis gyroscope and a 3-axis accelerometer on the same silicon die, together with an onboard Digital Motion Processor™ (DMP™), which processes complex 6-axis MotionFusion algorithms.
These MotionTracking devices are designed for the low power, low cost, and high-performance requirements of smartphones, tablets and wearable sensors.
Stuffs that you require:
1) Arduino UNO
2) MPU 6050 sensor
3) Connecting Wires
SOFTWARE: Arduino IDE
Communication Protocol: This IMU sensor communicates with the Arduino using I2C Bus Protocol.
You can work on accelerometers and gyroscopes separately, but they are not as accurate as this combined module.
Now, let's move on to the wiring diagram and the connection profile.
Refer to any of these 2 figures below for connection.
If you are facing problems with the above figures,don't panic.....
Go through the Connection Pin Profile below:
Connect 5V [IMU MPU-6050] to VCC [ARDUINO]
Connect SDA [IMU MPU-6050] to Analog IN (A4) [ARDUINO]
Connect SCL [IMU MPU-6050] to Analog IN (A5) [ARDUINO]
Connect GND [IMU MPU-6050] to GND [ARDUINO]
Connect INTPIN [IMU MPU-6050] to Pin 2 (Digital PWM pin) [ARDUINO]
Here, if your MPU 6050 module has a 5V pin, then you can connect it to your arduino’s 5V pin. Else, you will have to connect it to the 3.3V pin in order to avoid any over-voltage issues.
So now that we have setup the hardware, its time to program the Arduino .
Firstly, in order to test the MPU 6050,click on this link and download the arduino library for MPU 6050. There's a zip folder named "MPU6050.zip". Download the folder and extract its contents. After doing so, copy the library folder "MPU6050" and paste it inside the library folder of Arduino. That is, you have to go to the location where the "libraries" folder of Arduino is present and then, simply paste this "MPU6050" folder inside it.
Next, you need to download another library ,named "I2Cdev.zip" (if not previously installed) and paste it inside Arduino's library in the same way as the previous one.
So now, in the "libraries" folder of Arduino, we have two new entities. (Fig: 8 )
Now, click on the arduino IDE and see if these new libraries are visible (Fig (9).
Before including these libraries in your sketch, you need to fetch the code for MPU6050. Refer to Fig (10)
(File > Examples > MPU6050 > Examples > MPU6050_DMP6). Click on this "MPU6050_DMP6" file.
Next, include the libraries "I2Cdev" and "MPU6050" in this sketch [Fig (11)].
After having followed all steps, COMPILE the sketch [Fig (12)].
Now, the final step remains...
If you notice that below right-hand corner of this window, the message says "Arduino/Genuino Uno on COM1" , ensure if its correct. If not refer [Fig (14)]. Don't click on the Serial Monitor now. Only after uploading the sketch [as in Fig (13)], go to the next steps.
You must ensure that the right port is assigned every time you connect your Arduino.
Confused with this new window?? Well, that's your output screen. Technically speaking, we call it as the Serial Monitor. That's where we read our values from different sensors.
STEP: Tools > Serial Monitor or, Shortcut Key (Ctrl + Shift + M)
If you face issues with uploading the sketch, even though you selected the right-ports. Click on this link (for Windows users). For Mac users, refer to the guide. Linux users refer to this webpage for guidance.
After uploading the code, open the serial-monitor and change the “baud-rate” to 115200. If you select any other baud rates then you will see garbage comments because those won’t be in sync. NOTE: 8MHz or slower host processors, like the Teensy @ 3.3v or Ardunio Pro Mini running at 3.3v, cannot handle this baud rate reliably due to the baud timing being too misaligned with processor ticks. You must use 38400 or slower in these cases, or use some kind of external separate crystal solution for the UART timer.
If you don’t see this statement “Initializing I2C devices…” on your screen,then press the RESET button. It should work now. [Fig (15)]
KNOWLEDGECORNER >>You will see a line reading “Send any character to begin DMP programming and demo:” What is DMP??
Ans: DMP stands for Digital Motion Processing. The Invense’s MPU 6050 has an inbuilt motion processor. It processes the values from the accelerometer and gyroscope to give us accurate 3D values ; i.e Yaw , Pitch and Roll. [Fig (16)]
KNOWLEDGECORNER >> We saw that the communication between the sensor and arduino is based on I2C Bus protocol . Likewise,we also included an I2C library in this project. do you know,what I2C stands for?
Ans : The I2C bus physically consists of 2 active wires and a ground connection. The active wires, called SDA and SCL, are both bi-directional. SDA is the Serial DAta line, and SCL is the Serial CLock line. Every device hooked up to the bus has its own unique address, no matter whether it is an MCU, LCD driver, memory, or ASIC. Each of these chips can act as a receiver and/or transmitter, depending on the functionality. Obviously, an LCD driver is only a receiver, while a memory or I/O chip can be both transmitter and receiver.The I2C bus is a multi-master bus. This means that more than one IC capable of initiating a data transfer can be connected to it. The I2C protocol specification states that the IC that initiates a data transfer on the bus is considered the Bus Master. Consequently, at that time, all the other ICs are regarded to be Bus Slaves.As bus masters are generally microcontrollers, here for instance, the bus master is ArduinoUno. Likewise,the MPU sensor is the Bus Slave.
Visualise the motion in 3D in my next tutorial. Click here