How to make a 360 servo do a 180 sweep?

I've got a geekservo motor and would like it to make a 180 sweep.

if you are using a continuous rotation servo (often referred to as a "360° servo"), it doesn't have the same positional control as a standard servo. Instead of moving to a specific angle and holding position, it can rotate continuously in either direction. (So to do the sweep you start moving in one direction for some time and when the time is up , then you reverse the direction for the same amount of time)

➜ clarify exactly what you have

Welcome to the forum

Do you have a standard servo that moves through 360 degrees (unlikely, but possible) or a continuous rotation "servo"

If the latter then you cannot make it sweep through 180 degrees as you can only control its speed and direction, not its angle

What happens when you use the Servo Sweep example with the servo ? That will tell us what type of servo that you have

Is it this one?
geekservo

If so that page says:-

This model is a motor (but it looks like a servo!)

So it is not a servo at all. It only has two wires and a servo has three wires. So no it will not do a 180˚ sweep. Plus you can't even use it to control the speed like a continuous rotation servo.

well - you can get it to spin in one direction for some time and then reverse.
if you time this correctly, it can be 180°

but indeed it's not a servo

You really could not make this stuff up, could you ?

1 Like

Yes but you need extra electronics to do that in the form of a H-bridge and have some sort of control of the speed by applying PWM to the motor.

indeed

I have tried that but it's very inconcistent.

I think the answer is simple:

  1. Buy a real servo
  2. Use it

So post the code you have tried and also post a schematic of the hardware you used to make the motor reverse direction please.

It would be inconsistent without some type of positional feedback. The major problem is that the motor speed will vary depending on the load. A regular servo has a potentiometer connected to the output shaft so that the internal control electronics can detect the position.


int pos = 0;

void setup() {
  myservo.attach(9);
}

void loop() {
  if (millis()-lastupdate > 300){
  lastupdate = millis();
  myservo.write(pos);
  if (pos == 180){
    pos = 0;
  }
  else{
    pos = 180;
  }
  }
}

Here is the code for the servo. And here is how i connected the servo.

A "Frankenstein" solution is to mount an "endless" potentiometer connected to the gear in the motor through another gear in a 1x1 ratio.

By measuring the potentiometer value you will know where the motor is positioned.

You forgetting that you don't actually have a servo. So driving it like you have done is not going to happen.

Your code is very wrong as well and will not compile. The variable lastupdate is not defined anywhere, it should be an unsigned long type.

Yeah sorry copied it from a longer code and most have missed it. But the code compiles.

The servo on Wokwi has 3 wires as expected. How many wires does your "servo" have ?

Without additional hardware like limit switches or some kind of positional encoder, you can't.

It also have 3.

Then it is not GeekServo Building Brick Compatible Motor | The Pi Hut

Please post a link to the servo that you have