Gyroscopes and accelerometers are essential sensors in drones that work together to maintain stable flight: the accelerometer measures linear acceleration in three directions (forward/backward, side-to-side, up/down) to detect motion and adjust speed and balance, while the gyroscope detects angular rotation around three axes (X, Y, Z) to sense tilts and rotations and make adjustments to keep the drone level. These sensors provide real-time feedback to the drone's control system, enabling stable and responsive flight. The MPU6050 sensor combines both functions and is commonly used with microcontrollers like ESP32 for drone stabilization projects.
Gyroscope & Accelerometer Explained: Drone Stability & MPU-6050 Tutorial
Added:and today I will talk about a new project that is kind of I think I think that is kind of intermediate level of our a project because at first we used to do like LED and blah blah blah which is very much Elementary but today uh I will discuss something different that is gyroscope and additionally something more than that and what is the use of this ready to uncover the secret sauce that keeps drones flying smoothly let's get started at the heart of every drone stability lie two unsung heroes the accelerometer and the gyroscope first up the accelerometer this tiny sensor measures acceleration in three directions forward W and backward side to side and up and down imagine moving a drone forward the accelerometer detects this motion and sends real-time data to the drone's control system adjusting speed and balance now tilt the Drone rightward the accelerometer picks up this shift too ensuring smooth turns and Maneuvers and when the Drone ascends the accelerometer measures the upward acceleration helping it maintain a steady climb next let's talk about the gyroscope this sensor detects angular rotation around three axes the xais Y ya AIS and z-axis tilting the Drone forward or backward the gyroscope senses this rotation and makes tiny adjustments to keep it level tilt it side to side and the gyroscope is on it maintaining balance spin it clockwise or counterclockwise and the gyroscope ensures the Drone doesn't spiral out of control together the accelerometer and gyroscope work in harmony providing real-time feedback to the drone's control system the result a stable responsive flight whether you're capturing stunning aerial footage or racing through an obstacle course okay for that I am first time using uh esp32 before you and for that you have to come like I start from the beginning uh the come to um my project start new and I need I esp32 and then I know okay and this is my workplace and okay let me simulate uh let me connect this and then we will move to the code uh let explain what I have done uh what I have done before that I want to uh this sorry for mention the wrong name of this component this is gyroscope and accelerat meter and uh these are various pins but what that pins I need uh now I will explain that if you have enough interest you can ask jbd it can help you to understand each and use of each and every Point okay first of all it is yes2 we need to connect the Power Pin VCC I explained earlier the VCC pins it will uh be connected with volt right and that's why I have connected it in 5 volt and then ground uh I have explained earlier ground will be connected to ground and if You observe then you'll have other ground pin in this uh column you can also uh connect with this as well and the next thing that is s and sdl as I have uh explained I think U time and again in my previous videos I was explaining the LCD screen screen what is the or function of HCL and what is the function of HDL so if you are following my videos I think explaining this um the function is like uh nothing but time most so uh I am connecting SC with 22 uh Toth pin and HDL with 21th pin and it is very much Essential to me uh keep in mind that I have to use I have to connect uh this two pin with this specific um pins okay okay fine uh let's move on to the code okay fine this is the code that is very much a lengthy code so it is very uh I think tough as so to uh type you I have read the code earlier and I will likey to explain this line Bel L whatever you need to do and uh to listen me carefully and understand whatever I'm saying this is adap fruit uh mpu 650h this is the header file to understand the command I am I want to give with related to this component if you whenever you search this component like I'm showing us like gyroscope see that mpu 6050 so this is the name of this uh component and this header file contains the command that I need to do and I can do with this uh component and will help the compiler to execute the specific thing that I want okay then uh and fruit uh sensor. H this is also a header file and the next thing that is include y.h I have explained it earlier what is the use of y.h y. H is a fun header file that help me to help me so that I don't need to explain the connections okay uh like I have earlier I se earlier that uh you have to have you have to connect the S da with 21 SC with 22 because in this y. H in this header file it is by default written that the HCL will be connected to that this pin and HDL will connect to 21 pin so if you code perfectly and con if you have connction perfectly but you didn't maintain this the connection of this two pin then definitely the code will not work because uh by default uh the demand and your configuration is matching okay this is the and so what is the use of this y uh because just only uh explaining just writing this herror file it helped me that I don't it helps me in this respect that I don't need to the connections line at all okay fine this is adap fruit m p u actually this uh if you are familiar with with like C uh program then you maybe you have written as like if I see you if I show you [Music] like okay and uh we may be familiar with C programming so if I declare a variable like a so I need to declare what type of variable it is so I need to uh say like in a isn't it okay and then in this case this is happening the same thing the mpu this is the name of the class and what type of class is it this is adap RO mpu 6050 I think you have got the point then it comes vo serum and void Lo we know that vo setup uh we need to mention those setup that have to have for the first time and for the last time I think in the whole code I have to do this setup for one time only a single time only those have to WR in The Voice setup those Duty have to executed time and again in that code repeatedly that have to be mentioned in the uh voice Loop section okay so what about the writing code indicates here calv 1 520 this I think I don't need to explain because uh I have explained it earlier is it says to start the communication okay and uh in what rate this number is showing the rate of the communication okay and then uh using this line I have started the communication I started the work okay and then and it comes the if this happens for uh look at this mpu I think you can got the point mpu means this uh objects okay actually this is um as I have said earlier like it is similar to the um variable variable and the variable declaration type so um mpu do begin that means I want to start initialize the mpu that I have earlier so and now notice something different that is not this sign represent not in coding okay so if this is zero this is the interpretation of this uh line okay if there is no this exclamatory sign only this uh is written I think this one is written that means two means one okay if uh but in this code this is not sign before this that means zero or false okay so if it is false uh I mean in this means if nothing is executed then serial print in failed to initialize mpu 6050 sensor that means that if nothing executed nothing happens then definitely uh give me a what can say message that there is error in the sensor but if the mpu uh full stop being equal to one or if you can omit this part as well this part okay uh so if this isal to equal toal to one that if it is two then delay [Music] for 20 seconds okay and and when it will happen when uh notice that the if and then this is nested while okay so this the summary is if nothing happen nothing initialized then the compiler will go in this section and then it will work for 20 second for new updates new data if nothing happens then finish but if happens then it will go in this Loop okay fine and then the uh vo Loop the vo loop again like AC c g y r o t m these like kind one kind of variables okay that um I have said earlier that int a in a variable and and int the denotes it type so similarly in this coding ACC G TMP as the variable okay where I will put the datas okay fine and mpu do event do uh get even that means definitely I am getting datas whether the Drone is rotating with respect to x-axis or not what is the rate of rotating with xaxis or yis or Z Axis or what is the temperature of the surrounding and is there any acceleration around along the x or zerxis so this data will be stored in ACC and GCC G G and temp this ACC will store the acceleration update along the xais Y AIS and Z axis and the gyro will uh store the data of rotating it x with respect to x-axis or Y AIS or Z axis and temperature will store the temperature values so now what I need to do I need to print those values so serial print in acceleration m/s Square this is the unit of acceleration and uh I'm saying that the in the serial monitor this message should be printed this message should be printed okay fine and then serial print notice one thing notice serial print in and print what is the difference between these two one I am writing sh print in that means after printing this message go to the next line or new line okay but if I just uh write print in that means after printing this stay in this line okay so in the next line uh serial okay serial do print I think something has happened sorry for that I need to correct this okay serial.
print bracket uh double quotation x s um X and what will be printed here in this before after the X the serial print ACC do acceleration. X that means after writing X or printing X print the acceleration along the x-axis and similarly print Y and after printing y uh print the value of acceleration along the Y AIS and similar for the Z axis after printing z uh print the value of acceleration on the Z axis this is the interpretation of the code and then here comes the next part that is signal print in rotation de per second that means print the um this message okay and then go to the next line because that is in okay okay but after coming the next line I'm saying that uh serial print in the serial monitor print this message X okay and then after printing X print serial print that means print in the serial this this means actually this means the angle of the along the xais when suppose if it is rotating along with the respect to xais definitely it is it has angular velocity and angular velocity means radian per second and this is giving me the value H but I need the value into degree so I need to convert it into degree so that's why I am multiplying 180 into 18 Pi I think you are familiar with this uh if I want to convert uh radian into degree I need to uh multiply the radian in um with 180° and divide it by 3.14 and in the same as I have explained earlier in this section acceleration section and the the meaning of this line that print in the serial monitor Y and after print printing y print the value of the rotation along the y y AIS and this is because to convert the radian into degree per second de per second and for the same explanation for the Z axis and that's it and then after the very uh last I have to explain this four lines see p I think you've got Point what is going on here and then serial print in temperature. temp for temp. temperature and that means I am saying that or commanding to print the temperature value the serial Monitor and then serial uh print in this line is for like giving a new uh what can I say section or uh new blank Line This is already mentioned here that G and then delay for 500 seconds okay and then here comes the end of the code let us uh try to simulate this uh it will take uh time okay close close it because I haven't uh add the library so come here come here and write mpu uh this comes then I have it's okay fine let's come to the code and then simul it I think you can see that it is being updated after certain period of time that I have mentioned here and for the explanation I am pausing this you can see that as I have said earlier that I want to uh see this command you can see this command this is WR right in here and I want to see the acceler acceleration along the x-axis you can see that there is no acceleration along the xaxis there is no acceleration in the y and z y axis but zis it has some acceleration then comes the rotation there is no rotation on with respect to X Y and Z axis that means it is not rotating it is still but going upward okay I'm saying again like if uh like a helicopter okay uh it is not going right left um front or back it is just uh going upward this data showing me uh giving me this case of sense that my vehicle or my drone is also uh doing something like this and then uh this is the uh reputation again because I have said that they said that after 5 100 second do the do this again so it is doing this again because if I want to update this value what I do uh I think this is I'm saying showing you again uh press in this black part and then if you change uh the parameters you'll see the changes uh zero like I'm also using this and temperature can also be changed and then come to the point uh I have shown you earlier that the acceleration was along the xaxis and Y AIS zero but ZX was 9 something but now you can see that it is 11 something y is- 10 something Z is minus 2 point something so this change has been made because I have uh I bought changes in the um drone or the machine environment and how in this part in this simulation I have made the change with the the very previous work I have done by changing the parameters and rotation at first there is no rotation along the X uh with respect to X Y and Z axis but now it is rotating uh 85.9 de per second and along the with to yis minus 100.5 de per second and with respect to zis is rotating in this degree the temperature is this and uh now you can change value as well and if I start this again then you you'll see the life changes and like this and I changed the parameter again and now you can see the this in now just see the gis was- 2- 2 something that is 4. 41 and the xaxis isus 20 uh 25 whereas it was around 180 something the temperature has also um become changed and this is all over today's um Pro coding and program uh one thing I need to say what this G Det notes g means uh 9.8 1 g means 9.8 2 g means 9.8 into 2 1.2g means 9.8 to 1.2 okay I think you have got the point this is all about today's coding and programming uh if you are enthusiastic about drone and and this type of uh projects I think this will help me a lot definitely you have to have the knowledge about gyroscope and acceler meters so I think you get will get the help from this video uh so thanks you so much for watching my video and keep watching do subscribe uh share with your friend and definitely give me suggestion what type of development I have to do um in my channel let me know and help us help me to grow
Up Next

US-China Trade War: Tariffs, Tech Conflict, and Economic Fallout
@frontline
5.4M views•2019-05-13

Triumph of Orthodoxy Icon: Byzantine Art & History Explained
@BenCallan
2.1K views•2024-08-06

FastAPI vs Flask vs Django: Choosing the Right Python Web Framework
@TechWithTim
302.5K views•2024-05-26

Game of Thrones Opening Credits: A Cinematic Analysis
@gameofthrones
46.3M views•2011-04-18
Related Study Plans & Knowledge Roadmaps
Structured learning paths in General & Interdisciplinary Studies