Home > Industry Insights >Custom Drive
TECHNICAL SUPPORT

Product Support

How to Control Servo Motor Clockwise and Counterclockwise Rotation with a Microcontroller Board (Complete Step-by-Step Guide)

Published 2026-04-19

This guide provides a practical, tested method to make aservomotor rotate both clockwise (CW) and counterclockwise (CCW) using a standard microcontroller board. Whether you are building a robotic arm, a camera pan-tilt system, or a simple rotating display, you will learn exactly how to achieve bi-directional control. We will use common, real-world examples—such as opening and closing a small gate or rotating a sensor left and right—to show you the verified wiring, code structure, and troubleshooting steps. No brand-specific products are required; the principles work with any standardservoand compatible control board.

01Core Principle: Understanding HowservoDirection Works

Before writing any code, you must know which type of servo you have. There are two common types:

Standard 180° servo– rotates only between 0° and 180°. “Forward” means increasing angle (e.g., 0° → 180°). “Reverse” means decreasing angle (180° → 0°).

Continuous rotation servo– rotates fully in either direction. “Forward” is one rotational direction (e.g., CW), “Reverse” is the opposite (CCW). Speed can also be controlled.

> Verification(source: standard servo datasheets and industry practice): For continuous servos, a pulse width of 1.5 ms stops the motor; 1.3 ms drives full speed one way; 1.7 ms drives full speed the opposite way. For standard servos, 0° = 0.5 ms pulse, 180° = 2.5 ms pulse (typical values, check your servo’s specs).

02Step 1: Gather Your Components (Common Case Example)

For the following instructions, we assume you have:

1 microcontroller board (any common development board)

1 servo motor (standard 180° or continuous – we will cover both)

3 jumper wires (male-to-female)

1 external power supply (4.8V–6V for most small servos; do not power a servo directly from the board’s 5V pin if it draws >200 mA)

1 breadboard (optional, for neat connections)

Real-world scenario used in this guide: You are building a small automated gate that swings open (CW) and closes (CCW). The servo is mounted to the gate hinge.

03Step 2: Wiring (Follow This Exactly)

Connect the servo to the board using these verified pinouts:

Servo Wire Connection Point
Brown or Black (GND) Board GND
Red (VCC / power) External 5V power supply positive terminal (shared GND with board)
Orange or Yellow (signal) Digital pin 9 (or any PWM-capable pin)

Critical rule: Always connect the servo’s ground to the board’s ground, even if using an external power supply. Without a common ground, the signal will be unstable.

04Step 3: Install the Required Library (No Brand Dependency)

The standardServolibrary is included in most microcontroller IDEs. To use it:

1. Open your IDE.

2. Go toSketch → Include Library → Servo(or equivalent in your environment).

3. If not pre-installed, search for “Servo” in the Library Manager and install the official one (usually maintained by the platform developers).

05Step 4: Code for Standard 180° Servo (Angle-Based “Forward/Reverse”)

pwm控制舵机反转_arduino舵机反转_arduino怎么控制舵机正反转

This code makes the servo sweep from 0° to 180° (one direction) and back to 0° (opposite direction). Use this for arms, levers, or gates that need precise positioning.

#includeServo myServo; // create servo object int pos = 0; // variable to store angle void setup() { myServo.attach(9); // signal pin 9 } void loop() { // Forward direction: 0° -> 180° (clockwise for most servos) for (pos = 0; pos 0° (counterclockwise) for (pos = 180; pos >= 0; pos -= 1) { myServo.write(pos); delay(15); } }

To test just one forward movement and stop: remove the reverse loop or add awhile(1);after the forward loop.

06Step 5: Code for Continuous Rotation Servo (True Forward/Reverse)

Continuous servos do not use angles – they use speed and direction. Use this code for wheels, conveyor belts, or continuous rotation platforms.

#includeServo myServo; void setup() { myServo.attach(9); } void loop() { // Full speed clockwise (forward) myServo.write(0); // or a value 90 (e.g., 135 or 180) delay(2000); // Stop again myServo.write(90); delay(1000); }

> Important calibration: The exact “stop” value varies between servos. Test values from 85 to 95 to find your servo’s neutral point. Use a small delay and observe.

07Step 6: Common Real-World Issues and Fixes

Based on actual user reports and our own testing,here are the most frequent problems and verified solutions:

Problem Most Likely Cause Verified Fix
Servo jitters or does not move Insufficient power Use a separate 5V/2A supply. Do not share the board’s 5V pin.
Continuous servo rotates only one way Wrong neutral calibration Adjust thewrite()value (try 88 to 92).
Standard servo moves then stops Angle out of range Ensure values are between 0 and 180 inclusive.
No movement, but code runs Signal pin mismatch Confirmattach(pin)matches your wiring.

08Step 7: Actionable Summary – Your Step-by-Step Checklist

To successfully control servo forward and reverse rotation:

1. Identify your servo type(180° or continuous).

2. Connect power– external supply + common ground.

3. Attach signal wireto a PWM pin (e.g., pin 9).

4. Load the Servo libraryand upload the appropriate code above.

5. Test direction– for standard servos, 0→180 = forward; for continuous, write 90 = reverse.

6. Calibrate stop(continuous) or speed delay (standard) as needed.

> Core takeaway: The same hardware setup works for both servo types – only the control values change. For standard servos, think inangles. For continuous servos, think inspeed and directionrelative to the neutral 90° pulse.

09Final Recommendation for Reliable Operation

Always start testing with the servo disconnected from any mechanical load (e.g., gate or wheel). Verify free rotation first.

Use a multimeter to confirm the power supply outputs between 4.8V and 6V DC.

If you need to reverse direction on a standard servo without moving through all intermediate angles, simplywrite(newAngle)– it will move directly to that position via the shortest path.

By following this guide, you can now implement servo forward/reverse control for any project – from a rotating camera mount to a two-wheeled robot – using common components and verified code.

Update Time:2026-04-19

Powering The Future

Contact Kpower's product specialist to recommend suitable motor or gearbox for your product.

Mail to Kpower
Submit Inquiry
+86 0769 8399 3238
 
kpowerMap