power off servo with transistor

Hi there,

I would greatly appreciate if someone could help me figure how I can use a transistor to power off servo in code so that I can drive it manually without detaching any wires. I'm using 3 servos in my project connected to a 5V battery in parallel which are driven by sensors. I would like it to turn off when sensor reaches a certain value.

Will servo.detach() not do what you want?

That stops the library sending the position update pulse every 20ms so the motor wont “hunt” for its position. I assume you’re worried about energy usage?

There might be a very small current drawn by a detach()-ed servo, I’ve never measured it, but I doubt if it’s significant.

I tried that method but it holds its position resisting to move and I want to manually be able to turn it

Hmmmm well all the servos I've fiddled with don't hold position when the pulse stops, but I suppose some servos could have the electronics to do so.

edit.... in fact I vaguely recall reading that on the forum some time back.

Fruit123: how I can use a transistor to power off servo in code so that I can drive it manually without detaching any wires.

http://www.ermicro.com/blog/?p=423

dmjlambert: http://www.ermicro.com/blog/?p=423

If one used a transistor to switch a servo, would one need the flyback diode? The motor inside is an inductor of course, but does the back emf get out through the servo's electronics?

Probably. I don't think it would hurt to have the diode in place.

The OP is venturing a little bit into the unusual, I don't know if many people have done exactly this. It would be nice to hear back about success/failures.

dmjlambert: The OP is venturing a little bit into the unusual, I don't know if many people have done exactly this. It would be nice to hear back about success/failures.

I do think it's been asked before, but don't recall any outcomes. Zoomkat will be along with a suggestion i'm sure :)

I indeed never saw a servo that actively kept it's position without pulses (servo.detach() ).

Don't know about the diode. It can't hurt but don't know if it really does anything. The servo must have a build in H-bridge etc... So I think a diode to Vcc (when using a PNP) might work better as I expect there to be a diode to GND already in the servo.

RC Servos will hold position for a while when pulses vanish - otherwise intermittent radio contact would cause an RC plane to immediately crash, which is dumb - of course how long an outage before they give up is down to the manufacturer, they will all have different ideas of what's best, and many will have this as a programmable parameter too. Cheap RC servos are built for one purpose, RC model control, so bear that in mind when expecting them to perform a different function.

This works with a small 6 volt gearmotor, the FQP27P06 is overkill but all I had.
Use 6V instead of the 12V shown.



motorsw.png

All RC servo’s I have all stop being active like immediately. That’s at least < 0,5second. Letting the servo be the fail safe for radio communication would also be pretty stupid… Isn’t that a task for the receiver? Btw, I said it’s stupid, not that no manufacturer does it.

6V is out of spec for some servos, normal voltage is still 5v. Then you can control the MOSFET directly as well.

My servomotor spec: http://www.hobbyking.co.uk/hobbyking/store/__25455__Turnigy_8482_XGD_11HMB_Digital_Servo_DS_Mini_Servo_3_0kg_0_12sec_11g.html

Please could someone help me figure out how to control power of servomotor using a transistor circuit. I'm really struggling to build the circuit. I want the servomotor to automatically power off(no buttons) when it reaches a certain angle so it doesn't hold its position and still allows to be turned manually by hand. If there is better way than using a transistor to control the power please let me know.

Thank you in advance Any help will be much appreciated

Power control circuits are already posted here. So what's the problem?

And are you really sure you did a proper detach()? (Maybe you attach() it somewhere else again by accident?) Can you show us code?

#include <Servo.h> 
String readString;
Servo myservo;  // create servo object to control a servo 
               // twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position 
int servodata;
void setup() 
{
 Serial.begin(9600);  
 Serial.println("Ready");

} 

void loop() 
{ if (Serial.available() > 0)
 {
  servodata = Serial.read();
   
   if(servodata == '1') 
   {
      Serial.println("servo on"); 
      myservo.attach(9);
     
 for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees 
 {                                  // in steps of 1 degree 
   myservo.write(pos);              // tell servo to go to position in variable 'pos' 
   delay(15);                       // waits 15ms for the servo to reach the position 
  
 
 } 
 for(pos = 180; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees 
 {                                
   myservo.write(pos);              // tell servo to go to position in variable 'pos' 
   delay(15);                       // waits 15ms for the servo to reach the position 
   
 } 
   }
 }

else if(servodata == '2') 
   {
      Serial.println("servo off"); 
      myservo.detach();
}
}

This code seems to hold its position when i press 2, but i want to be able to turn it manually when i press 2 i.e. power it off

Not to be picky but at 22 posts, you should know to use code tags. Edit the post, select the code, hit the </> icon top left.

Code in
{
code tags
}
looks like this

Wow, you realy know how to mess up indentation!

#include <Servo.h>
//String readString; //evil
Servo myservo;  // create servo object to control a servo
               // twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position
int servodata;
void setup()
{
 Serial.begin(9600);  
 Serial.println("Ready");

}

void loop()
{ 
  if (Serial.available() > 0)
  {
    servodata = Serial.read();
     
    if(servodata == '1')
    {
      Serial.println("servo on");
      myservo.attach(9);
       
      for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
      {                                  // in steps of 1 degree
        myservo.write(pos);              // tell servo to go to position in variable 'pos'
        delay(15);                       // waits 15ms for the servo to reach the position
      }
      
      for(pos = 180; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees
      {                                
        myservo.write(pos);              // tell servo to go to position in variable 'pos'
        delay(15);                       // waits 15ms for the servo to reach the position
      }
    }
  }

  else if(servodata == '2')
  {
    Serial.println("servo off");
    myservo.detach();
  }
}

Looks wait better already.

But the code itself looks okay. But can you do two test? First, load this sketch. Can you move the servo before you send anything over serial?

And with this simple sketch:

#include <Servo.h>
//String readString; //evil
Servo myservo;  // create servo object to control a servo
               // twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position
int servodata;
void setup()
{ 
  Serial.begin(9600);
  Serial.println("Start");
  
  myservo.attach(9);
  delay(1000);
  myservo.detach();
  Serial.println("Detached");

}

void loop()
{ 
  
}

Can you move the servo after the delay of 1 second (after it printed detached on serial monitor)?

septillion:
Wow, you realy know how to mess up indentation!

#include <Servo.h>

//String readString; //evil
Servo myservo;  // create servo object to control a servo
              // twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position
int servodata;
void setup()
{
Serial.begin(9600); 
Serial.println(“Ready”);

}

void loop()
{
  if (Serial.available() > 0)
  {
    servodata = Serial.read();
   
    if(servodata == ‘1’)
    {
      Serial.println(“servo on”);
      myservo.attach(9);
     
      for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
      {                                  // in steps of 1 degree
        myservo.write(pos);              // tell servo to go to position in variable ‘pos’
        delay(15);                      // waits 15ms for the servo to reach the position
      }
     
      for(pos = 180; pos>=0; pos-=1)    // goes from 180 degrees to 0 degrees
      {                               
        myservo.write(pos);              // tell servo to go to position in variable ‘pos’
        delay(15);                      // waits 15ms for the servo to reach the position
      }
    }
  }

else if(servodata == ‘2’)
  {
    Serial.println(“servo off”);
    myservo.detach();
  }
}



Looks wait better already.

But the code itself looks okay. But can you do two test? First, load this sketch. Can you move the servo before you send anything over serial?

And with this simple sketch:


#include <Servo.h>
//String readString; //evil
Servo myservo;  // create servo object to control a servo
              // twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position
int servodata;
void setup()
{
  Serial.begin(9600);
  Serial.println(“Start”);
 
  myservo.attach(9);
  delay(1000);
  myservo.detach();
  Serial.println(“Detached”);

}

void loop()
{
 
}



Can you move the servo after the delay of 1 second (after it printed detached on serial monitor)?

Thanks a lot for taking the time to help but both ways resist the movement of servo

And you can move it when it's unplugged?

If so then yeah, you're just unlucky with the choice of servo. Then just build one of the suggested circuits to power it off.