Angle between 30 and 60 by mpu6050

hello

i want to make programe to measure angle by mpu6050 between 30 and 60 angle range

please need guide

Keep it simple and stupid firstly.
Follow the example code that comes with the library or
run some tutorials for the hardware selected.
If you are happy with the results of the tutorials you can merge these to your project.

Have a nice day and enjoy coding in C++.

What accuracy do you need?
1 degree, 1/2 degree, etc.

1 Like

1 degree will be more perfect

Not possible with the mpu6050
I would use an optical encoder connected to the pivot shaft

so mpu do not measure angle in range ?

No idea why you would want to use that chip, given it is not only end of life, but not suited to the application you are asking about.

The optical encoder will give you repeated accuracy with a lot easier way of coding.

WHAT parameters should i see in mechanism while chosing encoder

Lots of different types although it all depends on the application you are wanting it for.

The load on any encoder and the speed at which you want to move the encoder at, are of course parameters you should specify.

Is it a direct connection or are you having it geared?

1 Like

the link moving between 30 and 60 angle in software, so i have to see that angle by using arduino

The accelerometer is not accurate enough to provide 1 degree of accuracy.

The encoder should be able to operate with 5V and have a PPR (Pulses Per Revolution) specification of 360 or higher.

1 Like

Use a potentiometer.

1 Like
// minimal MPU-6050 tilt and roll (sjr). Works with MPU-9250 too.
// works perfectly with GY-521, pitch and roll signs agree with arrows on sensor module 7/2019
//
// Tested with 3.3V eBay Pro Mini with no external pullups on I2C bus (worked with internal pullups)
// Add 4.7K pullup resistors to 3.3V if required. A4 = SDA, A5 = SCL

#include<Wire.h>
const int MPU_addr1 = 0x68;
float xa, ya, za, roll, pitch;

void setup() {

  Wire.begin();                                      //begin the wire communication
  Wire.beginTransmission(MPU_addr1);                 //begin, send the slave adress (in this case 68)
  Wire.write(0x6B);                                  //make the reset (place a 0 into the 6B register)
  Wire.write(0);
  Wire.endTransmission(true);                        //end the transmission
  Serial.begin(9600);
}

void loop() {

  Wire.beginTransmission(MPU_addr1);
  Wire.write(0x3B);  //send starting register address, accelerometer high byte
  Wire.endTransmission(false); //restart for read
  Wire.requestFrom(MPU_addr1, 6); //get six bytes accelerometer data
  int t = Wire.read();
  xa = (t << 8) | Wire.read();
  t = Wire.read();
  ya = (t << 8) | Wire.read();
  t = Wire.read();
  za = (t << 8) | Wire.read();
// formula from https://wiki.dfrobot.com/How_to_Use_a_Three-Axis_Accelerometer_for_Tilt_Sensing
  roll = atan2(ya , za) * 180.0 / PI;
  pitch = atan2(-xa , sqrt(ya * ya + za * za)) * 180.0 / PI; //account for roll already applied

  Serial.print("roll = ");
  Serial.print(roll,1);
  Serial.print(", pitch = ");
  Serial.println(pitch,1);
  delay(400);
}

1 Like

thank you for sharing so this is general code to measure angles in range?

Use the code to measure tilt and roll angles up to, but not including, +/-90 degrees.

1 Like

No idea why you are trying to use this device to measure an angle.

Can you say why you want to use this device?

I can't speak for the OP, but accelerometers are very commonly used to measure tilt angles, and are essential components of 9DOF IMUs for estimating 3D orientation. They are used in every drone for flight stabilization.

1 Like

comparing angles between application in software and real model testing

I realise this, but the reason is the OP asked a specific question about measuring between two angles, something that I personally would use a shaft encoder for.

There are of course draw backs in using a mems device in an application that may or may not be suitable and given this is now an eol device I was just curious as to why it was chosen.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.