Hi, welcome to another video tutorial from Robojax. In this video we are
going to have an introduction to this MPU 6050 accelerometer and gyroscope in
one chip breakout for Arduino. in this video we are going to see how we
can use this and we will provide to the library so you can come and get
everything from one source but this is just basic introduction we will have
updates and advanced feature of this in separate videos you can get the code for
this by clicking at the link of the description below which will take you to
www.robojax.com/learn/arduino let's get started with this
My name is Ahmad Shamshiri and I am presenting this tutorial from Canada.
so what is accelerometer? accelerometers gives you the acceleration of an object
or a robot or a piece of a machine or equipment so you install this as soon as
accelerate in an direct an X for example and Y or in Z in all
three dimensions when it accelerates it will
gives you the acceleration meter per second and of course you can
change the units to get the friend values and then we have four gyroscopes
here gyroscope is used to give you the orientation for example in a robot and
equipment you want to know which side is up down left right so this will help
understand or maneuver properly with the equipment that it's being used in now in
almost every device including the tablets and mobile phones but for
example if you want to build those self-balancing robot that balances
itself so gyroscopes will give you the proper direction where it is which side
is up and also you can use accelerometers to see how fast it's
leaning on one side or the other side and apply proportional force to balance
it so this is one of the most useful component in robotics and very easy to
use of course you can be used in a very advanced way but this is very powerful
and cost-effective
Hardware explained
this module if offered in different variation but the important
part is this chip which is MPU6050 it has accelerometer and gyroscope module
is as I mentioned offer the many variation and but this one has the
actual chip works with 3.3 volts and we have here a voltage regulator that you
can feed a 5 volts and this regulator will convert it 3.3 volts and the
circuit will work fine and XCL and XDA these are this is for accelerometer and this
is for gyroscope SCL and SDA and we have this pin ADO and the i2c or I squared C
address selector . this is an interrupt and then we have VCC and ground on this side
we have nothing it's just double sided PCB. the length of
this module is 20.3mm millimeter the width is
15.5mm millimeter and depth of this one is 3.1mm millimeter
let's have a look at the data sheet this is from InvenSense. these are the values
that our concern this is operating voltage of this as I said we have a
voltage regulator the supplies voltage for us and here are some of the
application that is mentioned by the manufacturer. These are the range
that you concerned plus minus 250 plus minus 500 degrees or 1000 degree or even
2,000 degree per second and for important factor for us
3.6mA current it needs only the gyroscope and the standby is
500 micro ampere so if your application is battery and
this is very important and also for accelerometer these are the setting
values of 2g 4 8 and 16 G plus minus and as ammeter normal operating current is
500 micro ampere so that's half million per full day that mentions VDD in our
case this has a built-in voltage regulator so this doesn't matter for us
because the voltage regulator will supply that 3.3 volts. when you the pin 1
isn't this corner that is on the left top left corner is a pin 1 and here is
based on the pin 1 this is the Y and this is the X and Z is away from the
page from this towards you we are using this chip to find our orientation and
Here is on the actual chip and Z is away from this up from here the module
usually comes with this pin header or maybe with a 90 degree bent type. so in
this tutorial I'm going to connect this and - I'm gonna solder it this way so
the board will be flat I have now soldered the pin headers onto the board.
Getting the library
Here is the library for MPU 6050 this is some guys from Japan and so here
are some information and some others parameters that if you want to play with
so you can click and download it and after just wherever you have saved it
from here go and include Library and from here just go and select it and
include it
Wiring explained
let me explain the wiring the VCC goes to five volts in Arduino here it is there
there the second one is a ground, it is also connected to the GND and then
we have SCL and SDA this red and brown are connected to SCL and SDA
of my Arduino or you can connect SDA to A4 and SCL to A5. there we have
XDA and XCL this these two are the data and clock the same as this one but this
is for accelerometer I've connected two here. if your Arduino doesn't have that
pen so you have to extend this to you have to extend this to a breadboard so
it's absolutely fine your Arduino doesn't have those pins. so you can
connect let's say this one the other one lets you connect it to and A4
for analog 4 and this is to analog 5 A5 and now this is for SDA so you can
connect the pin that is going to SDA for example here if the data is wire brown
one so we can connect a brown here and SCL the white one is connected to here
so i'm going to connect it in this line so these are all connected this line is
all connected just so once you connect one all of them and then the same thing
for this the same thing as you can see SDA is here the red one is the sorry SCL
is SDA brown so SDA here and this yet so it's absolutely fine it because it's a
bus you can connect multiple and up to 127
pair and then the last pin which is interrupt, interrupt connected to pin 2
Code explained
Once you installed the library that I provided, go to file-> example and scroll
down you should see this MPU6050_tockn and then open one of these
so let's just open the All Data this is the one and the first line just includes
this header file this is part of the library this is Wire.ht for I squared C (I2C)
communication this is creating object for this so from this point
beyond we would use MPU6050 and if you're using multiple type of this
device you can just rename it and put here two or three and then create
another object another one for example if you are using two of those and you
can create here to just the name should be different and then when you're
reading the values the same we just use this object and you will get the second
one this is begin so you have to every line that is here with this just replace
it add this as well so you will have the second one functioning and working ID
and set the setup we are initializing this serial monitor the wire begins the
I2C and the initialization starts for MPU 60 50 and here it just
says gyroscope offset inside the loop which is also on there to here we are
just checking the millis() the start of this - a timer which if it's over thousand
because it just displayed the value when it's thousand millisecond or one second
this is just counting that so we don't go very quick giving enough time to
measure all these values and and these are just printing the text this is the
text and these are the value 6050 get dumped this is temperature
acceleration X acceleration Y and I an acceleration at Z and this is for
gyro gyro x y&z gyroscope value and then acceleration angle and gyroscope angle
and these are the general angle of the device if I go here and go to example GetAngle
this time just give the angle this is the one
exactly after here it's exactly the same except the data that we are printing and
gives him some application you just need the angle this is the angle at X this is
the value and this is the angle at Y and this is angle at Z. very simple and
you can use it in your smart car or device that's balancing I don't know
whatever application you're intending to do. thank you for watching this was basic
introduction and I just provided the code that you can use and embed the
school in any application that you have and using these you can use these data
for your robotic purpose. in the future I will create more videos
displaying all these values on LCD LED display and different types of this
place in case some people needed so subscribe so you can get updates of my
upcoming videos thank you
Subtitle typed on Mar 05, 2020 by Ahmad Shamshiri
It is time to click on Subscribe button. This is the least you can do for me.
you