Home > Industry Insights >Servo
TECHNICAL SUPPORT

Product Support

Arduino SG-90 servo actual combat: wiring code and pit avoidance guide

Published 2026-05-11

Let’s talk about a fact at the beginning: when playing with Arduino’s car, or playing with Arduino’s robotic arm, or playing with Arduino’s small access control, nine times out of ten, you will encounter the blue 9g micro servo, or the transparent 9g micro servo, which is the SG-90. Despite its small size, it twists the angle, controls the switch, and nods and shakes its head, all relying on the pulse width signal. But many people encounter difficulties in the first step: How to connect the lines? Why does the code jitter after it is written? Today I will sort it out for you in detail and pick out the essentials from the overwhelming experience.

01Don’t turn on the power first, recognize the three lines

Brown wire: GND (ground)

Red wire: VCC (5V power supply)

Orange line: PWM signal pin (D9/D10 is optional)

The following is a common rollover situation: push the red line to 3.3V, but the servo does not rotate; insert it into the positive terminal of the battery, causing the internal drive to be burned.

Its safe zone is 5V, which is enough to drive one by relying on USB power supply. If you are driving more than two, an external battery pack will be more stable.

02There are actually two sections of code

Use the Servo library, don't write the PWM duty cycle yourself.

#includeServo myServo; void setup() { myServo.attach(9); // The signal line is connected to pin 9 } void loop() { myServo.write(0); // 0 degree delay(1000); myServo.write(90); // 90 degree delay(1000); myServo.write(180); // 180 degree delay(1000); }

This section will rotate back and forth. Don't ask why it belongs to the situation of 0, 90 and 180, then its physical limit is here.

03The underlying logic that truly makes SG-90 obedient

There is a potentiometer and reduction gear inside it. When you give a pulse width of 1ms, it rotates 0 degrees, when you give a pulse width of 1.5ms, it turns 90 degrees, and when you give a pulse width of 2ms, it turns 180 degrees.

arduino Micro Servos SG-90_arduino Micro Servos SG-90_arduino Micro Servos SG-90

The Servo library automatically converts the angle in write to the corresponding pulse width.

However, it should be noted that SG-90 produced by different manufacturers may be off by a few degrees, so the calibration process cannot be omitted.

First write(90) to see if the arm piece is vertical

If not, manually bend it to the vertical position and reinstall the arm.

04Common fault scenes that you must have encountered before

Q/A section

Q: The servo vibrates wildly when connected, how to solve it?

A: The power supply is in an unstable state. The 5V power supply operation is performed solely on the red line. The 5V pin of Arduino is only used as a signal reference.

Q: What should I do if write(180) can only go to 120 degrees?

A: First perform the write(180) operation, then cut off the power, then manually bend the arm to the maximum angle, and then turn on the power again.

Q: Is it normal for the servo to get hot after turning continuously for several minutes?

A: Abnormal. SG-90 is a position servo, do not use it as a continuous rotating motor.

Q: The signal cable is connected correctly and the code is correct, but it just doesn’t move?

arduino Micro Servos SG-90_arduino Micro Servos SG-90_arduino Micro Servos SG-90

A: Check the common ground. Arduino GND and servo GND must be connected.

Q: Can I directly give the PWM signal instead of the Servo library?

A: Yes but not necessary. The library encapsulates the 20ms cycle, and it is easy to burn the servo if you write it yourself.

05A leaping practice from "active" to "accurate"

Don't think about making a six-legged robot in one step. First make a small device:

barrier made of cardboard

Trigger the button, press once to raise the lever, and then press the lower lever

The key point of the code is to record the current state every time write(0) or write(90) is called.

You can detect a situation. When it changes from 0 to 90 quickly, the servo will appear to "shoot forward". Add delay? Not so, but add easing.

void slowMove(int from, int to, int stepDelay) { if (from = to; i--) { myServo.write(i); delay(stepDelay); } }

In this way, it moves slowly like a real arm, and the gears are not prone to collapse.

06One caveat: the SG-90's torque is only 1.6kg·cm

What's the meaning? It's fine for lifting an AA battery, but want to push a book? Must be stuck.

In the process of making a robotic arm, the big arm part must use a metal tooth servo, such as MG995. However, SG-90 is only suitable for making wrists or claws.

Analogical reasoning: SG-90 is like a bicycle chain. If you use it to pull a car, it will definitely break.

07Finally, I’ll give you a mind map (text version)

SG-90 debugging decision tree ├─ No response when plugged in │ ├─ Check: GND is on the same ground? │ └─ Check: 5V power supply is enough for 1A? ├─ Jitter after moving to the target position │ ├─ Add capacitor: 100uF electrolysis between the red wire and GND │ └─ delay(15) after writing in the code ├─ The angle is off │ ├─ Soft calibration: myServo.write (actual angle + offset) │ └─ Hard calibration: remove the arm piece and reinstall it └─ Don’t follow the code at all └─ Change to a digital one and check if any other library occupies Timer1

08Suggestions for action: Take action now

1. Get a breadboard, an SG-90, and three DuPont wires.

2. Burn the code for reversing the first paragraph above.

3. Confirm the 0 degree, 90 degree, and 180 degree positions.

4. Modify the code so that it stops at 45 degrees and holds for 10 seconds.

5. If successful, you have mastered 80% of the application scenarios of small servos.

What is the remaining 20%? It is to connect multiple servos in series, to read the potentiometer to achieve a closed loop, and to set the action group. But I won’t talk about it today, because you have to get this one running first.

Remember: all complex robot projects start with an SG-90 that can rotate 30 degrees compliantly. Go try it, don’t just wait and see.

Update Time:2026-05-11

Powering The Future

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

Mail to Kpower
Submit Inquiry
WhatsApp Message
+86 0769 8399 3238
 
kpowerMap