I use a mega 2560, pir sensor and a SG90 9g Servo motor in my project. Basically while the pir outputs high, the Servo Motor rotates from 0 to 180 degrees.

Here is how everything is wired up:

PIR sensor:

Data: pin 24

Vcc: 5 volt

Gnd: Ground


PWM pin: pin 11

Vcc: 5 volt

Ground: ground

The arduino mega has two 5 volt and ground pins, one next to the analog pins and other at tho bottom bar of pin, where pins 22 and up are. I connected the Servo to the first 5v and gnd and the pir to the second.

My power source is my nexus 5 charger(5v 1.8 or 2 A).

My code:

Servo myservo; 

    void setup() {
     pinMode(24, INPUT);

    void loop() {
     if(digitalRead(24) == HIGH){

All of this works fine for the first ~10 hours. After that the arduino just shuts down. The power led of the arduino isn't lit up. Disconnecting the adapter and reconnecting it or pressing the reset button of the arduino doesn't work. I Have to wait for a couple of minutes with the adapter disconnected and reconnect it. After that it works fine for the next ~10 hours.

Seems like a hardware issue, but I'm not sure what exactly fails and why.

  • You should not route power for the servo through the Arduino. It needs its own connection to a supply capable of handling its stall current, which may well exceed an ampere. May 18, 2016 at 15:25

3 Answers 3


I assume your charger is connecting to the USB port of the Mega2560.

That USB port has a polyfuse (actually a special type of positive-coefficient thermistor) which is normally rated at around 500mA (polyfuses are a bit woolly with their ratings since they are heat based).

If you are drawing near that limit of current the fuse will be gradually heating up. I would think that after 10 hours it may have reached its threshold temperature and thus switches the power off.

Disconnecting the power and allowing it to cool down would then make the board work again.

How can you test it? Well, next time it switches itself off try bypassing the polyfuse (tweezers would be good to do that with) to see if the power LED turns on again.

enter image description here

  • Yes, it's connected to the usb port. The polyfuse indeed seems like a logical place to look for the issue. I will try your suggestion. Thanks. May 18, 2016 at 16:24

The power led of the arduino isn't lit up.

The power LED is implemented in hardware, basically, if it's not lit, it won't work.

Find the problems' (power?)source

After the 10h operation, your Arduino isn't on anymore.

Does the power supply still have 5V available at that point? Or does your Arduino's chips get hot or short-circuit the supply?

Exclude as much variables as possible

You don't know what the problem is, it could be:

  • The supply
  • The Arduino
  • The Servo
  • The PIR

Try another supply (preferably through the barrel jack, since it's regulated) (The supply may have some "protection" to avoid it being on too long).

Try another Arduino (unlikely?).

Try no servo & pir connected. (They may draw too much current, so the Arduino shuts down or create electrical noise.)

  • 1
    Yes, I'm trying out a new supply now, the difficulty with finding the problem is that every time I change something, I have to wait for 10 hours to see if there is difference :(. The arduino doesn't get hot, I tested that. May 18, 2016 at 9:57
  • @MeesterPatat, atleast you can do something else in that 10 hours ;) But yeah, welcome to the world of testing ;D It might be a good idea to make "test cases" or atleast think very well of what you're going to test, what the result should be and why ;)
    – aaa
    May 18, 2016 at 12:30

I'm just going to hazard a guess: Your 5v line isn't staying at 5v because of the servo. They draw massive amounts of power quickly, and can wreck a lot of havoc. Many times electronics "kinda" work after voltage drops, but will lock up or glitch eventually. (To get confirmation that this is the problem, monitor your 5v power with an oscilloscope. Set a trigger at 4.5v and try to capture the voltage drops.)

If that is the problem, you need better isolation on your digital power (running the arduino) and your analog power (running the servo.) Two ideas to try (you may need both):

1) Get a big cap (say 100 uF or more), then put it across your power to the arduino. If it's big enough, it will prevent your 5v from sagging. It may be expensive to get a big enough cap.

2) Instead of connecting your servo directly to 5v, put a small resistor (say 10 ohm) between them. Now when he tries to suck all the power, it will get resistance, which will limit the current. The bigger the resistor the better the isolation, but too big will prevent your servo from working. (And may heat up your resistor).

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.