Esp32 with servo td8120

Hey there, i'm new on the forum. I'm having trouble managing to work out and ESP32 with a Servomotor, would love is someone could give me some help. Basically i want the servo to go from 0-180 then wait a time depending on a selection then go back from 180-0 but instead the servo is doing some anoying moves and strange buzing noises.
Yes, my servo is supplied by an external source, 5V and the ESP32 supply is 6.7V.
Thanks!

I moved your topic to an appropriate forum category @cristians-12.

In the future, when creating a topic please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

1 Like
  • We need to see your schematic and good images of the actual wiring.
  • We need to see your sketch, use code tags when posting.

THe problem with jittering servos is usually that the servo supply can't deliver the needed stall current of the servo.
Small SG90 servos are happy with a 5volt/1Amp supply, medium sized servos might need a supply capable of delivering 2.5Amp or more.
Your TD8120 servo draws 2.1Amp stall@4.8volt.
Post a link to the supply.
Leo..

First, make sure the ground from your servo power supply is connected to the ESP32’s ground. Without a shared ground, the control signal from the ESP32 won't be understood by the servo, it’s a common mistake that causes strange behavior.

Also, not every GPIO pin on the ESP32 supports PWM (which is needed to control servos). Try using one that’s known to work well, like GPIO 18 or 19. using an incompatible pin might result in erratic movement or no movement at all.

Timing matters too, if the servo is moving too quickly between positions without enough delay, it can get confused or make buzzing noises. Adding proper pauses between motions helps the servo reach its positions cleanly.

You're already doing the right thing by powering the servo from an external 5V source, that’s important. Just be sure the power supply is stable and can handle the current your servo needs, especially under load.

If you haven’t checked it out already, this guide explains servo-ESP32 connections really clearly:
:link: Interfacing SG90 Servo with ESP32

And if you're interested in going further, this cool project might give you ideas for more complex setups:
:link: ESP32 Controlled Quadruped Spider Robot

Feel free to share more about your exact setup, like which servo you're using, what GPIO pin it's on, and how you're handling delays. Happy to help you sort it out!

Hi Leo,
It’s a custom-made power supply using a transformer.
Thanks for your response.


Hi Larry,
Here is my schematic, my sketch is pretty long and i'm not using best practices because didn't create modules for each of my functions but here it is.

void nonBlockingDosingProcess()
{
    static unsigned long lastMoment = 0;
    static int angle = 0;

    switch (dosingState)
    {
    case START:
        angle = 0;
        lastMoment = millis();
        if (!doserServo.attached())
        {
            doserServo.attach(SERVO_PIN, 500, 2500);
        }
        doserServo.write(angle);
        showMessage("DOSING...", GREEN);
        dosingState = MOVING_FORWARD;
        break;

    case MOVING_FORWARD:
        if (millis() - lastMoment >= servoInterval)
        {
            if (angle >= 150)
            {
                doserServo.write(180);
                doserServo.detach();
                dosingState = WAITING_TIME;
                lastMoment = millis();
            }
            else
            {
                angle += servoStep;
                doserServo.write(angle);
                lastMoment = millis();
            }
        }
        break;

    case WAITING_TIME:
        if (millis() - lastMoment >= pendingDosingTime)
        {
            lastMoment = millis();
            dosingState = MOVING_BACK;
            doserServo.attach(SERVO_PIN, 500, 2500);
        }
        break;

    case MOVING_BACK:
        if (millis() - lastMoment >= servoInterval)
        {
            angle -= servoStep;

            if (angle <= 50)
            {
                angle = 0;
                doserServo.write(0);
                lastMoment = millis();
                dosingState = FINISH;
            }
            else
            {
                doserServo.write(angle);
                lastMoment = millis();
            }
        }
        break;

    case FINISH:
        doserServo.detach();
        showMessage("", BLACK);
        dosingCount++;

        dosingHistory[historyIndex].timestamp = rtc.now();
        dosingHistory[historyIndex].week = currentSubOption;
        dosingHistory[historyIndex].completed = true;
        historyIndex = (historyIndex + 1) % MAX_DOSING_HISTORY;
        dosingState = WAITING_TIME;
        hasPendingDosing = false;

        showDosingScreen = true;
        showSubMenu1 = false;
        showMainMenu = false;
        displayHistoryScreen();
        break;
    }
}

Thanks for your response

Hi dhamu,
First of all thanks for your valuable answer, i'm using the pin 13. Noticed that might me noise on the wires sometimes when i touch them the servo moves, also noticed the timing indeed does the thing, here:

int servoSteps= 2;
int delayServo= 10;

I'm using a delay between each step of my servo, and I noticed that this is key — adjusting it can improve or worsen the servo's behavior.
Thanks for your response.

Where is the rest of the code?

Tell us more about that supply. Is it regulated or not.
What current rating is the secondary winding and what is the size of the smoothing cap. An annotated diagram speaks a thousand words.
Leo..