1

I just got to play around with Arduino lately so I'm really new on this stuff and sorry for the grammar error.

I got a work where I need to turn the LED on all the time, my plan is to add a slow fade in and fade out later but the problem occurs when I add the servo.

Everytime servo starts moving slowly or fast the LED kinda flickering/dim like it lost power and come back to normal after the servo stops moving.

Here's the scheme I used and the code, I only change some delay to 5ms and so to test it out but no matter what the led is keep flickering.

Im using nano v.3 clone if its matter.

exactly like this, I tried to add a resistor but no luck

#include <Servo.h>
Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 100;    // variable to store the servo position
int ledpin3 = 3;

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  pinMode(ledpin3, OUTPUT);
}

void loop() {
  digitalWrite(ledpin3, HIGH);
  delay(1000);

  for (pos = 99; pos <= 150; pos += 1) { // goes from 0 degrees to 180 degrees
                                         // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable ‘pos’
    delay(15);                       // waits 15ms for the servo to reach the position
  }

  for (pos = 150; pos >= 30; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable ‘pos’
    delay(15);                       // waits 15ms for the servo to reach the position
  }

  for (pos = 30; pos <= 99; pos += 1) { // goes from 0 degrees to 180 degrees
                                        // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable ‘pos’
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}
4
  • Try moving your LED digitalWrite in the setup as you are just turning it on. Commented Sep 5, 2018 at 22:50
  • Do you have a resistor on your LED?
    – trapper
    Commented Sep 6, 2018 at 8:04
  • Does the LED flicker with same sketch and the servo disconnected? If not I think power is the issue.
    – Craig
    Commented Sep 6, 2018 at 15:24
  • if it's only a cosmetic problem, add a resistor in series with the LED and a capacitor across the LED leads.
    – dandavis
    Commented Sep 6, 2018 at 17:43

1 Answer 1

2

If you are powering the arduino via usb try not to do that or plug it in to an usb 3.0 (and higher) port. The reason for this is that the servo draws a lot of power and the standard usb 2.0 with 0.5A can't handle the load and you got an voltage drop. And in that period of time the led goes off. usb 3.0 (and higher) can handle up to 1.5A so this souldn't be an error.

3
  • Thanks for your reply coder,tried to put it on my 3.0 usb ready powerbank and also directly at wall with no luck,the led still go wild,do i need to power the servo from another source? I tried to really minimize the component since i barely got any space left
    – user194312
    Commented Sep 5, 2018 at 21:37
  • It would be better if you powered the servo from its own power source such as batteries during development / testing. Later, if a larger power supply can be located, you might try using the same power source for both the Arduino and servos. Remember that the servo ground needs to be connected to the Arduino ground as well as the independent power source ground.
    – st2000
    Commented Sep 5, 2018 at 23:36
  • 1
    This not only depends on the USB power source, but also in the diode, through which the current flows on the Arduino. If you draw too much current through it, you will fry the diode. You have to connect the servos power besides the Arduino, not through it.
    – chrisl
    Commented Sep 7, 2018 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.