અર્ડુઇનો કોડ MPU-6050 માટે LCD1602 I2C ડિસ્પ્લે સાથે
આ ટ્યુટોરિયલમાં, આપણે MPU-6050 એક્સેલેરોમીટર અને જાયરોસ્કોપને I2C સંચારનો ઉપયોગ કરીને LCD1602 ડિસ્પ્લે સાથે કેવી રીતે જોડવું તે શીખીશું. MPU-6050 કોણ માપન પ્રદાન કરશે જે LCD પર દર્શાવવામાં આવશે. આ પ્રોજેક્ટ તમને MPU-6050 ના ખૂણાઓને રીઅલ-ટાઇમમાં જોવામાં મદદ કરશે, જે સેન્સર ડેટા અને ડિસ્પ્લે ઇન્ટરફેસિંગની તમારી સમજને વધારશે.


આ ટ્યુટોરિયલના અંત સુધીમાં, તમારી પાસે એક કાર્યકારી સેટઅપ હશે જે LCD સ્ક્રીન પર X, Y અને Z ખૂણાઓ દર્શાવે છે. આર્ડુઇનો પ્રોજેક્ટ્સમાં સેન્સર ડેટા અને ડિસ્પ્લે ટેકનોલોજી સાથે હાથથી અનુભવ મેળવવાનો આ એક શ્રેષ્ઠ માર્ગ છે. વધુ સ્પષ્ટતા માટે, (વિડિયોમાં 00:00 પર) વિડિયો જોવાનું ભૂલશો નહીં.
હાર્ડવેર સમજાવ્યું
આ પ્રોજેક્ટના મુખ્ય ઘટકો MPU-6050 સેન્સર અને LCD1602 ડિસ્પ્લે મોડ્યુલ છે. MPU-6050 એક બહુમુખી સેન્સર છે જે 3-અક્ષ એક્સેલેરોમીટર અને 3-અક્ષ જાયરોસ્કોપને જોડે છે, જે રીઅલ-ટાઇમ કોણ માપન પ્રદાન કરે છે. તે I2C પર સંચાર કરે છે, જે આર્ડુઇનો સાથે સીમલેસ એકીકરણની મંજૂરી આપે છે.
LCD1602 ડિસ્પ્લે પણ I2C પ્રોટોકોલનો ઉપયોગ કરે છે, જે વાયરિંગને સરળ બનાવે છે અને સંચાર માટે જરૂરી પિનની સંખ્યા ઘટાડે છે. I2C ઇન્ટરફેસ બહુવિધ ઉપકરણોને સમાન બસ પર કનેક્ટ કરવાની મંજૂરી આપે છે, જે બહુવિધ સેન્સર અથવા ઘટકો ધરાવતા પ્રોજેક્ટ્સ માટે કાર્યક્ષમ બનાવે છે.
ડેટાશીટ વિગતો
| ઉત્પાદક | ઇનવેન્સેન્સ |
|---|---|
| ભાગ નંબર | MPU-6050 |
| લોજિક/IO વોલ્ટેજ | 3.3 V / 5 V |
| સપ્લાય વોલ્ટેજ | 3.3 V થી 5 V |
| આઉટપુટ ડેટા દર | 1 kHz (મહત્તમ) |
| જાયરોસ્કોપ રેન્જ | ±250, ±500, ±1000, ±2000 °/s |
| એક્સેલેરોમીટર રેન્જ | ±2g, ±4g, ±8g, ±16g |
| પેકેજ | QFN |
| નોંધો / વેરિઅન્ટ્સ | ડિજિટલ મોશન પ્રોસેસર (DMP) શામેલ છે |
- I2C સરનામું તપાસો (ડિફોલ્ટ 0x68 છે).
- યોગ્ય પાવર સપ્લાય વોલ્ટેજ (3.3 V અથવા 5 V) ની ખાતરી કરો.
- જો બોર્ડ પર પહેલેથી ન હોય તો SDA અને SCL લાઇનો માટે પુલ-અપ રેઝિસ્ટરનો ઉપયોગ કરો.
- સ્થિરતા માટે પાવર પિન નજીક ડિકપ્લિંગ કેપેસિટરનો ઉપયોગ કરવાનું વિચારો.
- સંચાર સમસ્યાઓ ટાળવા માટે વાયરિંગ જોડાણો ચકાસો.
વાયરિંગ સૂચનાઓ

MPU-6050 અને LCD1602 ડિસ્પ્લેને તમારા આર્ડુઇનો સાથે જોડવા માટે, આ જોડાણોને અનુસરો:
- MPU-6050 ના
VCCપિનને આર્ડુઇનો પરના5Vપિન સાથે જોડો. - MPU-6050 ના
GNDપિનને આર્ડુઇનો પરનાGNDપિન સાથે જોડો. - MPU-6050 ના
SDAપિનને આર્ડુઇનો પરનાA4પિન સાથે જોડો. - MPU-6050 ના
SCLપિનને આર્ડુઇનો પરનાA5પિન સાથે જોડો. - LCD1602 ડિસ્પ્લે માટે,
VCCપિનને આર્ડુઇનો પરના5Vસાથે જોડો. - LCD1602 ના
GNDપિનને આર્ડુઇનો પરનાGNDપિન સાથે જોડો. - LCD1602 ના
SDAપિનને MPU-6050 માટે વપરાયેલા સમાનA4પિન સાથે જોડો. - LCD1602 ના
SCLપિનને MPU-6050 માટે વપરાયેલા સમાનA5પિન સાથે જોડો.
તમારા જોડાણોને બે વાર તપાસવાનું સુનિશ્ચિત કરો, કારણ કે ખોટું વાયરિંગ ઉપકરણની ખામી અથવા યોગ્ય રીતે સંચાર કરવામાં નિષ્ફળતા તરફ દોરી શકે છે.
કોડ ઉદાહરણો અને વોકથ્રુ
કોડ MPU-6050 અને LCD ડિસ્પ્લે માટે જરૂરી લાઇબ્રેરીઓ શામેલ કરીને શરૂ થાય છે. નીચેનો અંશ બતાવે છે કે MPU-6050 ને કેવી રીતે પ્રારંભ કરવું:
MPU6050 mpu6050(Wire);
અહીં, આપણે MPU6050 ઑબ્જેક્ટ બનાવીએ છીએ, જેનો ઉપયોગ સેન્સરમાંથી ડેટા વાંચવા માટે થશે. આગળ, આપણે setup() ફંક્શનમાં ઉપકરણ સેટ કરવાની જરૂર છે:
void setup() {
Serial.begin(9600);
Wire.begin();
mpu6050.begin();
mpu6050.calcGyroOffsets(true);
lcd.begin();
lcd.backlight();
}
આ કોડ સીરિયલ સંચાર, I2C બસ અને MPU-6050 સેન્સરને પ્રારંભ કરે છે. તે LCD ને પણ પ્રારંભ કરે છે અને તેની બેકલાઇટ ચાલુ કરે છે. લૂપમાં ખૂણાઓને અપડેટ અને દર્શાવવાનો તર્ક શામેલ છે:
void loop() {
mpu6050.update();
lcd.clear();
lcdDisplay(0, 0, "X:", 2, 0, mpu6050.getAngleX());
lcdDisplay(13, 0, "Y:", 0, 1, mpu6050.getAngleY());
lcdDisplay(7, 1, "Z:", 9, 1, mpu6050.getAngleZ());
delay(100);
}
આ લૂપમાં, X, Y અને Z માટેના ખૂણાઓ અપડેટ થાય છે અને LCD પર દર્શાવવામાં આવે છે. આઉટપુટને યોગ્ય રીતે ફોર્મેટ કરવા માટે lcdDisplay() ફંક્શનનો ઉપયોગ થાય છે. તમે લેખની નીચે લોડ કરેલો સંપૂર્ણ કોડ શોધી શકો છો.
પ્રદર્શન / શું અપેક્ષા રાખવી
જ્યારે સેટઅપ પૂર્ણ થાય અને કોડ અપલોડ થાય, ત્યારે તમારે X, Y અને Z માટેના ખૂણાઓ LCD પર રીઅલ-ટાઇમમાં દર્શાવેલા જોવા જોઈએ. જો બધું યોગ્ય રીતે વાયર કરેલું હોય, તો ડિસ્પ્લે દર 100 મિલિસેકન્ડે રિફ્રેશ થશે, જે MPU-6050 ની વર્તમાન દિશા દર્શાવે છે.
સામાન્ય મુશ્કેલીઓમાં I2C જોડાણો યોગ્ય છે તેની ખાતરી કરવી અને પાવર સપ્લાય સ્થિર છે તેની ખાતરી કરવી શામેલ છે. જો MPU-6050 યોગ્ય રીતે પ્રારંભ ન થાય, તો તમે LCD પર ખોટો અથવા કોઈ ડેટા જોઈ શકો છો (વિડિયોમાં 01:15 પર).
/*
*
* 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 LCD1602-I2C display module.
*
* Library and code have been taken from:
* https://github.com/tockn/MPU6050_tockn
*
* Updated by Ahmad Shamshiri on July 05, 2018 at 22:19 in Ajax, Ontario, Canada
* for Robojax.com
* Get this code from Robojax.com
* Watch video instructions for this code at: https://youtu.be/uIz6WIis4dc
*
* 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 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
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();
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(
// to print X:
0, // character 0
0, // line 0
"X:",
// to print AngleX
2, // character 2
0, // line 0
mpu6050.getAngleX()
);
lcdDisplay(
// to print Y:
13, // character 13
0, // line 0
"Y:",
// to print AngleY
0, // character 0
1, // line 1
mpu6050.getAngleY()
);
lcdDisplay(
// to print Z:
7, // character 7
1, // line 1
"Z:",
// to print AngleZ
9, // character 9
1, // line 0
mpu6050.getAngleZ()
);
delay(100);
}// loop end
/*
* lcdDisplay(int tc, int tr, String title, int vc, int vr, float value)
* displays value and title on LCD1602
* How to use:
* If you want to display: "Voltage: 13.56mV" starting from the first character
* on the second row.
* use:
* lcdDisplay(0, 1, "Voltage: ", 13.56)
*
* tc is the character number (0)
* tr is the row number in the LCD (1)
* title is the text ("Voltage:")
* vc is the character number for the value
* vr is the row number for the value
* value is the value (13.56)
*/
void lcdDisplay(int tc, int tr, String title, int vc, int vr, float value)
{
// Robojax.com MPU6050 Demo
lcd.setCursor (tc,tr); //
lcd.print(title);
lcd.setCursor (vc,vr); //
lcd.print(value);
}
Things you might need
-
AmazonPurchase LCD1602-I2C from Amazonamzn.to
-
AmazonPurchase MPU-6050 from Amazonamzn.to
-
eBayPurchase LCD1602-I2C from eBayebay.us
-
AliExpressPurchase 10pcs LCD1602-I2C from AliExpresss.click.aliexpress.com
Resources & references
-
ExternalManufacturer websiteinvensense.com
Files📁
Arduino Libraries (zip)
-
LCD1602 LCD Arduino library from Robojax
robojax-LCD1602-I2C-library-master.zip0.01 MB -
Arduino library for MPU9250
robojax-MPU9250-master.zip3.38 MB
Fritzing File
-
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
Other files
-
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