My Arduino keeps resetting as soon as my continuous servo finishes the first 2 commands

#include <Servo.h>

Servo myservo;

void setup() {
  myservo.attach(9); 
}

void loop() {
  myservo.write(35); 

  delay(6000);

  myservo.write(90); 

  delay(3000); 

  myservo.write(135); 

  delay(6000); 
  
}

I have my arduino on board usb connector hooked up to an external power supply too (its an old one so it doesn't stop if the current drawn from it is low enough) (Im using a MG995r servo if that changes anything)

Welcome to the forum

How is the servo powered, ie, where are its 5V and GND wires connected to ?

Is there any load on the servo ?

The servo is connected to the 5v pin the Arduino board and the ground is too, should I hook up the power pin to an external power source and the ground too? (the is no load on it whatsoever)

Yes. Power the servo directly from an external source with a common GND connection. If you have a DMM then monitor the the voltage of the power supply

So I should just conect the negative wire from the supply to the arduino ground? And the servo ground pin to the ground pin shared by both the arduino and supply? And for the positive wire (on the power supply), should i just connect it directly to the servo power pin?
Sorry for putting so many questions, its my first project :smiling_face_with_tear:

That sounds correct

The servo is powered directly from the power supply, as is the Arduino (which board do you have ?). The GND connections are common to all devices and the servo data pin is connected to the chosen Arduino pin. Having common GND connections allows the devices to use the same reference point for signal levels

Arduino UNO R3 if I remember correctly , and the Arduino shares the positive wire too or is it just the servo that's connected to it?

The Uno needs to be powered so, yes, it needs to be connected to the 5V supply

Can't I add a 9v battery to the Arduino dc connector?

this is how I hooked up everything

You could, but such a battery will not supply the required current for very long

or use USB 3.x connector

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.