Please help me to make the servos go to the opposite direction to the tilt direction of the gyro
I used-arduino nano
Mpu 6050 gyro
2 9g servos
here is my code
#include <Wire.h>
#include <Servo.h>
const int MPU=0x68; // I2C address of the MPU-6050
int16_t GyX, GyY; //Variabile int a 16bit
Servo ServoMot_X;
Servo ServoMot_Y;
void setup(){
Wire.begin();
Wire.beginTransmission(MPU);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
ServoMot_X.attach(8);
ServoMot_Y.attach(9);
Serial.begin(9600);
}
void loop(){
Wire.beginTransmission(MPU);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU,14,true); // request a total of 14 registers
GyX=Wire.read()<<8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
GyY=Wire.read()<<8|Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
int PosServo_X = map(GyX, -16000, 16000, 0, 179);
int PosServo_Y = map(GyY, -16000, 16000, 0, 179);
ServoMot_X.write(PosServo_X);
ServoMot_Y.write(PosServo_Y);
Serial.println("Giroscopio");
Serial.print("Asse X : "); Serial.println(PosServo_X);
Serial.print("Asse Y : "); Serial.println(PosServo_Y);
Serial.println(" ");
delay(100);
}
jremington:
How have you wired things up and what happens when you try to run the code?
IT WORKS FINE WHEN I TILT GYRO LEFT SERVO TURNS RIGHT WHEN I TILT GYRO RIGHT SERVO TUNS RIGHT
I NEED TO MAKE THIS EXACTLY OPPOSITE.I HAVE USE X AND Y AXIS PLEASE HELP ME TO MAKE IT RUNNING OPPOSITE
(please take off your CAPS LOCK - it looks like you're SHOUTING at us)
i m really sorry about that i thought typing it in capital would be just fine and neat really sorry about that please show me a way or a code to make this go opposite