কোড অনুসন্ধান

LCD 1602 বা LCD2004-এ MPU-6050 সেন্সর ডেটা প্রদর্শন করা Arduino দিয়ে

LCD 1602 বা LCD2004-এ MPU-6050 সেন্সর ডেটা প্রদর্শন করা Arduino দিয়ে

এই টিউটোরিয়ালে, আমরা শিখব কীভাবে Arduino ব্যবহার করে MPU-6050 সেন্সর থেকে ডেটা LCD 1602 বা LCD2004-তে প্রদর্শন করা যায়। MPU-6050 একটি বহুমুখী সেন্সর যা একটি 3-অক্ষের গাইরোস্কোপ এবং একটি 3-অক্ষের অ্যাক্সিলেরোমিটার একত্রিত করে, যা এটিকে গতি সনাক্তকরণ এবং অভিযোজন নির্ণয়ের মতো বিভিন্ন প্রয়োগের জন্য আদর্শ করে তোলে। এই সেন্সরটিকে একটি LCD ডিসপ্লের সাথে সংযুক্ত করে, আমরা রিয়েল-টাইম সেন্সর ডেটা, যেমন কোণ এবং তাপমাত্রা,可视化 করতে পারি।

এই প্রকল্পে অগ্রসর হওয়ার সাথে সাথে, আমরা প্রয়োজনীয় হার্ডওয়্যার উপাদান, তারের সংযোগের বিবরণ এবং কোড বাস্তবায়ন কভার করব। এটি আপনাকে MPU-6050 সেট আপ করতে এবং এর আউটপুট LCD-তে প্রদর্শন করতে বুঝতে সাহায্য করবে। কোড সম্পর্কে আরও স্পষ্টতার জন্য, ভিডিওটি দেখতে ভুলবেন না (ভিডিওতে 00:00 সময়ে)।

হার্ডওয়্যার ব্যাখ্যা

এই প্রকল্পের প্রাথমিক উপাদানগুলি হল Arduino বোর্ড, MPU-6050 সেন্সর এবং LCD ডিসপ্লে (1602 বা 2004)। Arduino মাইক্রোকন্ট্রোলার হিসেবে কাজ করে যা MPU-6050 থেকে ডেটা প্রক্রিয়া করে এবং তা LCD-তে পাঠায়।

MPU-6050 সেন্সর Arduino-তে ডেটা পাঠাতে I2C যোগাযোগ ব্যবহার করে। এতে একটি অ্যাক্সিলেরোমিটার এবং একটি গাইরোস্কোপ অন্তর্ভুক্ত রয়েছে, যা এটিকে গতি এবং অভিযোজন অনুভব করতে সক্ষম করে। LCD ডিসপ্লে সেন্সর ডেটা থেকে প্রাপ্ত কোণগুলি দেখাতে ব্যবহৃত হয়। এটি I2C এর মাধ্যমেও Arduino-এর সাথে সংযুক্ত হয়, যা তারের সংযোগ এবং যোগাযোগ সহজ করে।

ডেটাশিট বিবরণ

প্রস্তুতকারকইনভেনসেন্স
পার্ট নম্বরMPU-6050
লজিক/আইও ভোল্টেজ3.3 V / 5 V
সাপ্লাই ভোল্টেজ3.3 V থেকে 5 V
আউটপুট ডেটা রেট1 kHz (সর্বোচ্চ)
তাপমাত্রা পরিসীমা-40 থেকে +85 °C
প্যাকেজQFN
নোট / ভেরিয়েন্টগাইরোস্কোপ এবং অ্যাক্সিলেরোমিটার একীভূত

  • নির্দিষ্ট ভোল্টেজ পরিসীমার মধ্যে সঠিক পাওয়ার সাপ্লাই নিশ্চিত করুন।
  • প্রয়োজনে I2C লাইনে পুল-আপ রেজিস্টর ব্যবহার করুন।
  • আপনার সেটআপের সাথে সামঞ্জস্যের জন্য I2C ঠিকানা পরীক্ষা করুন।
  • সঠিক রিডিংয়ের জন্য সেন্সরটি ক্যালিব্রেট করুন।
  • শর্ট সার্কিট এড়াতে তারের সংযোগে সতর্ক থাকুন।

তারের সংযোগ নির্দেশাবলী

arduino_wiring_MPU-6050_LCD2004_bb

MPU-6050 কে Arduino-তে সংযোগ করতে, প্রথমে MPU-6050 এর VCC পিনটি Arduino-এর 5V পিনের সাথে সংযুক্ত করুন। এরপর, MPU-6050 এর GND পিনটি Arduino-এর যেকোনো GND পিনের সাথে সংযুক্ত করুন। I2C যোগাযোগের জন্য, MPU-6050 এর SDA পিনটি Arduino-এর অ্যানালগ পিন A4-এর সাথে সংযুক্ত করুন এবং SCL পিনটি অ্যানালগ পিন A5-এর সাথে সংযুক্ত করুন।

LCD ডিসপ্লের জন্য, VCC পিনটি Arduino-এর 5V পিনের সাথে এবং GND পিনটি Arduino-এর GND পিনের সাথে সংযুক্ত করুন। LCD-এর SDA পিনটি MPU-6050-এর জন্য ব্যবহৃত একই A4 পিনের সাথে এবং LCD-এর SCL পিনটি A5 পিনের সাথে সংযুক্ত করুন। এইভাবে, MPU-6050 এবং LCD উভয়ই একই I2C লাইন ভাগ করে, যা তারের সংযোগ সহজ করে।

সংযোগগুলি নিরাপদ এবং কোনো আলগা তার নেই তা নিশ্চিত করুন। যদি আপনার LCD বা সেন্সর চালু না হয়, তবে তারের সংযোগ এবং সংযোগগুলি পুনরায় পরীক্ষা করুন।

কোড উদাহরণ ও ব্যাখ্যা

কোডে, আমরা MPU-6050 এবং LCD-এর জন্য প্রয়োজনীয় লাইব্রেরিগুলি অন্তর্ভুক্ত করে শুরু করি:

#include 
#include 

#include 

এখানে, আমরা MPU-6050 এবং LCD উভয়ের জন্য ইনস্ট্যান্স তৈরি করি। MPU-6050 I2C যোগাযোগের জন্য `Wire` লাইব্রেরি দিয়ে আরম্ভ করা হয়, যখন LCD তার ঠিকানা এবং মাত্রা দিয়ে সেট আপ করা হয়।

সেটআপ ফাংশনে, আমরা সেন্সর এবং LCD আরম্ভ করি:

void setup() {
  Serial.begin(9600);
  Wire.begin();
  mpu6050.begin();
  lcd.begin();
  lcd.backlight();
  lcd.clear();
}

এই কোডটি ডিবাগিংয়ের জন্য সিরিয়াল যোগাযোগ সেট আপ করে, I2C যোগাযোগ আরম্ভ করে এবং LCD ডিসপ্লের জন্য প্রস্তুত করে। ডিসপ্লে দৃশ্যমান করতে ব্যাকলাইট চালু করা হয়।

লুপ ফাংশনে, আমরা ক্রমাগত MPU-6050 থেকে ডেটা পড়ি এবং LCD-তে প্রদর্শন করি:

void loop() {
  mpu6050.update();
  lcd.clear();
  lcdDisplay(mpu6050.getAngleX(), mpu6050.getAngleY(), mpu6050.getAngleZ());
  delay(100);
}

এই স্নিপেটটি সেন্সর ডেটা আপডেট করে এবং প্রতি 100 মিলিসেকেন্ডে নতুন রিডিংয়ের জন্য LCD পরিষ্কার করে। LCD-তে কোণগুলি দেখাতে `lcdDisplay` ফাংশনটি কল করা হয়।

সম্পূর্ণ বোঝার জন্য, অনুগ্রহ করে সংশ্লিষ্ট ভিডিওটি দেখুন যেখানে সম্পূর্ণ কোড প্রদর্শিত হয়েছে (ভিডিওতে 00:00 সময়ে)।

প্রদর্শন / কী আশা করবেন

যখন সবকিছু সঠিকভাবে সেট আপ করা হয়, তখন LCD-তে X, Y এবং Z অক্ষের কোণগুলি রিয়েল-টাইমে প্রদর্শিত হওয়া উচিত। আপনি MPU-6050 সেন্সরটি কাত করে ডিসপ্লেতে পরিবর্তন দেখতে পারেন। যদি সমস্যা হয়, তবে আপনার তারের সংযোগে বিপরীত পোলারিটি পরীক্ষা করুন বা I2C ঠিকানাগুলি সঠিকভাবে সেট করা আছে তা নিশ্চিত করুন।

LCD-তে মানগুলি পর্যবেক্ষণ করলে আপনি দেখতে পাবেন কীভাবে সেন্সরটি গতি এবং অভিযোজন পরিবর্তনে সাড়া দেয়। যদি মানগুলি স্থির বা ভুল মনে হয়, তবে সংযোগগুলি যাচাই করুন এবং সেন্সরটি সঠিকভাবে কাজ করছে তা নিশ্চিত করুন।

ছবি

arduino_wiring_MPU-6050_LCD2004_bb
arduino_wiring_MPU-6050_LCD2004_bb
LCD2004_display-3
LCD2004_display-3
LCD2004_display-1
LCD2004_display-1
LCD2004_display-2
LCD2004_display-2
119-Arduino code for MPU-6050 accelerometer and gyroscope sensor (angles only)
ভাষা: C++
/*
 * 
 * This code is basic usage of the MPU-6050 accelerometer and gyroscope.
 * Running this code, you will get angles only.
 * The angles at X, Y, and Z are displayed on the LCD2004-I2C display module.
 * 
 * Library and code have been taken from:
 * https://github.com/tockn/MPU6050_tockn
 * 
 * Updated by Ahmad Shamshiri on July 07, 2018 at 13:43 in Ajax, Ontario, Canada
 * for Robojax.com
 * Get this code from Robojax.com
 * Watch video instruction for this code at: https://youtu.be/ixe--SXemp8
 * 
 * You will need to watch two videos before following the instructions in this video:
 * 1-MPU6050 Introduction video and code: https://youtu.be/uhh7ik02aDc
 * 2-LCD1602 with I2C module video and code: https://youtu.be/q9YC_GVHy5A
 */
#include <MPU6050_tockn.h>
#include <Wire.h>

MPU6050 mpu6050(Wire);

#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 20 chars and 4 line display
LiquidCrystal_I2C lcd(0x27, 20, 4);

void setup() {
  Serial.begin(9600);
  Wire.begin();
  mpu6050.begin();
  mpu6050.calcGyroOffsets(false);

  // initialize the LCD, 
  lcd.begin();
  // Turn on the backlight and print a message.
  lcd.backlight();
  lcd.clear();
   lcd.setCursor (0,0); //
   lcd.print("Robojax MPU-6050"); 
   lcd.setCursor (0,1); //   
 
   lcd.print("Please Wait - 3");  
   lcd.setCursor (0,1); // 
   delay(1000);        
   lcd.print("Please Wait - 2");  
   delay(1000); 
   lcd.setCursor (0,1); //      
   lcd.print("Please Wait - 1");  
   delay(1000);       
}

void loop() {

  mpu6050.update();
  Serial.print("angleX : ");
  Serial.print(mpu6050.getAngleX());
  Serial.print("\tangleY : ");
  Serial.print(mpu6050.getAngleY());
  Serial.print("\tangleZ : ");
  Serial.println(mpu6050.getAngleZ());
  
  lcd.clear();// clearn previous values from screen
   lcdDisplay(
            mpu6050.getAngleX(), // send angle X
            mpu6050.getAngleY(), // send angle Y
            mpu6050.getAngleZ()  // send angle Z
            );                       
   delay(100);

}// loop end

/*
 * Written by Ahmad Shamshiri for Robojax.com
 * lcdDisplay(float x, float y, float z)
 * displays value and title on LCD2004-I2C display
 * How to use:
 * just pass the three values and it will display them.
 * lcdDisplay(mpu6050.getAngleX() , mpu6050.getAngleY() , mpu6050.getAngleZ() )
 */
void lcdDisplay(float x, float y, float z)
{
   // Robojax.com MPU6050 Demo with LCD2004-I2C Display
   lcd.setCursor (0,0); //
   lcd.print("Robojax MPU-6050");  
    
   lcd.setCursor (0,1); //character zero, line 1
   lcd.print("Angle X:");
   lcd.setCursor (9,1); //
   lcd.print(x);   
   
   lcd.setCursor (0,2); //character zero, line 2
   lcd.print("Angle Y:");
   lcd.setCursor (9,2); //
   lcd.print(y);

   lcd.setCursor (0,3); //character zero, line 3
   lcd.print("Angle Z:");
   lcd.setCursor (9,3); //
   lcd.print(z);   
 
}
120-Arduino code for the MPU-6050 accelerometer and gyroscope sensor (all data)
ভাষা: C++
/*
 * 
 * This code is basic usage of the MPU-6050 accelerometer and gyroscope.
 * 
 * This code displays data on the LCD2004 display based on
 * the option you set. See below.
 * 
 * 
 * Library and code have been taken from:
 * https://github.com/tockn/MPU6050_tockn
 * 
 * Updated by Ahmad Shamshiri on July 03, 2018 in Ajax, Ontario, Canada
 * for Robojax.com
 * Get this code from Robojax.com
 * Watch video instructions for this code at: https://youtu.be/ixe--SXemp8
 * 
 * You will need to watch two videos before following the instructions in this video:
 * 1-MPU6050 Introduction video and code: https://youtu.be/uhh7ik02aDc
 * 2-LCD1602 with I2C module video and code: https://youtu.be/q9YC_GVHy5A
 
 */
#include <MPU6050_tockn.h>
#include <Wire.h>

MPU6050 mpu6050(Wire);

long timer = 0;

#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 20 chars and 4 line display
LiquidCrystal_I2C lcd(0x27, 20, 4);

int typeSelect = 6;// select type . See below

String type[]={ "GyroAng and Ang",// select 0
                "GyroAng and Acc",// select 1
                "GyroAng and Gyro",// select 2
                "AccAng and Acc",// select 3
                "AccAng & Gyro",// select 4
                "AccAng and Ang",// select 5
                "Angle and Temp"// select 6
              };
              
void setup() {
  Serial.begin(9600);
  Wire.begin();
  mpu6050.begin();
  mpu6050.calcGyroOffsets(true);

  // initialize the LCD, 
  lcd.begin();
  // Turn on the backlight and print a message.
  lcd.backlight();    
}

void loop() {
  mpu6050.update();

  if(millis() - timer > 1000){
    
    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();
                        
     
  }// if
  lcd.clear();// clearn previous values from screen
  switch (typeSelect)
  {
    
  case 0:// display GyroAngle and Angle
   lcdDisplay(mpu6050.getGyroAngleX(),mpu6050.getGyroAngleY(),mpu6050.getGyroAngleZ(), 
             mpu6050.getAngleX(),mpu6050.getAngleY(),mpu6050.getAngleZ()                                
            );
   break;

  case 1:// display GyroAngle and Acceleration value
   lcdDisplay(mpu6050.getAngleX(),mpu6050.getAngleY(),mpu6050.getAngleZ(), 
             mpu6050.getAccX(),mpu6050.getAccY(),mpu6050.getAccZ()                                
            );
   break;  

  case 2:// display GyroAngle and Gyroscope value
   lcdDisplay(mpu6050.getAngleX(),mpu6050.getAngleY(),mpu6050.getAngleZ(), 
            mpu6050.getGyroX(),mpu6050.getGyroY(),mpu6050.getGyroZ()                                
            );
   break;

  case 3:// display Acceleration Angle and Acceleration value
   lcdDisplay(mpu6050.getAccAngleX(),mpu6050.getAccAngleY(),0.0, 
           mpu6050.getAccX(),mpu6050.getAccY(),mpu6050.getAccZ()                                
            );
   break; 

  case 4:// display Acceleration Angle and Gyro value
   lcdDisplay(mpu6050.getAccAngleX(),mpu6050.getAccAngleY(), 0.0, 
              mpu6050.getGyroX(),mpu6050.getGyroY(),mpu6050.getGyroZ()                                 
            );
   break;
   
  case 5:// display Acceleration Angle and Angle
   lcdDisplay(mpu6050.getAccAngleX(),mpu6050.getAccAngleY(), 0.0, 
           mpu6050.getAngleX(),mpu6050.getAngleY(),mpu6050.getAngleZ()                                   
            );
   break; 
   
  case 6:// display angle and Temperature
   lcdDisplay(mpu6050.getAngleX(),mpu6050.getAngleY(),mpu6050.getAngleZ(), 
           mpu6050.getTemp(), 0.0, 0.0                                 
            );
   break;                      
  }// switch end
    delay(100);
}// loop


/*
 * Written by Ahmad Shamshiri for Robojax.com
 * lcdDisplay(lcdDisplay(float x, float y, float z, float x1, float y1, float z1)
 * displays values and titles on the LCD2004-I2C display.
 * How to use:
 * just pass the 6 values and it will display them.
   lcdDisplay(mpu6050.getAccAngleX(),mpu6050.getAccAngleY(),mpu6050.getAccAngleZ(), 
           mpu6050.getAngleX(),mpu6050.getAngleY(),mpu6050.getAngleZ()                                   
            );
 */
void lcdDisplay(float x, float y, float z, float x1, float y1, float z1)
{
   // Robojax.com MPU6050 Demo with LCD2004-I2C Display
   lcd.setCursor (0,0); //
   lcd.print(type[typeSelect]);  
   lcd.setCursor (17,0); //
   String dis = "("+String(typeSelect)+")";
   lcd.print(dis);    

    if(typeSelect !=6){
   lcd.setCursor (0,1); //character zero, line 1
   lcd.print("X:");
   lcd.setCursor (2,1); //
   lcd.print(x);  
   /////////////////////
   lcd.setCursor (10,1); //character zero, line 1
   lcd.print("X1:");
   lcd.setCursor (13,1); //
   lcd.print(x1);       
   
   lcd.setCursor (0,2); //character zero, line 2
   lcd.print("Y:");
   lcd.setCursor (2,2); //
   lcd.print(y);
   ////////////////////////
   lcd.setCursor (10,2); //character zero, line 1
   lcd.print("Y1:");
   lcd.setCursor (13,2); //
   lcd.print(y1);   
   

   lcd.setCursor (0,3); //character zero, line 3
   lcd.print("Z:");
   lcd.setCursor (2,3); //
   lcd.print(z);   
   //////////////////////
   lcd.setCursor (10,3); //character zero, line 3
   lcd.print("Z1:");
   lcd.setCursor (13,3); //
   lcd.print(z1);   
    }else{
   lcd.setCursor (0,1); //character zero, line 1
   lcd.print("X:");
   lcd.setCursor (2,1); //
   lcd.print(x);  
   /////////////////////
   lcd.setCursor (10,1); //character zero, line 1
   lcd.print("TMP: ");
   lcd.setCursor (15,1); //
   lcd.print(x1);       
   
   lcd.setCursor (0,2); //character zero, line 2
   lcd.print("Y:");
   lcd.setCursor (2,2); //
   lcd.print(y); 
   

   lcd.setCursor (0,3); //character zero, line 3
   lcd.print("Z:");
   lcd.setCursor (2,3); //
   lcd.print(z);   

  
    }
 
}

সম্পদ ও রেফারেন্সসমূহ

ফাইলসমূহ📁

আর্ডুইনো লাইব্রেরি (জিপ)

ফ্রিটজিং ফাইল

অন্যান্য ফাইলগুলি

  • LCD1602 LiquidCrystal Library
    robojax-LCD1602_LiquidCrystal.zip
  • MPU6050_tockn-master
    Arduino library for the MPU6050 accelerometer and gyroscope module. Provides functions to read acceleration, gyro, and temperature data, with calibration and angle calculation. Designed for easy integration into motion-sensing projects.
    robojax-MPU6050_tockn-master.zip