SM-S2409S Moteur is not spinning 360 degress

How do I make my moteur spin 360degress :o it won’t work for me it only spin 180 then back here is my code please help me. :slight_smile:

#include <Servo.h>
#include <LiquidCrystal.h>

Servo myservo;
int pinServo = 9;
int periode=20000;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
myservo.attach(9);
myservo.write(0);
lcd.begin(16, 2);
pinMode(pinServo,OUTPUT);
digitalWrite(pinServo, LOW);

lcd.print(“Nombre de tours”);
}

void loop() {

digitalWrite(9, 2000);
for (int angle=0;angle<=180;angle+=20){
setAngle(angle);
}
lcd.setCursor(0, 1);

lcd.print(millis() / 2000);
}

void setAngle(int a){
int duree=map(a,0,179,1000,2000);
digitalWrite(pinServo,LOW);
for (int t=0;t<300;t++){
digitalWrite(pinServo,HIGH);
delayMicroseconds(duree);
digitalWrite(pinServo,LOW);
delayMicroseconds(periode-duree);
}
}

Please provide a link to the motor specifications. Google does not know about that motor.

Paul

ok sorry paul I meant to write a SM-S2309S moteur. :cold_sweat:

Martin_Bourcier:
ok sorry paul I meant to write a SM-S2309S moteur. :cold_sweat:

What is the problem? The PDF for that servo states the movement is +_60 degrees.

Paul

I want it to spin 360 degress but it just does 180 and goes back.

If you are getting 180 degrees you are doing very well because that servo is only specified to travel 120 degrees.

I can't think of any micro servos that will do a full 360 degrees. Most that are called 360 degree servos have no positional control at all. They just spin continuously forward and backwards.

BTW why are you not using the normal servo write() or writeMicroseconds() commands?

Steve

As Steve mentioned, you are not using the servo commands.
Go get the servo sweep tutorial and see it in operation. Much easier that what you are doing with the delaymicroseconds().

Also as mentioned before, most servos have a limited range of movement. Mose are about 120 degrees. Some closer to 180 degrees.
Be aware that most servos that are called 360 degree servos or continuous rotation servos do rotate continuously like the wheel on a car. Youi can tell it to rotate forward. Or tell it to rotate backward. You might even have some ability to control how fast it rotates.
But you lose the ability to control how far it rotates. The servo loses positional awareness when it is modified to be a 360 servo.