Brand new to Arduino, need some help with servo control

Hi all. I'm trying to control just one continuous rotation servo motor (Feetech FS5106R) with an Arduino Due. I am powering both the Arduino and the motor with a 5V external power supply. The servo is connected at PWM pin 9. Here is my code:

#include <Servo.h>

Servo myservo;

void setup() {
myservo.attach(9); //pin number


void loop() {


Once I get this to work how I want, I'll expand it to how I really want it. But basically I'm just looking to rotate it clockwise for a time, stop for a time, counterclockwise for a time, etc, etc. When I run this code, it seems to get stuck in the first three lines of the loop code. The motor remains stationary for 3 seconds, rotates CW for a second, remains stationary for 3 seconds, rotates CW for a second, and so on, without ever rotating CCW. It took a little trial and error to find 1450 as the stopped value, but that is the correct one. How do I fix this?

Remove this

Your issue is myservo.detach.

The servo will complete one loop of code, before it gets erased and the Arduino can no longer control it.

Just a heads up, it sounds like you are using a continuous servo. They have no position feedback and cannot be set to specific angles.

have you done this adjust?

The FS5106R continuous rotation servo converts standard RC servo position pulses into continuous rotation speed. The default rest point is 1.5 ms, but this can be adjusted by using a small screwdriver to turn the middle-point positioner. Pulse widths above the rest point result in counterclockwise rotation, with speed increasing as the pulse width increases; pulse widths below the rest point result in clockwise rotation, with speed increasing as the pulse width decreases.

RV mineirin

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.