# Servo move Counter-clockwise to Clockwise direction (0 to 90 degree)

**URL:** <https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075>\
**Category:** General Guidance\
**Created:** [September 6, 2024, 8:17am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075 "2024-09-06T08:17:33Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![poseidon\_sv](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/poseidon_sv/32/1098747_2.png) [@poseidon\_sv](https://forum.arduino.cc/u/poseidon_sv)\
**Post date:** [September 6, 2024, 8:17am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075/1 "2024-09-06T08:17:34Z")

</div>

My Servo motor goes 0 to 90 to180 degree counter-clockwise is there anyway to make it clockwise?? Like If I do `myservo.write(90);` I want it to go 90 degree to the clockwise direction NOT counter-clockwise. I can use ESP32 if required.

---

<div class="post-metadata">

**Author:** ![SurferTim](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/surfertim/32/1072341_2.png) [@SurferTim](https://forum.arduino.cc/u/SurferTim)\
**Post date:** [September 6, 2024, 8:36am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075/2 "2024-09-06T08:36:08Z")

</div>

Can you be more specific about "My servo motor"? What model? A link might help.

---

<div class="post-metadata">

**Author:** ![poseidon\_sv](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/poseidon_sv/32/1098747_2.png) [@poseidon\_sv](https://forum.arduino.cc/u/poseidon_sv)\
**Post date:** [September 6, 2024, 8:58am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075/3 "2024-09-06T08:58:16Z")

</div>

> [@poseidon\_sv](#):
>
> My Servo motor goes 0 to 90 to180 degree counter-clockwise is there anyway to make it clockwise?? Like If I do `myservo.write(90);` I want it to go 90 degree to the clockwise direction NOT counter-clockwise. I can use ESP32 if required.

Tower pro 180 degree Micro servo

 ![Normal Servo](https://europe1.discourse-cdn.com/arduino/original/4X/9/9/2/992cf5a8a0ff0d24bc3c1c576f5a61662169e233.jpeg)

@SurferTim

---

<div class="post-metadata">

**Author:** ![SurferTim](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/surfertim/32/1072341_2.png) [@SurferTim](https://forum.arduino.cc/u/SurferTim)\
**Post date:** [September 6, 2024, 9:01am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075/4 "2024-09-06T09:01:02Z")

</div>

The direction of movement will depend on where it started. Does the servo start at zero or 180? 90 should be right in the middle.

---

<div class="post-metadata">

**Author:** ![poseidon\_sv](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/poseidon_sv/32/1098747_2.png) [@poseidon\_sv](https://forum.arduino.cc/u/poseidon_sv)\
**Post date:** [September 6, 2024, 9:07am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075/5 "2024-09-06T09:07:44Z")

</div>

Yah you are right but I am fixing this servo (_Screwing on board or something_) and if it goes in other direction things might get damaged, so while fixing I'm keeping it 0 degree (because **I think** when on boot servos tends to go 0 degree) so when `myservo.write(90)` I want it to go 90 but in clockwise, by default it goes counter-clockwise to 90 degree. **Or** I fix it on 90 degree and write 0 to move 90 degree clockwise??

---

<div class="post-metadata">

**Author:** ![SurferTim](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/surfertim/32/1072341_2.png) [@SurferTim](https://forum.arduino.cc/u/SurferTim)\
**Post date:** [September 6, 2024, 9:10am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075/6 "2024-09-06T09:10:07Z")

</div>

Start at 0 and go 90, it rotates one direction.  
Start at 180 and go to 90, it rotates the other direction.  
Sounds like you need to boot the servo to 90. Now it can go clockwise or counter-clockwise.

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [September 6, 2024, 9:13am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075/7 "2024-09-06T09:13:02Z")

</div>

Please use the code tag, "`" symbol and post the code.`

---

<div class="post-metadata">

**Author:** ![poseidon\_sv](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/poseidon_sv/32/1098747_2.png) [@poseidon\_sv](https://forum.arduino.cc/u/poseidon_sv)\
**Post date:** [September 6, 2024, 9:22am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075/8 "2024-09-06T09:22:39Z")

</div>

No there's no code right now I'm just looking for a way to go servo in clockwise direction if its start from 0 degree (by these I mean the potentiometer is in 0 degree position like I keep it on 0 with the help of `myservo.write(0)` then screw it on board), but I think I have to screw it on 90 degree `myservo.write(90)` to move it to 0 degree `myservo.write(0)` (90 degree clockwise direction) .

---

<div class="post-metadata">

**Author:** ![SurferTim](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/surfertim/32/1072341_2.png) [@SurferTim](https://forum.arduino.cc/u/SurferTim)\
**Post date:** [September 6, 2024, 9:24am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075/9 "2024-09-06T09:24:31Z")

</div>

Start at 0 and the servo will move in only one direction.  
Start at 180 and the servo will move in only the other direction.  
Start at 90, and now it can move to 0 or 180.

---

<div class="post-metadata">

**Author:** ![davidefa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/davidefa/32/1088935_2.png) [@davidefa](https://forum.arduino.cc/u/davidefa)\
**Post date:** [September 6, 2024, 9:29am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075/10 "2024-09-06T09:29:35Z")

</div>

Simply position at 180-angle, 90° position stays same, you are only swapping 0° and 180°

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [September 6, 2024, 9:40am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075/11 "2024-09-06T09:40:21Z")

</div>

What device is sending the signal to the servo then? Repeating the same story doesn't help.

---

<div class="post-metadata">

**Author:** ![poseidon\_sv](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/poseidon_sv/32/1098747_2.png) [@poseidon\_sv](https://forum.arduino.cc/u/poseidon_sv)\
**Post date:** [September 6, 2024, 9:41am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075/12 "2024-09-06T09:41:31Z")

</div>

ESP32 microcontroller

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [September 6, 2024, 10:16am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075/13 "2024-09-06T10:16:31Z")

</div>

Does it run without code?

---

<div class="post-metadata">

**Author:** ![poseidon\_sv](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/poseidon_sv/32/1098747_2.png) [@poseidon\_sv](https://forum.arduino.cc/u/poseidon_sv)\
**Post date:** [September 6, 2024, 10:22am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075/14 "2024-09-06T10:22:13Z")

</div>

```arduino
#include <ESP32Servo.h>

Servo myservo;

void setup() {
    myservo.attach(9); // Attach servo to pin 9
}

void loop() {
    for (int pos = 0; pos <= 180; pos += 1) {
        myservo.write(pos); 
        delay(15); // Delay to allow servo to reach the position
    }

    for (int pos = 180; pos >= 0; pos -= 1) {
        myservo.write(pos);  
        delay(15); // Delay to allow servo to reach the position
    }
}

```

---

<div class="post-metadata">

**Author:** ![SurferTim](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/surfertim/32/1072341_2.png) [@SurferTim](https://forum.arduino.cc/u/SurferTim)\
**Post date:** [September 6, 2024, 10:24am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075/15 "2024-09-06T10:24:45Z")

</div>

And with that code the servo does what?

---

<div class="post-metadata">

**Author:** ![poseidon\_sv](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/poseidon_sv/32/1098747_2.png) [@poseidon\_sv](https://forum.arduino.cc/u/poseidon_sv)\
**Post date:** [September 6, 2024, 10:28am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075/16 "2024-09-06T10:28:26Z")

</div>

It goes from 0 to 180 degree (Counter Clockwise direction) then comes back to 0 degree (Clockwise direction), but I want to change the direction, like I want to make it go 0 to 180 in clockwise direction.

---

<div class="post-metadata">

**Author:** ![davidefa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/davidefa/32/1088935_2.png) [@davidefa](https://forum.arduino.cc/u/davidefa)\
**Post date:** [September 6, 2024, 10:31am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075/17 "2024-09-06T10:31:28Z")

</div>

As said instead of writeing:

`myservo.write(pos);`

write:

`myservo.write(180-pos);`

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [September 6, 2024, 10:35am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075/18 "2024-09-06T10:35:29Z")

</div>

Change place of the two for loops.

---

<div class="post-metadata">

**Author:** ![poseidon\_sv](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/poseidon_sv/32/1098747_2.png) [@poseidon\_sv](https://forum.arduino.cc/u/poseidon_sv)\
**Post date:** [September 6, 2024, 10:40am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075/19 "2024-09-06T10:40:58Z")

</div>

Really?? If `pos = 90` and current position is 0 degree does it will not go counter-clockwise (default direction) to 90 degree as `180-90 = 90`? And yes I have tried, it goes counter-clockwise to 90 degree which I don't want.

First I executed (to go 0 degree position):

```arduino
#include <ESP32Servo.h>

Servo myServo; // Create a Servo object

// Define the pin for the servo signal
const int servoPin = 27;  

int pos = 0;

void setup() {
  myServo.attach(servoPin);  
}

void loop() {
  // Move servo to 0 degrees
  myServo.write(pos);

}

```

Then this: (Result is same as with `myservo.write(pos);`)

```arduino
#include <ESP32Servo.h>

Servo myServo; // Create a Servo object

// Define the pin for the servo signal
const int servoPin = 27;

int pos = 90;

void setup() {
  myServo.attach(servoPin); 
}

void loop() {
  myServo.write(180 - pos);

}

```

---

<div class="post-metadata">

**Author:** ![camsysca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/camsysca/32/1015228_2.png) [@camsysca](https://forum.arduino.cc/u/camsysca)\
**Post date:** [September 6, 2024, 10:42am UTC](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075/20 "2024-09-06T10:42:49Z")

</div>

Woah. Different approach may be needed. See if the following description fits:

When I mount my Servo, I want to know what position (0...180) it is set at so that when it powers up it is centered. My code will assume it is centered, so it could move either direction after that. If it starts at 0 (or 180), there could be damage done when the code starts.

IF that's the case, write a short code in setup that sets the servo to 90; put nothing in loop(). Upload that code. When it runs, the servo will move to 90. Now power it down - the servo should not change position.

Now, write your main code. MAKE DARN SURE you set the servo position to 90 in your code BEFORE you servo.attach(pin). That is the point in time when the servo code begins to control the position, so your code will start at 90.

Does that help?

[Next page](https://forum.arduino.cc/t/servo-move-counter-clockwise-to-clockwise-direction-0-to-90-degree/1299075.md?page=2)
