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
Servo:
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() {
myservo.attach(11);
pinMode(24, INPUT);
}
void loop() {
if(digitalRead(24) == HIGH){
myservo.write(0);
delay(500);
myservo.write(180);
delay(500);
}
}
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.