Here's the code I'm trying to run:
#include <Servo.h>
Servo servoRight;
void setup(){
Serial.begin(9600); //Serial Debugging
servoRight.attach(2); //Attach servo
}
void loop()
{
Serial.println("My sketch has started"); // Serial Debugging
delay(10000);
servoRight.write(180); //spin servo backwards
delay(10000); //wait ten seconds
servoRight.write(0); //Spin servo other way
}
It's very simple, just spin the servo ten seconds, then spin it the other way. (I'm using a continuous rotation servo). I'm using arduino uno and connecting it to the computer using the on board serial to usb connection. I upload the sketch, the lights on the board blink, and the ide says upload complete. And i have the uno selected under boards.
Here's My circuit setup:
It's exactly that, AND i have tried this with the breadboard and direct connection of servo to uno. I also have verified that the digital port is the same one in my code.
All that seems right I'm mostly sure.
Here's where the problem starts:
After the sketch gets uploaded, (with the circuit broken), I connect the power wire to the 5V slot and two things happen simultaneously:
- The arduino board instantly disconnects from the computer and draws only power, sending no data through.
- The servo begins to spin in one direction (good i suppose), 20 seconds later nothing happens, just keeps spinning.
I break the circuit and the uno reconnects to the computer. I've also tried the same procedure using the sweep example form the IDE, same results.
So what am I doing wrong exactly? Arduino issue or user error?