i’m making a gyroscopic stabiliser for a school project and I’m having a problem.
I’m using an Adafruit ADXL335 accelerometer and a Hitec HS-485HB servo. I started programming and I can perfectly get the values from the accelerometer that I also remapped from 0 to 180.
The problem occurs when I try to give the servo the value the accelerometer gives me, for example when I add servo1.write(degx); with degx being the value in degrees, the values go from 90, 89, 90, 90, … (when everything works fine) to 291 90 246 290 90 256 for example as soon as I add this line telling the servo to take the value.
I really don’t get it why it’s doing that.
Here’s the code:
int xpin = A1; // X Axis
Servo servo1; // Declares servo 1
int axex; // Raw values X
int degx; // Remapped X values
servo1.attach(9); // Connects servo 1 to port 9
Serial.begin(9600); // Start com
axex = analogRead(xpin); // Gives axex its value
degx = map(axex, 269, 408, 0, 180);
//servo1.write(degx); // PROBLEM
Here are some pictures:
If you guys could help me it would be great