Hi new to this forum so I’m hoping I post this question in the right area. Im a beginner but trying to learn.
Currently working on a few projects for a animatronic cosplay. Main issue I’m having is for a shoulder mounted turret tracker.
I’m using a mpu 6050 module, arduino/elegoo uno and x2 cheap servor motors (sg90) So far I succesfully got the turret moving as the mpu moves. But the problem is that the z axis of the module has no effect on movement of the turret.
Bascialy I wasnt the servo motor to move when I move the module in the yaw/z axis as well as the pitch/y axis
I can move front/back (pitch) and angle sideways (roll) but not the yaw.
I was told to get a 9250 as they perform better, so I got one. I was able to use the same script and still have the turret moving but not for the yaw.
Here is the script im using
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"
#include "Servo.h"
MPU6050 mpu;
int16_t ax, ay, az;
int16_t gx, gy, gz;
Servo servo1;
Servo servo2;
int val1;
int val2;
int prevVal1;
int prevVal2;
void setup()
{
Wire.begin();
Serial.begin(38400);
Serial.println("Initialize MPU");
mpu.initialize();
Serial.println(mpu.testConnection() ? "Connected" : "Connection failed");
servo1.attach(9);
servo2.attach(10);
}
void loop()
{
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
val1 = map(ax, -17000, 17000, 0, 179);
if (val1 != prevVal1)
{
servo1.write(val1);
prevVal1 = val1;
}
val2 = map(ay, -17000, 17000, 0, 179);
if (val2 != prevVal2)
{
servo2.write(val2);
prevVal2 = val2;
}
delay(50);
}
The attachement shows my set up.
+AOD of mpu 6050 is connected to ground on the arduino uno to have it on I2C address 0x69.
Ive seen videos where few people succesfuly had the yaw move whilst using mpu 6050 and can’t seem to recreate it.
Im not sure if I need a completely different script or if I need to change some values of the current script
Let me know if you need more info in what I’m trying to do. A lot of this is new to me but Im trying to learn. I would really appreciate for any help. Thank You