Skip to main content
2 of 3
added 8 characters in body; edited title
ocrdu
  • 1.8k
  • 3
  • 12
  • 24

Servo keeps rotating

I used a 360° servo with a program I made on an Arduino Uno.

The program was meant to control two separate servos with two potentiometers on a breadboard. When I used 180° and 90° servos, it worked fine, but when the 180° servo was swapped with a 360° servo, it kept spinning and spinning non-stop.

Could it be the knock-off board (not Arduino brand) I'm using?

Servo serX;    // create servo object to control a servo for x axis
Servo serY;    // create servo y axis

int pot1 = 0;  // potentiometer pin number on board
int pot2 = 1;  // potentiometer number 2
int val;       // variable to read the value from the analog pin
int val2;      // read value from other analog pin

void setup() {
  serX.attach(9);  // attaches the servo on pin 9 to the servo object
  serY.attach(10); // attach servo to number 10 pin
}

void loop() {
  val = analogRead(pot1);           // reads the value of the potentiometer
  val = map(val, 0, 1023, 0, 180);  // scale it to use it with the servo
  serX.write(val);                  // sets the servo position
  
  val2 = analogRead(pot2);          // reads the value of the potentiometer
  val2 = map(val2, 0, 1023, 0, 90); // scale it to use it with the servo
  serY.write(val2);                 // sets the servo position
  
  delay(15);                        // waits for the servo to get there
}