gy-801 3 servo motor control

two servo motors turning the x and y position.

However, the GY-801 does not rotate when the third motor rotate around its axis.

How do I run the third engine on its axis, so when I return in the GY-801 Z-axis.

Arduino Digital SDA 20 = GY-801 SDA
Arduino Digital SCL 21 = GY-801 SCL
Arduino VCC = GY-801 VCC_IN
Arduino GND = GY-801 GND

Servo Motors
Digital 9, 10, 11

Arduino Code

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

#include <Servo.h>

Servo servo1;  // create servo object to control a servo
Servo servo2;
Servo servo3;

ADXL345 adxl; //variable adxl is an instance of the ADXL345 library

int x, y, z;
int rawX, rawY, rawZ;
int mappedRawX, mappedRawY, mappedRawZ;

void setup() {
  Serial.begin(9600);
  adxl.powerOn();
  servo1.attach(9);
  servo2.attach(10);
  servo3.attach(11);
}

void loop() {
  adxl.readAccel(&x, &y, &z); //read the accelerometer values and store them in variables  x,y,z

  rawX = x - 7;
  rawY = y - 6;
  rawZ = z - 10;
  
  if (rawX < -255) rawX = -255; else if (rawX > 255) rawX = 255;
  if (rawY < -255) rawY = -255; else if (rawY > 255) rawY = 255;
  if (rawZ < -255) rawZ = -255; else if (rawZ > 255) rawZ = 255;
  
  mappedRawX = map(rawX, -255, 255, 0, 180);
  mappedRawY = map(rawY, -255, 255, 0, 180);
  mappedRawZ = map(rawZ, -255, 255, 0, 180);
  
  
  servo1.write(mappedRawX);
  delay(15);
  
  servo2.write(mappedRawY); //(180 - mappedRawY);
  delay(15);

  servo3.write(mappedRawZ);
  delay(15);
  
  Serial.print(" mappedRawX = "); Serial.print(mappedRawX); // raw data with offset
  Serial.print(" mappedRawY = "); Serial.println(mappedRawY); // raw data with offset
  Serial.print(" mappedRawZ = "); Serial.println(mappedRawZ); // raw data with offset
}

please help me

You don't tell us what attempts you've tried to probe the problem. There's plenty of basic stuff you could do to investigate.

I'm not familiar with the Servo library other than to see if you compile with 0016 or earlier only pins 9 and 10 are supported. Are you using the latest Arduino IDE and servo library?

What information comes to you from your Serial.Prints for the 3 channels? Do they change as you would expect? The serial port is a great way of checking your variables [e.g. raw and mappedRaw].

Have you tried swapping the motors over or using standard servos which don't 'need' to fly? Have you checked the pins you are using for the motors? That's to say have you got the motor connected to the correct pin? Have you used a logic probe / tracer / oscilloscope on the pin to check the waveform?

By the way the constrain command constrain() - Arduino Reference is 'clearer' when used in a sketch rather than:

if (rawZ < -255) rawZ = -255; else if (rawZ > 255) rawZ = 255;

There's plenty you can do to help yourself locate the problem. :slight_smile: