Delay on servo not working after switching to external power

Hi everyone!

I have an issue I've been struggling with for some time with no results.

Project Description:
The goal of this project is very simple: I have servo connected to a microcontroller (Pololu A-star running on Atmega 328pb at 5V and 20Mhz) and two wires going out of it. When these wires come into contact, the servo should move to position for 3 seconds and come back.

Problem:
Everything works fine when I am connected via UART to the controller, but when I switch to external power (using 5V voltage from a USB charger) the servo just alternates back and forth without delay when wires come into contact. I.e the servo doesn't hold the position for 3 seconds, just returns immidiately.

Done so far:

  • I tried supplying voltage to the controller via alternative pins - same effect
  • I also ran the famous 'blink' example while on external power and there the delay worked
  • I tried omitting the delay function by implementing a counter via millis() -> saving the time when we closed the wires and checking when we exceeded that time plus 3 seconds, also no success

If anyone has any ideas or suggestions on what to try/do I would be very thankful

It sounds like you are powering the servo from the micro controller. That may be ok with a single servo and light loads, but it's marginal. The servo needs separate power.

You're right - the issue is the servo is already connected directly to the USB power supply, omitting the controller

Then the supply to the servo's is insufficient to do the thing.

Thanks for all the responses so far

Yes, I did more testing and it seems that the cause for the constant repetition is that the controller is resetting itself after every servo trigger. Is it because the servo is pulling so much current from the usb (even under no load) that the board resets itself due to power shortages? But how can a phone-grade usb charger be insufficient?

(I'm gonna buy some capacitors tomorrow and try them - maybe they'll help)

A standard USB supply will supply 500 milliamps. The Arduino consumes some of that. A servo may consume an Amp or more, especially under load. That's where your problem lies I suspect.

Check the grounds and be sure they are connected. Try a 1 or 2 amp power source.