LCD 1602 અથવા LCD2004 પર MPU-6050 સેન્સર ડેટા દર્શાવવું Arduino સાથે
આ ટ્યુટોરિયલમાં, આપણે શીખીશું કે કેવી રીતે MPU-6050 સેન્સરમાંથી ડેટાને LCD 1602 અથવા LCD2004 પર Arduino નો ઉપયોગ કરીને પ્રદર્શિત કરવો. 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 |
| લોજિક/IO વોલ્ટેજ | 3.3 V / 5 V |
| સપ્લાય વોલ્ટેજ | 3.3 V થી 5 V |
| આઉટપુટ ડેટા દર | 1 kHz (મહત્તમ) |
| તાપમાન શ્રેણી | -40 થી +85 °C |
| પેકેજ | QFN |
| નોંધો / વેરિઅન્ટ્સ | ગાયરોસ્કોપ અને એક્સેલરોમીટર સંકલિત |
- નિર્દિષ્ટ વોલ્ટેજ શ્રેણીમાં યોગ્ય પાવર સપ્લાયની ખાતરી કરો.
- જરૂર પડે તો I2C લાઇનો પર પુલ-અપ રેઝિસ્ટરનો ઉપયોગ કરો.
- તમારા સેટઅપ સાથે સુસંગતતા માટે I2C સરનામું તપાસો.
- ચોક્કસ રીડિંગ્સ માટે સેન્સરને કેલિબ્રેટ કરો.
- શોર્ટ સર્કિટ ટાળવા માટે વાયરિંગમાં સાવધાની રાખો.
વાયરિંગ સૂચનાઓ

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 પર મૂલ્યોનું નિરીક્ષણ કરવાથી તમે જોઈ શકશો કે સેન્સર ગતિ અને દિશા ફેરફારોને કેવી રીતે પ્રતિસાદ આપે છે. જો મૂલ્યો સ્થિર અથવા ખોટા લાગે છે, તો જોડાણો ચકાસો અને ખાતરી કરો કે સેન્સર યોગ્ય રીતે કાર્ય કરી રહ્યું છે.
/*
*
* 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);
}
/*
*
* 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);
}
}
સંસાધનો અને સંદર્ભો
-
બાહ્યGet the library from GitHubgithub.com
-
બાહ્યManufacturer websiteinvensense.com
ફાઇલો📁
Arduino લાઇબ્રેરીઓ (zip)
-
Arduino library for MPU9250
robojax-MPU9250-master.zip3.38 MB
Fritzing ફાઇલ
-
LCD LCD1602-I2C module with 4 wires
LCD1602-I2C.fzpz0.01 MB -
MPU-6050 Board GY-521
MPU-6050 Board GY-521.fzpz0.01 MB -
LCD2004-I2C
LCD2004-I2C.fzpz0.02 MB
અન્ય ફાઇલો
-
LCD1602 LiquidCrystal Library
robojax-LCD1602_LiquidCrystal.zip -
MPU6050_tockn-masterArduino 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