Smooth servo movements

Hey guys,

I made a Gimbal (camera stabilizer) with an Arduino Uno and MPU6050 gyro sensor. I read the values from the MPU6050 and write it to the servos. The values are really exact so I get every movement. The values go from 0 to 180 so we can write them on the servo directly. My problem is that I get values like 83, 91, 85 so it's always moving forward and backwards and because of this it's very instable. Anyone got an idea how to make it move smoother?


For the accelerator: Use a filer. Either the Kalman filter or the i2cdev library. For the stepper motor : The accelstepper library speeds up smooth.


Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7,148850.0.html

Tom… :slight_smile:

I’ll try this thanks!

Here’s the code

#include <Servo.h> 
const int MPU=0x68;  // I2C address vom MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
Servo myservo;

int pos, distance;

int i=0;

void setup(){
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // 0 setzen, sleep mode vom sensor wird deaktiviert
  pinMode(13, OUTPUT);
//  myservoX.attach(8);

void loop(){
  Wire.write(0x3B);  // mit 0x3B register beginnen(ACCEL_XOUT_H)
  Wire.requestFrom(MPU,14,true);<<8|;  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)<<8|;  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)

  pos = (AcY/200)+85;

  if(pos <1){
    pos = 1;
    distance = pos -90;
    pos = 90-distance;
  else if(pos <90){
   distance = 90-pos;
   pos = 90 + distance; 




That won't work. Every accelerometer is noisy. I suggest to start with the Kalman Guide.

You have to understand how to build a 6-DoF IMU from 3-axis gyro and accelerometer first - this is a requirement for orientation feedback. Accelerometer by itself is almost useless, and gyro output drifts. The accelerometer is purely used to eliminate the drift, not give orientation directly in the short term.

Since you have a 6050 you can just get the quarternion out of it directly surely?