Это видео недоступно.
Сожалеем об этом.
How to use MPU-6050 Accelerometer and Gyroscope with Arduino code
HTML-код
- Опубликовано: 17 авг 2024
- In this video you will learn how to use MPU-6050 Accelerometer and Gyroscope sensor module for Arduino.
The best thank you for me is to Subscribe 🔔 to my channel and thumb up the video. It is greatly appreciated. 🔔 😊.
I will reply to all Subscriber's 🔔 questions. So make sure to Subscribe.😊
*** Free Course ***
Arduino Step by Step Course (over 100 lectures) Starts here • Lesson 00 What is Ardu...
Download Code and resources for MPU-6050: robojax.com/L/?...
***Purchase MPU-6050***
Amazon Canada: amzn.to/3qzV2ue
Amazon USA: amzn.to/3vd6kYD
Amazon Europe (all countries): amzn.to/3tbjGmH
Banggood: www.banggood.c...
** Purchase Arduino Start Kit **
Amazon USA: amzn.to/3z88F9G or just UNO board amzn.to/3aY7KOL
Amazon Canada: amzn.to/31an88J or just UNO board amzn.to/3pYxSNN
Amazon Europe (all Europe): amzn.to/3pMCHge or Just UNO board amzn.to/2PgGItD
AliExpress: s.click.aliexp...
Banggood: www.banggood.c... or UNO board www.banggood.c...
eBay: ebay.us/B1JWLi
***** Purchase Authentic Arduino Uno from ***
Amazon USA: amzn.to/2KApAwK
Amazon Canada: amzn.to/37LZ8sW
All Europe Amazon: amzn.to/36YDSzn
Related videos:
MPU-6050 with Display • Using MPU6050 with LCD...
Chapters of this video:
00:00 Start
00:00 Introduction
02:28 Hardware explained
03:45 Datasheet viewed
06:08 Getting library
06:44 Wiring explained
09:05 Code explained
MPU-6050 Registers' map:
www.invensense...
How to use a breadboard (video) : robojax.com/L/?...
Tutorial by Ahmad Shamshiri form Canada
****************************
Arduino Step by Step Course (over 100 lectures) Starts here • Lesson 00 What is Ardu...
Learn Arduino in 30 Minutes (video): robojax.com/L/?...
****************************
If you found this tutorial helpful, please support me so I can continue creating contents like this. Here is PayPal link paypal.me/robo...
If you want to learn Arduino from proven instructor on **Udemy**: bit.ly/rj-udemy
Follow me on Facebook robojaxTV
Follow me on Twitter: / robojaxtv
Follow me on Instagram: / robojax
Tutorial by Robojax.com
Get other projects code and learn Arduino
robojax.com/lea...
#robojaxAccelerometer
#robojax #robojaxMPU6050
Only connect SDA and SCL to retrieve gyro angle and accelerometer values.
XCL and XDA do not need to be connected. They are for connecting an external magnetometer module so that DMU (an advanced, but seldom used, feature) can calculate yaw using the magnetometer as a slave device. You shouldn't need the interrupt pin either, unless you are using the advanced DMU feature of the MPU6050. You only need to connect Vcc, Gnd, SDA and SCL to use the device.
saved
thanks bro this really helped me ; )
THANK YOU
Best Explanation, I have watched 100 videos on youtube, all people are mixing gyro with acceleration, Thanks A lot
Belal you are welcome. Ahmad from Canada.
Hi, I have a problem, its just read x=-90, y=90, and z=0. You have solution for it?
Thank you so much, this vid help me a lot with my school project.
You're very welcome!
Thank you for the excellent explanation.
I have two additional questions:
1) How can I read the temperature?
2) I understand there is a Tangent function available (in the IDE or perhaps in the Library). I need to use this in one axis. Where is it, and how can I get the tangent of the angle the MPU6050 is detecting?
Best video i've ever seen
I am so thankful for this video! Thanks for taking your time with it!
You are welcome. I am please to be helpful. That's very kind of you.
@@robojax You re really awesome. Many thanks for sharing such an informative video. Many thanks.
i have a question. can we use this sensor on inclined plane to test somethings stability? if we could then where do we place it and how is it going to work, im so lost pls helpp.... thanks so much for this videoo tho soo helpful!
Perhaps from watching this video you have learned that this sets a reference coordinate in 3d plane. whatever angle you put it, it sets those as 0,0,0 in x, y and z. So if you are installing it in inclinded surface, then in the code add or subtract that angle. The location doesn't matter. as soon as the module powers up it sets them as zero but you add your inclined value to get correct angle in any of the 3d plane.
@@robojax so its okay if we dont put it on the object that we are going to test? i thought we have to put it there so we can now the angle and stuff from the object? and i still dont get how exactly the sensor work...
you should put it and it has inclination in X or Y or Z and add or subtract the value. inside the cod.e
Thank you for this informative video; I have a question; after doing the same and testing it, I noticed that the Z value is changing over time even without touching the module. Do you have any idea why?
thank you from my heart the simplest calibration at all!
You are welcome.
well, sir, I have one question and any help will be appreciated!
thanks again!
Thank you so much!
P.S.- Love your accent
You are welcome.
P.S. Thank you! 😊
@@robojax
hi , i just want to know how can i calulate number of 360 degrees rotations completed by MPU6050 using arduino . it would be nice if u help me
Hey dude would you please tell me the difference between ADXL345 and MPU6050 , and which one should be preferred for esp32?🙏
The first one is just accelerometer but the 2nd one has gyro and compass. When you use I2C it works with both.
i have been watching this video 2 -3 times and in the and i understood good explanation
Thank you.
Great info. Thanks for sharing. You got yourself another subscriber!
You are welcome. Thank you for not skipping the ads and keep watching it. This will help me a lot.
thanks a lot sir for the explaination and the code ur video helped alot
You are most welcome
Hello what is sample rate in your code ? Thanks
Thank you so much, Now I can use this for my rocket project.
Glad I could help!
hey
did you do it?
I am also making flight computer
I like this instruction,but do we really need interrupt pin to be connected?,because i couldn't see it in the library,thanks.
does anyone know how to simulate the output signal of the mpu6050 with arduino ? i have an electric unicycle and its circuit board works with an accelerometer and i want to use it with a potentiometer. is there any code ?
Arduino is reading digital data from this board. Poetentiometer (variable resistor) is analog. You will need some extra work to convert analog to digital, (in arduino which is easy) then the value to convert it in a format similar to MPU-6050 so Arduino library understands it.
Very clear. Wish i found this video sooner 😟
I am glad you did not. Please share so other know about it. Thanks.
Hi sir,I tried to follow your tutoriali did everything the same. but the value stays on 127 to all variables x y z, i thought my mpu is not working then i tried another MPU Chip and the results are the same, any tips? :)
hi, use I2C scanner to check if device is connected or check wiring. on robojax.com search for I2C scanner code, run it to see if it prints the I2C address then check the wiring.
Hello kind sir, would you please make a video about displaying the data of the sensor on an I2C 0.96" OLED display?
Here is the video on OLED ruclips.net/video/UmYiHTOz-5k/видео.html very easy to use and here is example of a sensor value to be displayed ruclips.net/video/Pgx5fNF4Q6M/видео.html
Thank you, bro. Amazing video. You just solve my problem with this stuff
You are welcome. Pleased to hear that.
Thank you a lot. your video was the best that I found and only your code works for my project. Question: Whats happen If I dont conect INT pin? Sometime the angle Z is decreasing alone, this is my questions. Thanks you man. Congrats, you are a genius
You are welcome. INT pin can be left open. see it in datasheet on page 21 www.invensense.com/wp-content/uploads/2015/02/MPU-6000-Datasheet1.pdf
@Robojax TKS. I'm going to take off INT. And about angle Z, do You Know why the numer is decreasing?
Thanks for you time making this video. What camera are you using for such great closeups? You audio is very low on this video. I rewound a few times to figure out what you said... Maybe you can edit and increase gain.
You are welcome. When I test the video, I have headphone and it sounds good. The problem is once video is uploaded, it is done. can't change it. I will try in future videos. Can you please check my latest video and see if is loud enough?
hello and thanks a lot for your sketch! it works like a charm, but i have a question. How to deal with 180+ problem. For instance i would like to continue storing the angle after i do a 180 degree up to 359. It is possible? I dont know how but in my android phone i tried a gyro sensor test demo and it is possible to continue the rotation up to 360. maybe it should be based on a script like if the prev angle was 179 then continue to add angles bla bla bla? Thanks a lot!
Hello, is it possible to connect 2 different gyroscopes with your code ? If yes, should they be connected in parallel or each one on a different input ?
Hi, I haven't tried it but you can get the idea from this video of mine ruclips.net/video/WQ3oFyF5qeY/видео.html
thx !
You are welcome.
Good day Robojax... Thanks for your videos, you've help me with a lot projects...Thats also why Ive posted this comment...
So I have a mpu6050 and I have build a self balancing RC motorcycle, the project is 99% complete, however, the code on the arduino that reads the data form the mpu would freeze the arduino or cause the some weird shit...I am not sure anymore if it is due to interference or even something dodge in the mpu6050 library which I am currently using
The mpu6050 library I've used is from a guy named Jeff something, he's mpu 6050 code is quite popular...Ill have to search his full name and surname if you want. His code is quite sensitive, if I use a delay() somewhere in my loop() then it bugs out...
Problem is, his source code to read measurements from the mpu6050 is miles long, confuses me and I had to change stuff in his header files to make it work longer on my Nano (In the beginning I often received a Fifo overflow error). I also have two 3.3k pull up resistors on the SCL and SDA pins
I am planning to switch out tomorrow his code and library for yours as yours is much shorter...
MY QUESTION: Have you build something like a self balancing robot with the mpu6050? How sensitive is it to noice and interference from the motors?
Sometimes after I turn on my motor, the mpu will send random angles to the steering servo. The mpu is not that close to the drive motor of the motorcycle (its about 15cm away)
Any idees or comments?
Thanks
Manie
Edit: Jeff Rowberg is the name of the guy that created the mpu6050, on the Arduino forum a lot of people mentioned that they've used his library...
Hi Manie, You are welcome and thank yo for sharing your thoughts. I have not made any self-balancing robot. I love the idea and it is very interesting project to use control system. But I have full time job and family. Very busy trying to make a living.
good luck with your projects.
@@robojax that's cool, I understand👌👌 Thanks anyway and stay safe man👍
What is the price of this sensor in INDIA ? Plz plz help me..
do search on your country's Amazon store. In Canada it is about $14.
so how do you make it balance something like a robot what code would i need for that
that is a big project. search for "balancing robot with mpu-6050"
Thank you so much. This video was beyond helpful.
you are welcome.
Hello, Thank you for the tuto. I do not succeed to get the acceleration (or speed) along one axe. It seems that we can only get angle values for each axes but not the translations. Can you explain ?
Hi, I am not sure what you do different. If you uploaded the code and do not change it, you should get exact result.
Hello!! This is great help for an MPU 5060. Everything working fine but the angles reads as for X:-90, Y:90, Z:0.
What could be the possible errors this may be having??
ThankYou.
please check wiring. or disconnect and see what is the reading.
@@robojaxThnak you for response!! After I replied to the video and before your response to the problem I tried the same setup but found the readings fluctuating and for z: it is going around 1500 or so... same for y and x but below 1000.... even when the MPU was still. In another case I tried I2C scanner for the MPU at a loop of 1sec. It showed 0x68 address and mpu found in first 2 to 3 scans then it said of not founding the same. I think the gyro may be faulty(still have to buy a new one). Or may be there some other technical problem??
""Thanks again for your response.
Really helpful. Thank you. 奥力给
You are welcom. 来自加拿大的艾哈迈德
Hello sir! This is great help for an MPU 5060. Everything working fine but the angles reads as for X:0, Y:0, Z:0.
if i move MPU 5060 it's dosn't change angle.
What could be the possiblity ?
mine angles are changing, but my linear acceleration is not working fine
Can we exchange our codes and libraries?
what are the units of the values, is it on degrees, deg/s, and m?
Yes
thaaanks for this vid!
you are welcome.
Will it work for NODEMCU too?
can you do a video on how to control a motor with the gyro?
It needs lots of work and if I don’t get 100k views in a month else it would be huge waste of my time. I know for sure your request is very specific and may be 500 to 700 people watch it. Won’t work and I have already gave up on RUclips. I get Paid $100hour if I work in my own and working on RUclips is $0.20/hour income. Of course this is for robotics. For junk, pranks, smashing iPhone or musics it is totally different. So RUclips is not working as source of income for educators like me.
@@robojax was just a simple request, i seen other youtuber do it already. I just wanted to see it on your channel. since you have given up on youtube, i guess there is no reason on me being a subscriber. thanks for the respons though.
thanks for the video but how can i get to know how to use this sensor with IF CODE and servo motor?
That you have to do yourself or pay someone. I am very busy to make video on this.
A great video, I am wondering if you could help me on my project using this module , I am trying to write code to put in an "if" statement to light up a led when the "X = 45 " on the serial monitor. I have tried all I know but have no success it would be greatly appreciated
Thank you
Robin From Australia
Hi Robin, even is you keep it stationary, the value will fluctuate. 45 " very large value. and your value will not match. so you have to allow tolerance in your reading. On the page where the code is robojax.com/learn/arduino/?vid=robojax-mpu6050-basic if you look at datasheet on page 12 it show the tolerance is 3% . here is my resent video where I was comparing a value and allowed with certain tolerance like 1% or 10% ruclips.net/video/AI-zzmSZVfw/видео.html you have to watch the video in two section. in the introduction I've explained tolerance and how it works and in the code I've explained how it is accomplished. So experiment with % value to find out which value works for you. if you don't' watch it, you wont' understand. so good luck. Greetings from Ahmad from Canada
So helpful
thank you for making this helpful video!!
You are welcome. snag.gy/AHhRpV.jpg
I am trying with the same process and still, my serial monitor is not showing any readings. Can someone please guide me?
Please watch this video which is part of the course on serial monitor ruclips.net/video/WyWRGoACWFs/видео.html
Thanks a lot for sharing.Nice Video.
Thank you too
You are awesome! :)
Thank you . So are you.
My code gets stuck when it reaches wire.endtransmission(). what is the solution for that?
Please start with new code and use it without modifying it. Once it worked, then modify it.
Thanks so much! is really useful
You are welcome.
Hi, the module is giving accurate results of gyro angles and gyro accelerations, but I could not get acceleration values in X, Y and Z direction. Can you please help me find the possible errors?
Assalamu alaikum Muhammad, I am not sure what could be the issue. You would have to move it to see acceleration. If you haven't modified the code, you should see it. Very rarely possible that the module be bad.
@@robojax Wasalam. Thank you for your reply. I have changed the module as well, but unfortunately I didn't provide me linear acceleration. It only shows angular acceleration. Also I have not changed the code. Also I am expecting linear acceleration from the variables accX, accY, accZ.
Are you available?
Wonderful. I have a great application for this. But it would be nice to graph in the dynamic sense. Or do a sample of say a given time period ( a sew seconds only) and be able to zoom in on the time line.
The tiny brushless motors used in mini quads can be out of balance. Spinning at ~ 25,000 RPM any problems with balance can just obliterate the onboard Gyro/ Accel with many multiples of the 1st Harmonic(often a 6050, but also the ICM 20602 is used)
The size of the GY521 breakout makes sense for these tight places Maybe even with the I will be able to get a handle on where to place my tape on the bell of the motor with out losing my patience and just buying more expensive.
I can't thank you enough for publishing this and the Github link and I can't wait to fool around with the code! Happy New Year. Regards, CGL
You are welcome Chris, I am glad you found this useful. Thank you for your kind and nice comment. Ahmad
Nice one again sir
I have a question .
how exactly can the aceleromiter have a different angle than the gyroscope shouldnt they be the same angle
gyroscope is use to get orientation in X, Y, Z coordinate (up, down, left right and around axis). but accelerometer. is for motion (speed) in specific direction. so angle and acceleration are two different thing.
@@robojax I am talking about how you have 2 angles one for acceleration and another for the gyro because if the gyroscope measures acceleration wouldn't that be the angle that it is at not some gyroAngle
you gotta hold an object like pen in 3d space and try to understand. each has has its own reference and angle.
@@robojax ok. Thank you
Hi, i'm dont know much about Arduino, neither speak english, but you video help me a lot.
But i still don't understand about, on the serial monitor, minute 12:29 for example, you have accX, accY, accZ and their respectives values. Same for Gyro. i would like to know what are these values about since the angles of both gyroscope e accelerometer are given in accAngleX... and accGyroX.
And Angle X, Angle y, Angle z, on the last part, those referenced at the angles of what ?.
If you answer i would be grateful.
Hello, I have spent a lot of time typing the subtitle. Watch it with subtitle . I believe we have over 50 languages.
@@robojax Thank You !
how long do i let the code run for it to be calebrated
forever lol
@@nettyvoyager6336 is it like instant or something?
I have not tested it and don't know.
Really informative
I am glad you liked it. Thanks.
Thanks Sir! That's very informative tut.. Please sir guide me how can we set the code for Two MPU6050 Sensor, means how can we set the address for another MPU6050. Thanks Sir
So you want to use, two of the same module? if so I have no answer for that.
@@robojax A lot thanks sir... I have done it..
How? I am having the same problem. I will be happy if u could help please
Thank you very much
The function GETACCX, GETACCY, GETACCZ returns you the value of aceleration in m/s2?
No, it is in G
1 g is about 9.81 m/s^2
Can you help with the MPU library? I can not start the calibration mode in my mpu..... By the way my email is marcoaurelio_19@hotmail.com. I will appreciate so much if you can help me.
Hello sir!
How can I get the value in m/s*s instead of 'g'
Convert it , get the formula and convert it using simple math.
How can connect two mpu6050s together with this library? For some reason i cant get my code to work..what do i need to modify in the library to get two imus to work together?
I spent 2 or 3 days and it did not work. It seems we need different library so it can work with multiple modules. If I get a chance, I will write library but not in the near future.
@@robojaxohh i see. Im probably going to have to use more than one arduino uno then. Thanks anyways...your help was appreciated!!
You are welcome.
Hi sir,
Can I use this sensor to engage a servo if an angle detected on x or y axis (e.g over 60 degrees)
Could you help me please?
Thank you in advance!
yes you can. Try this to print value on serial monitor with if condition. Once it worked, then use servo.
you can do it with a 180 degree servo
If you use a second accelerometer, How is going to be the wire connection for the second accelerometer?
You can use the exact principle in this video that uses two LED display. Apply it to the MPU-6050 ruclips.net/video/27KjMfPH1dk/видео.html
@@robojax can you please specify how to use SDA & ADo pin for both the accelerometer
Can you get the speed of motion with this device?
Yes this is exactly it is made for.
@@robojax Of course...daaa! Thanks
what we get when connect XDA and XCL?
It is just to connect two of this module. Auxiliary pins.
@@robojax ok....sir one more thing can I calculate still position of a human through this sensor and how I can do this...any idea
Thank you...
You are welcome.
So, it can't start at any angle and read that angle.
When it starts from any position that is your reference and it would be zero. You then calculate from that point. Of course you can write your own code with some action or push buttons so it can initialized from new reference point.
Hmmm the wiring is a bit unclear. Could you help explain more on it?
I just watched the video and I have not left out anything in wiring. You need to listen carefully. You can't jump or skip to watch it quickly. to understand the wiring, you should have watched the beginning of the video where I explained the hardware and all pins.
@@robojax Hey! Thank you very much for replying and making such a good video! Sorry i think you misunderstood me, what i meant was that the wiring was well explained, however I was confused with some of the connections that you explained. And also, I actually watched the whole video 5 times just to make sure i understand the whole process.
I hope you could help confirm if im doing the connection right. My connection is as follows :
(Arduino Uno)->MPU6050
5V->Vcc
Gnd->Gnd
SCL->SCL
SDA->SDA
Now this is where I get a bit confused,
For default settings i connected the following:
A4->XDA
A5->XCL
(No Connection)->ADO
Digital Pin 2>Int
IS that correct?
@@robojax hi jax, I redid the wiring and i found that the problem was a faulty wire and not the connection! It seems a loose or bad connection will cause the program to stop immediately.
I have a problem though that i hope you could help with. its mainly due to the IMU drift. I see the value slowly drift upwards when idle at times and sometimes it hovers up and down at a a set value.
Is there any way to help improve this?
i can do that by esp32 ??
yes
great video but the code is not working !
Am I the only one ?
It should work. You must download the provided library and code.
How can I connect this to Arduino Uno........plz provide pin connection with a diagram
I have explained it. Watch the video.
analogic 4 = sda
analogic 5 = scl
I cannot understand where you plug it into the arduino board
I am sorry i misread you comments. I have explained the wiring at 06:44 (click on 06:44 to see it)
Led of the mpu6050 is not getting on
is this a question or statement?
Question because led of my module not getting on
How can I change from 2g to 8g or 16g?
Hi,
In MPU6050_tockn.cpp line 12 shown here github.com/tockn/MPU6050_tockn/blob/master/src/MPU6050_tockn.cpp
writeMPU6050(MPU6050_ACCEL_CONFIG, 0x00); selected 2g now. Change it as you desire.
0x00 ±2g (this is set now.)
0x01 ±4g
0x02 ±8g
0x03 ±16g
Here is how I found them
In page 15 www.invensense.com/wp-content/uploads/2015/02/MPU-6000-Register-Map1.pdf
ACCEL_CONFIG Bit 3 and 4 in Register 0x1c or 28 (decimal)
In line 11 in header file shows the address 0x1c:
github.com/tockn/MPU6050_tockn/blob/master/src/MPU6050_tockn.h
? never heard from you
@@robojax Oh sry RUclips did not notificate me that you answered me. Sadly this doesnt help ... Still only 2g.
why my MPU 6050 just read 90 degree angle?
move it or rotate it. Perhaps you are keeping in the same axis. This is strange.
@@robojax oh no, it just read x -90 , y 90, and z 0. I have rotate it, but the result is same. How? You have a solution?
Is that Java? Is there any way I can use Python?
the code is written for Arduino and it is in C, yes you can write it for Python, but you have to convert everything including the classes in the library.
Robojax thanks
how to download library linlk plz?
Under the video there is description box. I have links for the code and library.
i gets only 0's in output of all data
Either the code has changed when you copied or wiring is incorrect. Try to copy and paste the code
Some modules pull AD0 high, some pull it low. It sets the slave address to 67 or 68. Try using the other address in the code.
i have two of these devices
I have three and a half devices.
@@SH-vv7zq half lol what happened ?
@@nettyvoyager6336 Well, they only supplied the x-axis and half the y-axis this shipping - the other half of the y-axis and the z-axis are being shipped when the store receives them. I'm just gonna have to make do for now.
@@SH-vv7zq bloody china again it takes a good month from them even though they are efficient but yeah i just ran out of can for my project its a robot
I should have a box to test then.
7:35 xDD
?
One dislike for xcl and xda
Thank you very much.
It is useless. too many commercial advertisement and too few details
If you don't like the commercial, you can purchase RUclips premium and watch it commercial free. For the details please see the video rating. Thank you.
This video is why I struggle s much. You just totally skipped over the ADO pin and you weren't very clear at all with the the XDA AND XCL mess either...
those were not of our concern. I have provided the link to datasheet in the same page where Arduino code is. See the description.
They're not really necessary for his purpose
He isn't really unclear-- it takes some common sense of yourself to figure out.
ABIS MAKE YA LO. NGOMONG LEMES AMAT AJG
maaf saya tidak mengerti apa yang kamu katakan
Why you speak so quiet
It might have been recorded low. I am using headphone to listen and it sounds fine. You could just turn the volume up. I will try to boost the volume in my upcoming videos.
@@robojax ok thanks:)