تصميم منقلة رقمية مع الاردوينو لقياس الزوايا اكتب تعليقُا

 تم نشر هذا المشروع لجميع الأشخاص المهتمين في مجال تصنيع وابتكار المشاريع الإلكترونية والبرمجية، و نود التنويه أن موقع انا الكتروني يخلي مسؤوليته التامة في حال لم يعمل المشروع لدى العميل أو في حال الاستخدام الخاطئ للمكونات الإلكترونية والكهربائية التي قد تؤدي لحدوث الحرائق أو غيرها لا سمح الله.

مقدمـــــــــة عن المشروع

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

في هذا المشروع ، سنقوم ببناء منقلة رقمية باستخدام MPU6050 و الاردوينو . هنا يتم استخدام محرك سيرفو لعرض الزاوية على صورة المنقلة . يتم ربط عمود محرك سيرفو بإبرة تدور على صورة المنقلة للإشارة إلى الزاوية التي يتم عرضها أيضًا على شاشة  LCD .والان نبدأ !! .

متطلبات المشروع

Components Required

  • Arduino UNO
  • MPU6050 Gyroscope Module
  • 16×2 LCD Display
  • Potentiometer 10k
  • SG90-Servo Motor
  • Protractor Image

طريقة العمل والتوصيل

Circuit-Diagram-for-DIY-Arduino-Protractor

يتم التوصيل وفقا للمخطط أعلاه .

 

Circuit Connections between Arduino UNO and MPU6050: 

MPU6050

Arduino UNO

VCC

+5V

GND

GND

SCL

A5

SDA

A4

Circuit Connections between Arduino UNO and Servo Motor:

Servo Motor

Arduino UNO

RED (VCC)

+5V

ORANGE (PWM)

9

BROWN (GND)

GND

Circuit Connections between Arduino UNO and 16×2 LCD:

LCD

Arduino Nano

VSS

GND

VDD

+5V

V0

To Potentiometer Centre PIN

For Controlling Contrast of the LCD

RS

2

RW

GND

E

3

D4

4

D5

5

D6

6

D7

7

A

+5V

K

GND

تنبيه : في حال لم تكن متأكد من قدرتك على تنفيذ خطوات المشروع يرجى استشارة شخص متخصص في هذا المجال.

الكـــــــود البرمجي

لتحميل الكود البرمجي اضغط هنا
#include <Servo.h>                 //Include Servo Motor library for using Servo 
#include <LiquidCrystal.h>         //Include LCD library for using LCD 
#include <Wire.h>                  //Include WIre library for using I2C 

LiquidCrystal lcd(2,3,4,5,6,7);   //Define LCD display pins RS,E,D4,D5,D6,D7

const int MPU_addr=0x68;         //I2C MPU6050 Address

Servo myservo;                  //myservo object for class servo 

int16_t axis_X,axis_Y,axis_Z;    

int minVal=265;
int maxVal=402;

double x;
double y;
double z;

int pos = 0;  

void setup()
{
  Wire.begin();                        //Begins I2C communication
  Wire.beginTransmission(MPU_addr);    //Begins Transmission with MPU6050
  Wire.write(0x6B);                    //Puts MPU6050 in Sleep Mode
  Wire.write(0);                       //Puts MPU6050 in power mode 
  Wire.endTransmission(true);          //Ends Trasmission
  
  myservo.attach(9);               //Servo PWM pin as 9 in UNO
  lcd.begin(16,2);                 //Sets LCD in 16X2 Mode
  lcd.print("CIRCUIT DIGEST");   
  delay(1000);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Arduino");
  lcd.setCursor(0,1);
  lcd.print("MPU6050");
  delay(2000);
  lcd.clear();
}

void loop()
{
  Wire.beginTransmission(MPU_addr); //Begins I2C transmission 
  Wire.write(0x3B);                 //Start with register 0x3B (ACCEL_XOUT_H)             
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,14,true); //Request 14 Registers from MPU6050
  
  axis_X=Wire.read()<<8|Wire.read(); //Obtain 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L) 
  axis_Y=Wire.read()<<8|Wire.read(); //0x3B (ACCEL_YOUT_H) & 0x3C (ACCEL_YOUT_L)
  axis_Z=Wire.read()<<8|Wire.read(); //0x3B (ACCEL_ZOUT_H) & 0x3C (ACCEL_ZOUT_L)
    
    int xAng = map(axis_X,minVal,maxVal,-90,90); 
    int yAng = map(axis_Y,minVal,maxVal,-90,90);
    int zAng = map(axis_Z,minVal,maxVal,-90,90);

   x= RAD_TO_DEG * (atan2(-yAng, -zAng)+PI);     //Formula to calculate x values in degree
     int pos = map(x,0,180,0,180); // As X value is from 0 to 360 deg
     myservo.write(pos);           // Write angle obtained 0 to 180 to servo
     lcd.setCursor(0,0);
     lcd.print("Angle");
     lcd.setCursor(0,1);
     lcd.print(x);                
     delay(500);
     lcd.clear();
}

اترك تعليقاً

لن يتم نشر عنوان بريدك الإلكتروني. الحقول الإلزامية مشار إليها بـ *