SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By jolijar
I am trying to use the Arduino to turn on a servo, move it to a position, then turn the servo back off. I need the servo to be turned off because of power consumption issues among other reasons.

Here is my code
Code: Select all
 #include <Servo.h> 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
int pos = 0;    // variable to store the servo position 
int Servo = 5;                                        // Servo power connected to pin 5

void setup() 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
  pinMode(Servo, OUTPUT);                                 // Set a digital pin for the GPS Power
void loop() 
  digitalWrite(Servo, HIGH);                              // Turn the Servo on
   myservo.write(10);              // tell servo to go to position 
  digitalWrite(Servo, LOW);                              // Turn the Servo off
       digitalWrite(Servo, HIGH);                              // Turn the servo on  
    myservo.write(105);              // tell servo to go to position 
 digitalWrite(Servo, LOW);                              // Turn the Servo off
It works when I have the power line connected to the 5v pin on the Arduino however it will not work when it is plugged into pin 5 (or any other pin I set it to for that matter)

I use this same method successfully to power a GPS unit. Any ideas on why it will not work?

I thought maybe adding delays after the servo high and before the servo low might help but it does not.

Pin 5 reads 4.75v
5v Pin reads 4.80v
By trialex
An arduino digital pin can supply ~40mA of current.

Your servo power input needs more than that - your GPS doesn't

Look for examples that show how to use a transistor to switch high current (or high voltage) lines.
By jolijar
ok I got it working with a NPN transistor however even with the power to the transistor off the servo still makes noise. I can stop the noise by gently moving the servo arm (attached to a lock) I will not be able to do this when the unit is in operation. It is so loud you can hear it from several feet away. I don't care how much noise it makes while it is moving but after it is done then I want it to be quiet. Any Ideas on how to make it quiet?
By tecoist
If the servo is making noise, you haven't powered it down. No power, no noise. I'd start looking there.
By jolijar
I measured the voltage and it goes from 4.8v to .01v
I guess the transistor has some leak-through Maybe if I double up on the transistors and then use two digital ports to control the servo.