Mpu6050 and Servo

Hello, i need a program that can controll 3 servoes using mpu6050. I need that the 3 gyroscope axis equal to the angle of the servoes. I have tried to do this but after a while the servoes stop and don't move anymore.

#include <MPU6050_light.h>
#include"Wire.h"
#include <Servo.h>

Servo servo1;
Servo servo2;
MPU6050 mpu(Wire);
unsigned long timer = 0;

int x, y, z;

void setup() {
  Serial.begin(9600);
  Wire.begin();

  byte status = mpu.begin();
  mpu.calcOffsets();

  servo1.attach(5);
  servo2.attach(6);

}




void loop() {
  mpu.update();



  x = mpu.getAngleX();
  y = mpu.getAngleY();
  z = mpu.getAngleZ();

  timer = millis();

  servo1.write(x);
  servo2.write(z);


}

please read How to get the best out of this forum

could you provide documentation of your ask: what type of Servos, how they are powered, circuit etc..?

1 Like

Won't these angles be in radians?

i use sg90 servoes powered by 5v

i actually do not need 3 servoes, i need one for the pitch and one for the yaw (not roll)

Those 9V batteries are really not fit for that purpose.
get something that can really provide enough Amps without collapsing

1 Like

like what?

Like four AA cells

Like 4 x AA NiMH rechargeable batteries (e.g. Eneloops). And connect them direct to the servos. It's never a good idea to power servos from the Arduino 5V pin.

Why not put some Serial prints in so you can see what you're actually writing to the servos?

Steve

i need it very compact so i don't know if i can use 4 aa batteries..

So use four AAAs

how many?

See reply #10

ok so i will try to use 4 AAA batteries for power the servoes and i will also try to get the data from the serial monitor to see what is going to be written on the servo

if i power the mpu with 3.3v and the servoes with 6v (4 AAA batteries) can change something?

I solved the problem: I just used a different library for the MPU6050. Thanks everyone for the support :slight_smile:

Share the link to the library that worked - that could help someone else

I used this library:

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