Servo works on Arduino Uno but not on Arduino Nano ESP32 — same wiring, same code

Hello,

I am new to Arduino and need some help. I am trying to control a servo (Reely D15022MG) with an Arduino Nano ESP32, but it does not move at all. The same setup works perfectly with an Arduino Uno.

My setup:

  • Servo signal wire connected to pin D2
  • Servo powered by external 5V power supply
  • All GNDs connected: Arduino GND, breadboard GND rail, and external power supply GND
  • ESP32Servo library installed manually via ZIP from GitHub

Things I already tried to rule out hardware defects:

  • Replaced the Arduino Nano ESP32 with a new one
  • Replaced all cables
  • Tried pin D9 instead of D2 on the Nano ESP32
    Same result every time.

Strange behavior: When I disconnect all GND wires between the Arduino and the breadboard, the servo starts twitching. As soon as I reconnect the GND, it stops completely and does not move at all.

With the Arduino Uno and the standard Servo.h library, the exact same wiring works without any problems.

Code for Arduino Nano ESP32:

#include <ESP32Servo.h>

Servo meinServo;
const int SERVO_PIN = 2;

void setup() {
  Serial.begin(115200);
  meinServo.attach(SERVO_PIN);
}

void loop() {
  meinServo.write(0);
  delay(1500);
  meinServo.write(90);
  delay(1500);
  meinServo.write(180);
  delay(1500);
}

Code for Arduino Uno (this works!):
#include <Servo.h>

Servo meinServo;
const int SERVO_PIN = 2;

void setup() {
  Serial.begin(115200);
  meinServo.attach(SERVO_PIN);
}

void loop() {
  meinServo.write(0);
  delay(1500);
  meinServo.write(90);
  delay(1500);
  meinServo.write(180);
  delay(1500);
}

Why does the servo work on the Uno but not on the Nano ESP32? Is there something special I need to do for the Nano ESP32?

Thank you!

Maybe because the Uno I/O voltage is 5V and the Nano ESP32 I/O voltage is only 3.3V

Besides the possible voltage problem, try using the Arduino pin name explicitly:

const int SERVO_PIN = D2;

instead of:

const int SERVO_PIN = 2;

The Nano ESP32 pin mapping can be confusing when moving code from an Uno.

Does this also matter for the signal pin. The voltage itself is provided by my 5v external power supply. It has alredy worked for a few days but stopped now for no obvious reason

Which pin mapping option is selected in the IDE I wonder ?

I can think of many reasons why it is not working and I think it is not working the way it should.Those two processors are as different as a balloon and an airplane, they both fly but??? The best way to get an accurate answer is post your annotated schematic showing exactly how you wired it. I am assuming you did not just connect wires. Post links to technical information on the hardware items you are using, there are many parts with the same name such as Nano but are not the same.

Yes, the signal pin may also matter.

Even if the servo is powered from an external 5 V supply, the Nano ESP32 still sends only a 3.3 V control signal. Many servos accept that, but not all of them do so reliably.

If it worked for a few days and then stopped, I would also double-check common GND between the ESP32 and the servo power supply, the servo supply voltage under load, and the signal connection.

thats basicly everthing I did. The 5V goes into the Breadboard as well of course.

I use the Nano Esp32:

Reely D15022MG Servo:

Thanks for the hint. However this didn't seem to be the problem

it's the default pin mapping

The only way to know for sure if it is a 3.3V/5V problem is to use a level shifter and see if it works. Buy a 74HCT125 and connect like this:

Red is 5V, black is GND, blue wire goes to Nano pin.

Also, breadboard connections can be very flakey and unreliable. Make sure the connections fit tight.

Then I would probably look again at the electrical side. That is quite a strong digital servo, not a tiny 9 g servo, so current peaks may be much higher than expected.

Even with an external 5 V supply, please make sure that:

  • servo GND and Nano ESP32 GND are connected together
  • the servo supply voltage stays stable under load
  • the servo signal wire is really connected to the intended pin
  • the servo accepts a 3.3 V control signal reliably

The fact that it worked for a few days does not completely rule out a marginal power or signal-level problem.

Nice picture but since I do not have the parts I cannot relate to it. I did check your motor and found this which tells me you would have problems if connected the way the picture indicates:
Idle:
10–30 mA

Moving, light load:
200–500 mA

Heavy load:
1–2 A

Near stall:
2–3 A peak possible

I think it will peak at about 5A @ 6V when stalled.

Hi, @samuelpfeil

Can you post some images of your project?
So we can see your component layout.

Thanks... Tom.... :smiley: :+1: :coffee: :australia:


Right now that's all there is. I reduced it to the most basic possibility.
What could also be interesting is, that the servo starts flinching as soon as I deconnect the GND of the arduino to the GND of the servo/5V. That is the way I actually should work right?

The GND connection between the ESP32 and the servo power supply must stay connected, otherwise there is no proper reference for the control signal anymore.

I would also try:

  • much shorter wires between ESP32 and servo
  • and especially avoid powering the servo through breadboard contacts

That is quite a strong digital servo, so I would connect the servo power directly to the 5 V supply with proper wires instead of routing the current through the breadboard.

That's normal and does not provide any useful debugging intormation

See post #11 for help otherwise you are just guessing as to what is wrong.