Gyro (Position) sensors (MPU6050) with Arduino - How to access Pitch, Roll and Yaw angles

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 มิ.ย. 2024
  • A quickie video showing how to use the MPU6050 Gyro Sensor to access the Pitch, Roll and YAW angle data.
    Project Page : www.xtronical.com/mpu6050
    GitHib Page for library used : github.com/rfetick/MPU6050_light
    Affiliate links for the items shown:
    MPU6050 : amzn.to/31UhdBU
    Arduino Nano : amzn.to/37Q6E6s
    OLED (SSD1306) : amzn.to/2TyZfjB
    Bread Board : amzn.to/35Kd0lc
    Wires : amzn.to/3jMePmV
    For other projects and ideas see :
    Web : www.xtronical.com
    If you'd like to support me via Patreon then the link is below and that would be just amazing. Patreons have access to all videos early plus can view all the posts on Patreon. There are other rewards if you're interested. If you just want to watch videos then that's also fantastic because without people viewing I wouldn't even do half of what I do. So thanks very much :)
    Patreon at : / xtronical
    If you don't like Patreon and would like to say thank you in other ways then there's also:
    Kofi (Coffee) if you want to tip me for a brew! : ko-fi.com/xtronical
    Also if you go to my website www.xtronical.com you will a part on every page to make a direct one off donation to my paypal.
    Credits
    Intro/Outro Music by Creo Music : www.creo-music.com
    Some sounds from Freesound.org
    Some images from OpenClipart-Vectors from Pixabay
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 120

  • @albrody8861
    @albrody8861 3 ปีที่แล้ว +3

    Wow. This has been the best source of information I have found so far for getting useful data from an MPU6050. I think it is the use of the MPU6050_light library. Thanks!

  • @walidchtioui7930
    @walidchtioui7930 3 ปีที่แล้ว +15

    A remark on yaw angle values :
    Even if you initially calibrate yaw orientation, yaw values will increase nonetheless. I assume this is because of the integral approximation that is occurring behind the scenes. As a matter of fact, the gyroscope doesn't measure angles instead it measures angular motion, that is in rad/sec. To go from that to having angles you need to integrate thus having to use some sort of integral approximation.
    The reason why you don't see this happening with pitch and roll values is because the gyroscope's pitch and roll angle values get the privilege of being 'corrected' by the accelerometer's sensor data. The yaw values, on the other hand, don't have this privilege.
    Edit : typos

  • @drhubs7049
    @drhubs7049 9 หลายเดือนก่อน

    Bro, this was so helpful. I figured out how to pull values without this but having a library like this that actually works is a huge time saver

  • @HexOperator
    @HexOperator หลายเดือนก่อน

    Absolute banger of a video mate. I was going on an absolute tirade trying to calculate the yaw values, but the library works beautifully.

  • @ahmetpehlivan3698
    @ahmetpehlivan3698 ปีที่แล้ว +1

    I was looking for yaw measurement with good calibration and finally i found it !! thank you so much.

  • @minebuddies8804
    @minebuddies8804 6 หลายเดือนก่อน

    Thank you so much! I have looked all over the internet for an example for this module, and it worked very good for me! Big Thanks to you :)

  • @fareed1983
    @fareed1983 2 หลายเดือนก่อน

    Thanks for this. I have been struggling to get this to work from quite a long time.

  • @Rizwaan122
    @Rizwaan122 3 ปีที่แล้ว +2

    cheers mate, i only needed the yaw angle so im glad you went into extra detail on that. Life saver!

    • @Talha80777
      @Talha80777 3 ปีที่แล้ว +1

      did it work without any problem?

  • @georgeandrawos3748
    @georgeandrawos3748 2 ปีที่แล้ว +8

    SIR I CAN'T THANK YOU ENOUGH. I have been trying to fix gyro issues (values increasing over time/inaccurate values) and trying different libraries for literally 7 hours and the libraries are unnecessarily complicated. Your video is very clear, straight to the point and extremely helpful lots of MPU 6050 videos are either unclear or give an unsatisfying result. Thank you so much!!!

    • @XTronical
      @XTronical  2 ปีที่แล้ว +1

      Glad it was so helpful.

    • @daudhtm5203
      @daudhtm5203 2 ปีที่แล้ว +1

      it's not the other libraries fault, its just the gyro and acce. you have to put on a filter for them to be acurate

    • @georgeandrawos3748
      @georgeandrawos3748 2 ปีที่แล้ว

      @@daudhtm5203 I agree but it sure would have been nice for the other libraries, tutorials, and videos to make that tip obvious and not implicit instead of wasting everyone's time.

    • @daudhtm5203
      @daudhtm5203 2 ปีที่แล้ว

      @@georgeandrawos3748 i tried out this library but it seems like the values are still increasing without even moving the gyro.

    • @XTronical
      @XTronical  2 ปีที่แล้ว

      That's the earth's rotation.

  • @inannasrls7219
    @inannasrls7219 3 ปีที่แล้ว +1

    The solution i needed! Thanks a bunch!

  • @TreudtLP
    @TreudtLP 2 หลายเดือนก่อน

    Thanks a lot, die normal MPU6050 Library wasnt working, but now i can finally start

  • @extremeroom7u7
    @extremeroom7u7 2 ปีที่แล้ว +1

    came back here again cause this tutorial is extremely great

  • @johnaustin937
    @johnaustin937 ปีที่แล้ว

    Really helpful
    Especially the library❤
    Thanks

  • @prateekmahajan1929
    @prateekmahajan1929 3 ปีที่แล้ว +1

    Basically all the 3 angles calculated using gyroscope drift, but then a complimentary filter is used to combine values from angles calculated using gyroscope and accelerometer, since the accelerometer can only be used to measure roll and pitch values hence the complementary filter can only be added to roll and pitch but not yaw. So yaw drifts.

  • @brianharper9798
    @brianharper9798 3 ปีที่แล้ว +4

    An amazing little thing for the price, and to think it's actually got microscopic mechanical parts inside. I did build a balancing robot a while ago but was also thinking of one inside a small cube with possibly Bluetooth to control things on the PC by choosing a side and then rotating, so a side chooses an item and rotating gives a value. But never got any further than the initial idea!

    • @XTronical
      @XTronical  3 ปีที่แล้ว

      Are they mechanical, I've never investigated. Your project sounds interesting!

    • @brianharper9798
      @brianharper9798 3 ปีที่แล้ว +1

      Yes, as far as I know they have a mems gyroscope. I vaguely remember looking it up when I built the balancing robot.

  • @nithinsai2250
    @nithinsai2250 3 ปีที่แล้ว +1

    Thanks buddy for sharing this valuable info

    • @XTronical
      @XTronical  3 ปีที่แล้ว

      Glad it helped.

  • @extremeroom7u7
    @extremeroom7u7 2 ปีที่แล้ว +1

    You just made my day

  • @wolfmicioyt7388
    @wolfmicioyt7388 2 ปีที่แล้ว

    I need to use this for a full motion flight simulator, but I want to make sure it fits the job.
    Basically, I've been trying to use the accelerator to get the angles. However, as the platform moved, it was reading incorrect values thus making everything shake.
    My questions are:
    - is this library capable of getting just the angle (ignoring the platform motion)?
    - if I initialise the system at any angle, would it still be able to get the actual value (getting the value from the accelerometer, for instance) or will it start at 0;0;0 deg?
    - How often do I need to re-calibrate the system?
    Thank you for your kind help and attention

  • @TYGAMatt
    @TYGAMatt 3 ปีที่แล้ว +4

    Great timing. I've just started using an MPU6050 in my motorcycle data logger project to measure lean angle, acceleration and braking force. I'm using an ESP32 with the MPU6050_tockn library. You can set the calibration in the code once it's known.
    It's a great little module.
    I've ordered an MPU9250 so looking forward to having a bash with that when it turns up.
    Keep up the good work old boy!!

    • @XTronical
      @XTronical  3 ปีที่แล้ว +1

      Great stuff, I'll have a look at that library. Can't remember now if I checked it or not! Thanks for the comments.

    • @TYGAMatt
      @TYGAMatt 3 ปีที่แล้ว +1

      @@XTronical well, my MPU9250 just turned up, so hopefully can give it a test in the next day or two

    • @TYGAMatt
      @TYGAMatt 3 ปีที่แล้ว

      Hmmmm. Not having a huge amount of joy with the MPU9250. The bolderflight library spits out oodles of data. Way more than I have the time to get my head around. Tried a couple of other libraries but no real joy. Seemed to be getting rather inaccurate roll, pitch and yaw.
      Will stick with the MPU6050 for now as it does what I need and I was just being greedy wanting a 9 axis ;)

    • @prateekmahajan1929
      @prateekmahajan1929 3 ปีที่แล้ว

      i2cdev library has example sketches for getting the angles and an example for getting the accelerations.

    • @prateekmahajan1929
      @prateekmahajan1929 3 ปีที่แล้ว

      You gotta do some changes to make it work with esp32, I usually use an esp8266 in which I just mention Wire.begin(sda_pin, scl_pin); other changes are needed when handling interrupt

  • @jamesnegapatan2082
    @jamesnegapatan2082 2 ปีที่แล้ว

    thank you and this is very helpful!, I understand it quickly, thankyou.

  • @g4ur4v88
    @g4ur4v88 2 ปีที่แล้ว

    Wow nice... Finally I got what I was searching for long time. Can you please share wiring diagram, photo of the board and list of items required

    • @ahmetpehlivan3698
      @ahmetpehlivan3698 ปีที่แล้ว

      Vcc->5V
      gnd->gnd
      SCL->SCL(pin is depends on which arduino you have)
      SDA->SDA (pin is depends on which arduino you have)

  • @taqiuddinwahab5912
    @taqiuddinwahab5912 2 ปีที่แล้ว

    thank you. this is so helpful

  • @lorenzothepasta2820
    @lorenzothepasta2820 3 ปีที่แล้ว

    Lol!! This video is funny and informative. Good job!!!!

  • @carlosalexandremartins7072
    @carlosalexandremartins7072 2 ปีที่แล้ว

    I wonder if the MAP function works with these parameters and if yes what are the maximum and minimum values to add in the works with that function.

  • @virajkharade4213
    @virajkharade4213 ปีที่แล้ว

    Using a magnentometer, we can measure yaw values.....? My doubt is that I am using the MPU9250 and I have already made the code, however, the values of the gyroscope are drifting and counting up point by point. As I have already calibrated the Gyrocope, what else can I do ....?
    If possible, please reply to me.....

  • @AbdulRahman-jz3px
    @AbdulRahman-jz3px ปีที่แล้ว

    Hi, I'm a beginner. I want to ask, what acceleration is meant by MPU6050, can it measure angular acceleration?

  • @hindouba5922
    @hindouba5922 29 วันที่ผ่านมา

    I need to measure the angle of the basketball shot. Can I use it, and what angle is considered correct?

  • @peut
    @peut 3 ปีที่แล้ว +8

    :-) Obviously the yaw increase when not calibrated is sensing the earth rotation :-)

    • @XTronical
      @XTronical  3 ปีที่แล้ว +2

      Ahh, really, thanks.

    • @vivansheth1902
      @vivansheth1902 2 ปีที่แล้ว +1

      😂😂😂😂 is it funny or is it real ?

    • @peut
      @peut 2 ปีที่แล้ว +3

      @@vivansheth1902 No, I don't think it is real,but it is a fun idea

  • @DaMu24
    @DaMu24 ปีที่แล้ว +1

    4:18
    So the exact library used will be dated, especially as Adafruit and other repositories update their libraries, but it's important to note that, if the access to the MPU6050 is uncertain with an installed library, try another one from the manager. Especially important for future use.

  • @ramunasreimontas
    @ramunasreimontas ปีที่แล้ว

    Hello, I wired Arduino and MPU6050 and uploaded project to microcontroller. But I have one problem. If gyroscope not moving (is in stable position) Z axis angle continuously decreasing. Approximately 0.5 deg/minute. How I could solve this problem? Any advise I appreciate. Thanks

  • @pawes7476
    @pawes7476 3 ปีที่แล้ว +1

    That was very helpful! Is it possible to measure the position value (coordinates) with the MPU6050? By integrating the acceleration values or something else? What would you advise to use to get these values for a mobile robot. I would be very grateful for help ;)

    • @XTronical
      @XTronical  3 ปีที่แล้ว

      Yes, I'm quite sure it's possible with the libraries that are available but I've never looked at it. Accuracy may be an issue though, if you want repeatable positions down to millimetre precision then I'm not sure it would be good enough, although I may be wrong. But I can't help more I'm afraid as I've not looked into this.

    • @pawes7476
      @pawes7476 3 ปีที่แล้ว

      @@XTronical ok, so I keep searching the internet, thanks!

    • @marufmorshed3793
      @marufmorshed3793 2 ปีที่แล้ว

      so did you find any sources where we can measure position value(coordinates) with the MPU6050

  • @priminersouthamerica7965
    @priminersouthamerica7965 2 ปีที่แล้ว +1

    That was just great!. The simplest way I have found so far. Thanks !!. I have a question: The YAW value is not very accurate... it changes all the time. Is there anything to do with it? Or is it just the 6050 hardware which is not good enough? Any ideas or suggestions? Thank you again!

    • @XTronical
      @XTronical  2 ปีที่แล้ว

      Thanks. It's changing because of the earth turning. This is 15 deg per hour. So to keep the yaw relative to your position on earth you would have to allow for this.

    • @priminersouthamerica7965
      @priminersouthamerica7965 2 ปีที่แล้ว

      @@XTronical Wow! That's cool!. Do you have any inputs to give me about how to allow that function to keep it relative to my position?. Thank you again!

    • @XTronical
      @XTronical  2 ปีที่แล้ว

      Unfortunately I never investigated further. I should imagine someone has done the solution, perhaps I will revisit this one day.

    • @shun01able
      @shun01able 2 ปีที่แล้ว

      @@XTronical Would a filter like Kalman filter make the value much more consistent? I am planning to use an accelerometer and a gyroscope to track the back posture of an individual and i think i would require a constant or at least a less noisy values

    • @XTronical
      @XTronical  2 ปีที่แล้ว

      Not sure, sorry.

  • @sudattsdeadchannel3495
    @sudattsdeadchannel3495 4 หลายเดือนก่อน

    hi. i need help for my school project. i have a load cell with hx711 amplifier . i want to show load and mpu readings symultaneiously on oled screen. both codes run fine when ran single. when i try to merge them then the code stops after 1st loop. i want help with proper code for this. plz help me , im not smart enough for this

  • @pujiwido5043
    @pujiwido5043 2 ปีที่แล้ว

    mpu.calcOffsets();
    not working when i want to recalibrate with button
    Can you help me?

  • @robinwood5833
    @robinwood5833 3 ปีที่แล้ว

    Really great video, easy to understand, I am trying to write code for if statement to get led to light up when X val = 50 degrees have tried all I know but failing, could you please help?
    Thank you and merry Xmas from Australia

    • @XTronical
      @XTronical  3 ปีที่แล้ว

      I'll code an example this weekend

    • @robinwood5833
      @robinwood5833 3 ปีที่แล้ว

      Thank you very exciting

  • @marekcermak3843
    @marekcermak3843 ปีที่แล้ว

    How does the example code know which pins are you using, for SCL and SDA input? Should I always use A4 and A5, or I dont have to specify pins and just use the mpu.getAngleX,Y,Z() function? And should I connect it also to A5 and if I use Arduino Mega?

    • @XTronical
      @XTronical  ปีที่แล้ว

      Use whatever I do in the video. They are fixed on the Arduino unlike the esp32.

    • @marekcermak3843
      @marekcermak3843 ปีที่แล้ว

      @@XTronical So Ard. Mega has special SCL and SDA input - shorturl.at/einHQ, so I should just hope the libary can work without me specifying the pins. You also did not specify them, or did you? Thanks for answering man!

    • @XTronical
      @XTronical  ปีที่แล้ว

      Just use whichever pins are used for the mega and the library will sort rest out. As when you specify the board your using the library has access to certain "defines" which it can use to set itself up correctly.

    • @XTronical
      @XTronical  ปีที่แล้ว

      Your welcome

  • @connorpetersen4763
    @connorpetersen4763 ปีที่แล้ว

    at 6:19, how did you get the live data from the board to be shown on screen?

    • @XTronical
      @XTronical  ปีที่แล้ว +1

      It's in the code isn't it? Check link in description.

    • @connorpetersen4763
      @connorpetersen4763 ปีที่แล้ว

      @@XTronical I figured it out. Everything was working properly, I didn't realize you have to push the serial monitor button. Thank you, awesome video.

  • @andy_texguittar
    @andy_texguittar ปีที่แล้ว

    bro how can i do the same with an adafruit oled display 0.96 ssd1331?

  • @varl2004
    @varl2004 3 ปีที่แล้ว +1

    thank you for this video, finally I could read data from my sensor but I need some help, I'm using this sensor with Arduino nano, but I can't make it work with Opentrack software, could you do a tutorial for achieving it?, thanks again!

    • @XTronical
      @XTronical  3 ปีที่แล้ว +1

      I'll make a note to check it out but won't be for a while I'm afraid. Currently working on other stuff.

    • @varl2004
      @varl2004 3 ปีที่แล้ว

      @@XTronical just if you can, but it would be very useful because there is not a clear tutorial about how to do it, thank you in advance and greetings from Chile ☺️

  • @thelazycat_
    @thelazycat_ 2 ปีที่แล้ว

    I only see Z slowly increasing, the X and Y stays on 0, any idea?

  • @rakshithahm5131
    @rakshithahm5131 ปีที่แล้ว

    Hyy it's really useful. But values are changing continuously without delay. Is there any way to display the values slowly??

    • @XTronical
      @XTronical  ปีที่แล้ว

      You could average them over several samples and display the average. This would provide some stability to the results.

  • @axonbro707
    @axonbro707 2 ปีที่แล้ว

    I'm able to get this to work when the MPU6050 lays flat, however my robot stands up at 90 degrees initially. I can't get accurate readings when the calibration starts with the MPU vertical. idk why, any help?

    • @XTronical
      @XTronical  2 ปีที่แล้ว

      Sorry, not sure.

  • @vantuilpinheiro8433
    @vantuilpinheiro8433 3 ปีที่แล้ว

    Hi. XTronical. I'm getting abnormal readings. My Pitch is crazy. In the 0º position it gets 40-45º. I didn't get it. After a complete pitch movement of 90º, it shows 145º. Great video, by the way!

    • @XTronical
      @XTronical  3 ปีที่แล้ว

      Thanks, sorry I'm not sure what the problem is without recreating it

    • @nithinsai2250
      @nithinsai2250 3 ปีที่แล้ว

      i think u didnt place it on a flat surface while calibrating

  • @glitch9695
    @glitch9695 3 ปีที่แล้ว

    Do we not need pull up resistors for Data and Clock lines?

  • @Ziqastory
    @Ziqastory 3 ปีที่แล้ว

    hi, ty for the great video. i tried using the coding without oled. It works well on both roll and yaw. Buy my pitch (yaxis) can only reach max of 89 degree only. Can you or anyone help me with this issue?

    • @XTronical
      @XTronical  3 ปีที่แล้ว

      Sorry, Christmas got in the way of this I will try to look at it soon

    • @Ziqastory
      @Ziqastory 3 ปีที่แล้ว

      @@XTronical its okay . i also tried the coding from your project page of getting all data for angle (x,y,z) and its acceleration (g unit) of each axis. Is there any relation between tilt angle and the acceleration? Because when i change angle of x axis to positive value (90 deg etc), only the Y acceleration changes while X accel remain almost constant. Is that normal? i want to study about it but until now i still found no literature regarding the matter. Hope u can help and give a bit explanation.

  • @robjordan63
    @robjordan63 3 ปีที่แล้ว +1

    Happy to oblige with a patronising comment ;-)

    • @XTronical
      @XTronical  3 ปีที่แล้ว

      Thank you 😊

  • @plop5998
    @plop5998 2 ปีที่แล้ว

    hello, when opening the serial monitor it is completely blank. Is there a reason for this?

    • @XTronical
      @XTronical  2 ปีที่แล้ว

      Check your baud rate etc. Check with other seriel demo program.

  • @frenkkotarigan
    @frenkkotarigan ปีที่แล้ว

    Hallo sir
    I want to make an active suspension for an rc car base on gyro and accelerometer
    But i am beginer on arduino
    Could you help me? 🙏

    • @XTronical
      @XTronical  ปีที่แล้ว +1

      Sorry, I don't have enough time to help with individual projects

    • @frenkkotarigan
      @frenkkotarigan ปีที่แล้ว

      @@XTronical it's ok 🙏

  • @samuelstuff4557
    @samuelstuff4557 ปีที่แล้ว

    Does the yaw increase because of gravity affecting it?

    • @XTronical
      @XTronical  ปีที่แล้ว

      It's the earth spinning

    • @samuelstuff4557
      @samuelstuff4557 ปีที่แล้ว

      @@XTronical but wouldn’t that give it 360 degrees every 24 hours not a matter of minutes? Or is that not how it works

  • @Infoiswealth9511
    @Infoiswealth9511 2 ปีที่แล้ว

    yaw is changing with respect to roll and pitch right ???is it correct

    • @XTronical
      @XTronical  2 ปีที่แล้ว

      Yes, it's because the Earth is rotating.

    • @hamedtaran2102
      @hamedtaran2102 5 หลายเดือนก่อน

      ​@@XTronicalNo, this cannot be true, because if you change the position of the x and z axis together, you will still see that the z axis increases over time! I could not solve this problem for several days. In addition, this problem does not exist in newer gyroscope ICs, so the rotation of the earth cannot be the reason

  • @GGGatzy
    @GGGatzy 2 ปีที่แล้ว

    does it have forward and backward data?

    • @XTronical
      @XTronical  2 ปีที่แล้ว

      I've not used this but it has accelerometers so basic movement can be derived from them. Not sure of accuracy.

  • @craftbrewer5401
    @craftbrewer5401 3 ปีที่แล้ว

    One thing I can’t figure out, is how to get/calculate heave - vertical motion. I want to use it in a boat to display pitch, roll and heave ( wave height) Anybody have an idea?

    • @XTronical
      @XTronical  3 ปีที่แล้ว

      You'd need to use the accelerometer results, but I've never looked into this. But that's where I'd start. A certain acceleration over a given time should give you a approx distance travelled. There maybe something in the library that does this.

    • @pravinchavhan8890
      @pravinchavhan8890 3 ปีที่แล้ว

      @@XTronical
      hi , how can i detect 360 degree rotation of y-axis to complete a circle please help me with this

  • @user-lf8jp3dg8e
    @user-lf8jp3dg8e หลายเดือนก่อน +1

    it can not turn over 90 degree

  • @SpiritVector
    @SpiritVector 3 ปีที่แล้ว

    Can I use this in a drone?

    • @XTronical
      @XTronical  3 ปีที่แล้ว

      Yes. Should be OK.

  • @KartihkCg80
    @KartihkCg80 2 ปีที่แล้ว

    Australian 👍🏼

  • @Oxygen_56
    @Oxygen_56 ปีที่แล้ว

    Stupid -- The yaw change (rotation of the xy plane around the z axis) is not a drift or an error that needs to be zeroed. I put my MPU6050 on the kitchen table and collected the axis output for six and a half hours. Pitch and roll values were stable throughout the entire period. However, the yaw values are constantly changing at an extremely linear rate of 0.25 degrees per minute. That's 15 degrees an hour. The planet you are on is rotating at such a speed. It's not a coincidence.

    • @XTronical
      @XTronical  11 หลายเดือนก่อน

      I had a Tik-Toker say that these units could not detect planet drift, yet there it is

  • @-datolith2775
    @-datolith2775 ปีที่แล้ว

    😀

  • @arduinomaquinas
    @arduinomaquinas ปีที่แล้ว +1

    Subscribed + Like 670 👏👏👏👏👏👏

  • @FPChris
    @FPChris 11 หลายเดือนก่อน

    Man. This damn module ALWAYS Yaw drifting. >_

    • @XTronical
      @XTronical  11 หลายเดือนก่อน +1

      Planets moving underneath it, it detects this movement. 15 deg an hour