قياس الميل باستخدام حساس MPU6050 ✈️

هل سافرت من قبل بالطائرة؟


هل كانت الرحلة طويلة وربما تعتقد أن مهنة الطيار صعبة للغاية؟


نحن نتفق معك، ولكن يجب أن تعلم أيضًا أن نظام الطيار الآلي يتحكم في الطائرة في معظم وقت الرحلة بمساعدة بعض المستشعرات مثل MPU6050، والتي يمكنها قياس مدي ميل الطائرة.


مقدمة


الـMPU6050 عبارة عن مستشعر يمكنه قياس التسارع والسرعة والدوران حول المحاور الثلاثة. لهذا السبب يستخدم هذا الحساس في مجموعة واسعة من التطبيقات في الطائرات بدون طيار والروبوتات والهواتف الذكية وأجهزة التحكم في ألعاب الفيديو.


في الغالب، يحتوي هاتفك الذكي على مستشعر مشابه تمامًا لـ MPU6050 هذا المستشعر مسؤول عن العديد من الوظائف مثل تدوير الشاشة عند إمالتها لمنحك تحكمًا أفقيًا بهاتفك. كما أنه يستخدم أيضا للتحكم في الألعاب والتفاعل معها على هاتفك الذكي!


دعونا نتعرف على المزيد حول هذا المستشعر المثير للاهتمام!


الحصول علي القطع


ستحتاج إلى المكونات التالية لهذا المشروع، يمكنك شراؤها من متجر ڤولتات.

Sale Off
Voltaat Arduino Uno R3 (Voltaat Version)
45 QAR
Sale Off
Voltaat Jumper Wires - Male to Female (40 Pack)
10 QAR

التوصيل


توضح الصورة التالية كيفية توصيل الأسلاك بين MPU6050 والاردوينو. بمجرد توصيل MPU6050 والاردوينو ببعضهما البعض، قم بتوصيل الاردوينو بجهاز الكمبيوتر الخاص بك باستخدام وصلة USB.



التوصيلات من الاردوينو إلى MPU6050:

• MPU6050 VCC pin (+ pin) ← Arduino 5V pin

• MPU6050 GND pin (- pin) ← Arduino GND pin

• MPU6050 SCL pin ← Arduino pin 5

• MPU6050 SDA pin ← Arduino pin 4

برمجة الاردوينو


الغرض من نص البرمجة هذا هو الحصول على القراءات من مستشعر MPU6050 وعرض هذه البيانات مباشرة على جهاز الكمبيوتر الخاص بك.


ستحتاج إلى إضافة مكتبة wire.h لكي يعمل بالشكل الصحيح. تسمح المكتبة بالاتصال بين الاردوينو والمستشعر من خلال بروتوكول I2C.


سنستخدم أيضًا مكتبة بسيطة لمستشعر MPU6050، مما سيجعل نص البرمجة سهل الاستخدام.


المكتبات عبارة عن ملفات يمكنك تنزيلها ونسخها إلى ملفات برنامج Arduino IDE حتى يتمكن الاردوينو من التعرف على الحساسات المختلفة. يمكنك تنزيل ملفات المكتبة من قسم المصادر ثم تثبيتها باتباع هذا الدرس.


MPU6050 Library


دعنا نختبره معًا؛ ستتمكن من فهمه باتباع التعليقات والتعليمات الموضحة في النص البرمجى.



/*
Voltaat learn (http://learn.voltaat.com)
Link for full tutorial: https://bit.ly/3hZ4Y1v
Wire library: https://bit.ly/3zfCc2D
MPU6050 library: https://bit.ly/3gIrTOc

Tutorial: Measure titling using MPU6050

The purpose of this sketch is to get readings from the MPU6050 sensor
and print this data directly on your computer.

Connections from the Arduino to the MPU6050:
• Arduino 5V pin → MPU6050 VCC pin (+ pin)
• Arduino GND pin → MPU6050 GND pin (- pin)
• Arduino pin 5 → MPU6050 SCL pin
• Arduino pin 4 → MPU6050 SDA pin
*/

//Include MPU6050 Library
#include < mpu6050_tockn.h >
//This library allows you to connect with I2C/TWI devices
#include < wire.h >

MPU6050 mpu6050(Wire);

//Define variable
long timer = 0;

//Commands inside void setup run once
void setup(){
  //Start the serial monitor at 19200 baud rate (19200 bits per second)
  Serial.begin(9600);
  //This function initializes the Wire library and join the I2C bus as a controller or a peripheral
  Wire.begin();
  //This function initializes the MPU6050 library
  mpu6050.begin();
  //See state of calculating calibration in serial monitor
  mpu6050.calcGyroOffsets(true);
}

//Commands inside void loop run forever
void loop(){
  //Get all data of MPU6050
  mpu6050.update();

  if(millis() - timer > 1000){
    //Print data to serial monitor
    Serial.println("=======================================================");
    Serial.print("temp : "); Serial.println(mpu6050.getTemp());
    Serial.print("accX : "); Serial.print(mpu6050.getAccX());
    Serial.print("\taccY : "); Serial.print(mpu6050.getAccY());
    Serial.print("\taccZ : "); Serial.println(mpu6050.getAccZ());

    Serial.print("gyroX : "); Serial.print(mpu6050.getGyroX());
    Serial.print("\tgyroY : "); Serial.print(mpu6050.getGyroY());
    Serial.print("\tgyroZ : "); Serial.println(mpu6050.getGyroZ());

    Serial.print("accAngleX : "); Serial.print(mpu6050.getAccAngleX());
    Serial.print("\taccAngleY : "); Serial.println(mpu6050.getAccAngleY());

    Serial.print("gyroAngleX : "); Serial.print(mpu6050.getGyroAngleX());
    Serial.print("\tgyroAngleY : "); Serial.print(mpu6050.getGyroAngleY());
    Serial.print("\tgyroAngleZ : "); Serial.println(mpu6050.getGyroAngleZ());

    Serial.print("angleX : "); Serial.print(mpu6050.getAngleX());
    Serial.print("\tangleY : "); Serial.print(mpu6050.getAngleY());
    Serial.print("\tangleZ : "); Serial.println(mpu6050.getAngleZ());
    Serial.println("=======================================================\n");
    timer = millis();

  }

}

قم باختباره




بعد ان قمت بتوصيل مستشعر MPU6050 بشكل صحيح مع الاردوينو كما أوضحنا في قسم التوصيل، بالإضافة إلى تحميل نص البرمجة على لوحة الاردوينو الخاصة بك.


يمكنك الآن الوصول إلى شاشة التواصل وعرض البيانات في Arduino IDE من خلال النقر على أيقونة العدسة المكبرة في الزاوية اليمنى العليا.



نافذة التواصل وعرض البيانات هي أداه رائعة في Arduino IDE تمكنك من إجراء اتصال بين جهاز الكمبيوتر الخاص بك والاردوينو. تسمح بإرسال أوامر واستقبال البينات المختلفة وتكون مفيدة في عرض البيانات مثل القراءات من الحساسات المختلفة.


الآن كما نرى في الصورة التالية، تعرض شاشة التواصل قيم القراءة من مستشعر MPU6050.



يجب عليك أيضًا التأكد من اختيارك لمعدل baud الصحيح (9600) كما هو محدد في البرنامج.


يمكنك القيام بذلك عن طريق النقر على قائمة الاختيار في الركن الأيمن السفلي من نافذة التواصل مع الاردوينو.


المصادر


Arduino Code

MPU6050 Library

Fritzing Wiring file

دروس أخري


LCDs are used in a range of everyday applications, including the automobile radio and the house air conditioning remote. They display data and let you control it through menus.




A servo motor is just a simple DC motor with certain modifications. When you look at it, you'll notice that it has several gears and an electronic circuit.


Most of us are familiar with the switches used in household devices. A relay is a type of switch that can be connected to an Arduino or any other microcontroller.