Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem to get constant reading from MPU6050 sensor using esp32 when sensor is static position

Naznee

Newbie level 6
Joined
Mar 21, 2024
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
89
Hello
I am with a problem that I am using mpu6050 sensor with esp32 .I have tried many libraries many codes to get right reading from the sensor . when the sensor is static accX,accY,accZ
should be 0,0,0 respectively and gyroX, gyroY, gyroZ should be 0,0,9.8 . but I am getting some values and it's constantly change without any movement . so can anyone help me to calibrate my sensor according to the error.

as I said before that I have used many tutorials .there are some link of them:-
Link 1
Link2
Link3
Link4
link4
link5
link5

I don't have a code because I have tried many codes the nearest and fine code is below

C:
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>

Adafruit_MPU6050 mpu;

void setup(void) {
  Serial.begin(115200);
  while (!Serial)
    delay(10); // will pause Zero, Leonardo, etc until serial console opens

  Serial.println("Adafruit MPU6050 test!");

  // Try to initialize!
  if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050 chip");
    while (1) {
      delay(10);
    }
  }
  Serial.println("MPU6050 Found!");

  mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
  Serial.print("Accelerometer range set to: ");
  switch (mpu.getAccelerometerRange()) {
  case MPU6050_RANGE_2_G:
    Serial.println("+-2G");
    break;
  case MPU6050_RANGE_4_G:
    Serial.println("+-4G");
    break;
  case MPU6050_RANGE_8_G:
    Serial.println("+-8G");
    break;
  case MPU6050_RANGE_16_G:
    Serial.println("+-16G");
    break;
  }
  mpu.setGyroRange(MPU6050_RANGE_500_DEG);
  Serial.print("Gyro range set to: ");
  switch (mpu.getGyroRange()) {
  case MPU6050_RANGE_250_DEG:
    Serial.println("+- 250 deg/s");
    break;
  case MPU6050_RANGE_500_DEG:
    Serial.println("+- 500 deg/s");
    break;
  case MPU6050_RANGE_1000_DEG:
    Serial.println("+- 1000 deg/s");
    break;
  case MPU6050_RANGE_2000_DEG:
    Serial.println("+- 2000 deg/s");
    break;
  }

  mpu.setFilterBandwidth(MPU6050_BAND_5_HZ);
  Serial.print("Filter bandwidth set to: ");
  switch (mpu.getFilterBandwidth()) {
  case MPU6050_BAND_260_HZ:
    Serial.println("260 Hz");
    break;
  case MPU6050_BAND_184_HZ:
    Serial.println("184 Hz");
    break;
  case MPU6050_BAND_94_HZ:
    Serial.println("94 Hz");
    break;
  case MPU6050_BAND_44_HZ:
    Serial.println("44 Hz");
    break;
  case MPU6050_BAND_21_HZ:
    Serial.println("21 Hz");
    break;
  case MPU6050_BAND_10_HZ:
    Serial.println("10 Hz");
    break;
  case MPU6050_BAND_5_HZ:
    Serial.println("5 Hz");
    break;
  }

  Serial.println("");
  delay(100);
}

void loop() {
  /* Get new sensor events with the readings */
  sensors_event_t a, g, temp;
  mpu.getEvent(&a, &g, &temp);

  /* Print out the values */
  Serial.print("Acceleration X: ");
  Serial.print(a.acceleration.x);
  Serial.print(", Y: ");
  Serial.print(a.acceleration.y);
  Serial.print(", Z: ");
  Serial.print(a.acceleration.z);
  Serial.println(" m/s^2");

  Serial.print("Rotation X: ");
  Serial.print(g.gyro.x);
  Serial.print(", Y: ");
  Serial.print(g.gyro.y);
  Serial.print(", Z: ");
  Serial.print(g.gyro.z);
  Serial.println(" rad/s");

  Serial.print("Temperature: ");
  Serial.print(temp.temperature);
  Serial.println(" degC");

  Serial.println("");
  delay(500);
}
somebody help me to solve the problem
 
Last edited:
accX,accY,accZ should be 0,0,0 respectively and gyroX, gyroY, gyroZ should be 0,0,9.8
No. You'd expect accZ of 1 g (9.81 m/s²), all other measurements around 0. If you see something completely deifferent, there's probably a serious problem with your code.
 
No. You'd expect accZ of 1 g (9.81 m/s²), all other measurements around 0. If you see something completely different, there's probably a serious problem with your code.
No, I don't get these value but values should be these values when we doesn't move the sensor
Acceleration X: -1.24, Y: 0.28, Z: 10.38 m/s^2
Rotation X: -0.01, Y: 0.02, Z: 0.00 rad/s
Temperature: 34.23 degC
this is my output when sensor is in static position
 
Hi,

Did you read the MPU6050 datasheet and did you follow all informations?

Show your wiring diagram.
Show a photo of your complete test circuit (100kBytes should be sufficient)
Show the numbers you get in a list of several concurrent measurements.

Turn the sensor upside down then again show the results.

Klaus
 
I don't think those numbers are that bad, and look to
sum to roughly 9.8; maybe "dead straight vertical" is
just not where you think it is. I've made encased
accelerometer instruments which were "on plane"
and ones which were a bit off.

Probably in your software you need to be figuring
vector sums and using that, along with some kind of
baselining to get the reading that you will report all
else relative, to.

Like when I was doing hot rod data logging for tuning,
I would take out the intial at-rest reading in Excel
before plotting acceleration to true up the data sets.
 

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top