Servo not working with ESP32

When i am using servo with arduino uno it seems to work but with ESP32 (using the appropriate library) it does not work .Using multimeter is seems that the pwm of ESP32 oscillates between 1.5v to 3v but on Arduino uno it is from1.5v to 1.5 v. I don't know if its the servo or something else

1 Like

Welcome to the forum

How is the servo powered ?

What library are you using to support your servo from your esp32? The arduino library isn't going to work since it uses analogWrite which is not supported natively by the esp32 Espresif Library. Check out this.

1 Like

Not the correct instrument

Which is ..?

I tried this [GitHub - jkb-git/ESP32Servo: Arduino-compatible servo library for the ESP32] and [https://github.com/RoboticsBrno/ESP32-Arduino-Servo-Library/archive/master.zip]. I think that the DOIT Devkit v1 esp32 doesn't work with with The SG90 from Tower Pro .I have seen other esp32 boards with that servo and the DOIT bord working with servos from other brands ; IDK what the main problem is .

Please post your sketch and a schematic of your project

You have not said how the servo is powered

Have you tried the library suggested in post #3?

Your servo requires min 1000µs and max 2000µs configuration. Here's an example which includes link to your servo's datasheet:

In addition to @UKHeliBob share the code of arduino Uno as well for better understanding and if you are doing some mistake.

Also after multiple request you are not providing the required input

1 Like

I tried powering the servo via VIN ,3v pin and also tried and external power supply (3v and 5v).As for the code I used the Example code for the sweep function (both the libraries).

Seems that your servo needs voltage level translation for the pwm signal. There's a working solution (with example) here you could try that should work for your SG90.

PWM Voltage level translation:

  • Just 1 NPN transistor (or N-Cannel MOSFET), 2 resistors and inverted pwm
  • OR a level shifting board and normal pwm

Be careful to use the correct type of pwm, or the servo motor will not work and it might overheat.

Library: ESP32-ESP32S2-AnalogWrite
Using inverted PWM mode for level translation with a regular or continuous rotation servo motor:
Wokwi_badge

whats an inverted PWM and how to achieve it

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.