GY-80 Gyro sensor kalman filter

Hi all, i am trying to get the data from Yaw rotation with kalman filter and my coding does not giving the correct result to me, which is when i rotate to yaw and the angle in the serial monitor is NOT respond
BUT when i move to Pitch rotation the result in Yaw is responded.

my question is how to correct the coding that is have in order for me to get the result when rotate in YAW.

my Coding

#include <Wire.h>
#include <L3G4200D.h>
#include <ADXL345.h>
#include <KalmanFilter.h>

L3G4200D gyroscope;
ADXL345 accelerometer;

KalmanFilter kalmanX(0.001, 0.003, 0.03);
KalmanFilter kalmanY(0.001, 0.003, 0.03);
KalmanFilter kalmanZ(0.001, 0.003, 0.03);

float accPitch = 0;
float accRoll = 0;
float accYaw = 0;

float kalPitch = 0;
float kalRoll = 0;
float kalYaw = 0;
int red = 6;

void setup()
{
Serial.begin(115200);
pinMode(red, OUTPUT);

// Initialize ADXL345
while(!accelerometer.begin())
{
delay(500);
}

accelerometer.setRange(ADXL345_RANGE_2G);

// Initialize L3G4200D
while(!gyroscope.begin(L3G4200D_SCALE_2000DPS, L3G4200D_DATARATE_400HZ_50))
{
delay(500);
}

// Calibrate gyroscope. The calibration must be at rest.
// If you don't want calibrate, comment this line.
gyroscope.calibrate(100);
}
void loop()
{
data();
led();

}
void data()
{
Vector acc = accelerometer.readNormalize();
Vector gyr = gyroscope.readNormalize();

// Calculate Pitch & Roll from accelerometer (deg)
accPitch = -(atan2(acc.XAxis, sqrt(acc.YAxisacc.YAxis + acc.ZAxisacc.ZAxis))180.0)/M_PI;
accRoll = (atan2(acc.YAxis, acc.ZAxis)180.0)/M_PI;
accYaw = 180 * atan (acc.ZAxis/sqrt(acc.XAxis
acc.XAxis + acc.ZAxis
acc.ZAxis))/M_PI;

// Kalman filter
kalPitch = kalmanY.update(accPitch, gyr.YAxis);
kalRoll = kalmanX.update(accRoll, gyr.XAxis);
kalYaw = kalmanZ.update(accYaw, gyr.ZAxis);

Serial.print(accPitch);
Serial.print(":");
Serial.print(accRoll);
Serial.print(":");
Serial.print(kalPitch);
Serial.print(":");
Serial.print(kalRoll);
Serial.print(":");
Serial.print(kalYaw);

Serial.println();
}
void led()
{
if (kalYaw >= -180 && kalYaw <=-20)
{digitalWrite(red, HIGH);
}

else {digitalWrite (red,LOW);
}
}

kalman___led.ino (1.78 KB)

Always use code tags when posting ("</>" button).

An accelerometer cannot be used to measure yaw, only pitch and roll. You need a magnetometer to measure yaw.

A Kalman filter combines data sources and reduces noise, it does not measure anything. If you are using the code from TKJElectronics, don't. It is not even a Kalman filter, and does not work properly.

Thanks for reply

anyone know how to correct yaw drifting problem?
please Help

Use a magnetometer.

First Thanks for the suggestion

Do you have any coding reference for GY-80 sensor magnetometer yaw drifting correction.

Is Google broken today?

Do you have any coding reference for GY-80 sensor magnetometer yaw drifting correction.

See reply #1. This is not a simple process.

What you want is an AHRS (Attitude and Heading Reference System). By far the best open source example for Arduino is RTIMUlib.