In my project I am using mpu6050,servo motor,I2c LCD,and Arduino UNO
the prototype works just fine but the problem is with the LCD it doesn't display anything at all,
how can I fix it? thanks
#include <Servo.h> //Include Servo Motor library for using Servo
#include <LiquidCrystal_I2C.h> //Include LCD library for using LCD
#include <Wire.h> //Include WIre library for using I2C
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;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup()
{
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
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.print("CIRCUIT DIGEST");
delay(1000);
lcd.clear();
lcd.setCursor(3,0);
lcd.print("Arduino");
lcd.setCursor(2,1);
lcd.print("MPU6050");
delay(3000);
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(1,0);
lcd.print("Angle");
lcd.setCursor(2,1);
lcd.print(x);
delay(500);
lcd.clear();
}