Hello. My program was working a few days ago with controlling servos with a Gryoscope. However, now..the servos (there is 4 of them ) randomly start spinning at random times and at any given order. (They do not all spin at once.)
Even when I write them out of the code...they keep spinning!
Why is this happening...thank you.
Code and schematics would help otherwise just take a guess...
Schematics are this: https://image.dfrobot.com/image//Blog/1309/2.png
Code:
//hammadiqbal12@gmail.com
//https://www.youtube.com/watch?v=Cvtr3LKdqvk
#include <GY6050.h> //library for GYRO
#include <Wire.h>
#include <Servo.h>
Servo myservo; //y
Servo myservo2;//y
Servo myservo3;//x
Servo myservo4;//x
int Y2 = 0;
int X = 0;
int Y = 0;
GY6050 gyro(0x68); //to save GYRO data
void setup() {
Serial.begin(9600);
Wire.begin(); //initializing GYRO
gyro.initialisation();
delay(100);
myservo.attach(9);
myservo2.attach(8);
myservo3.attach(7);
myservo4.attach(10);
}
void loop() {
X = map(gyro.refresh('A', 'X'), -90, 90, 0, 180); //mapping the gyro data according to angle limitation of servo motor
Y = map(gyro.refresh('A', 'Y'), -90, 90, 0, 180);
Y2 = 180 - (Y - 10);
myservo.write(Y2);
myservo2.write(Y2);
//myservo3.write(X);
myservo4.write(X);
Serial.println(Y2);
//movement of Y axis will control servo
delay(15);
}
It's what you said was the schematic. So you only have one servo. That should make things easier.
Or if that's not the real schematic and you have 4 servos all powered from a Uno's 5V pin then that's your problem. Use a separate power supply for the servos.
Steve
Oops..I have 4 servos..but everything else is the same
engineer123498:
Oops..I have 4 servos..but everything else is the same
Then you probably need a separate good power supply for the servos as previously stated.
X = map(gyro.refresh('A', 'X'), -90, 90, 0, 180);map?
Seriously?