Go Down

Topic: Arduino making USB disconnected noise about every 2 seconds (Read 140 times) previous topic - next topic

shane_grover

Hello all,

I seem to be having an issue with my Arduino of some sorts but I can not find out what is causing it.

So, when a servo is connected to the Arduino, the 'L' button will flash rapidly about 3 times and the one button will quickly blink/ become more dark. The servo will jitter in relation to the on button blinking and when the servo jitters my laptop will make that noise that a USB has been disconnected. I have tested with 3 different servos, and the code runs fine and everything when the servo is disconnected.

Here is the code just in case thats where the issue is coming from.

#include <Servo.h>
Servo myservo;
int pos = 90; 

void setup() {
  pinMode(13, OUTPUT); // setup pin 13 as output
  Serial.begin(9600);          // begin serial communication
    myservo.attach(9);
}

/* Function to flash LED for a specified number of milliseconds */
void blinkLED(int n) {
  digitalWrite(13, HIGH);   // turn the LED
  delay(n);                           // wait for n milliseconds
  digitalWrite(13, LOW);   // turn the LED off
}
int laser = 13;

/* Fires laser for n milliseconds */
void fireLaser(int n)
{
  digitalWrite(laser, HIGH); // Set laser pin to +5V
  delay(n);                             // Delay for n milliseconds
 
  Serial.print("Fire!");          // Print string
 
  digitalWrite(laser, LOW);  // Set laser pin to 0V
  delay(500);                         // Delay 500 milliseconds
} // end fireLaser()

void moveservop(int n)
{
     pos += n;                // Increment position by 1 point (-0.5 deg)
    //printPosition(pos); // Print updated servo position to serial monitor
    Serial.print("Left!");
}

void moveservom(int n)
{
     pos -= n;                 // Decrement position by 1 point (+0.5 deg)
    //printPosition(pos); // Print updated servo position to serial monitor
    Serial.print("Right");
  }


void loop() {
  char c = Serial.read(); // Read serial input character
 
  if (c == ' ')         // If spacebar pressed
  {
    fireLaser(200); // Fire laser diode
  }  // end if
 
  if (c == 'a' && pos <= 179)        // If 'a' pressed and position not already at 180
  {
    moveservop(1);                // Move servo
  }
  if (c == 'd' && pos >= 1) // Otherwise if 'd' pressed and position not already at 0
  {
    moveservom(1);              //Move servo
  }
}

Thank you all in advance!

spycatcher2k

Are you powering the Servo from the Arduino? If so, this is the problem. Don't power anything from the Arduino, especially motors.
Mrs Drew
-=-
http://www.uk-pcb.co.uk - UK PCB Fab Company
I will design & code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.

Go Up