Project showcase
Control Servo Power with a Transistor

Control Servo Power with a Transistor © MIT

A simple method to power a servo on or off from the Arduino, using a NPN Darlington Transistor (TIP-120) and an Arduino.

  • 5,361 views
  • 1 comment
  • 9 respects

Components and supplies

About this project

Motivation

I was looking for an easy way to "cut" the power to a servo when it was not in use to conserve power and was surprised to see so few articles and blog posts on the subject. I found some, but usually using the wrong transistor or mechanical relays. I've found this method as the most elegant approach and thought it worth sharing. I'm not an electronics engineer, but from what I've read, this is the proper way to provide high current to a device using an Arduino.

Credit:

https://www.arduino.cc/en/Tutorial/TransistorMotorControl Thanks to Scott Fitzgerald for a great tutorial.

Reference:

A good reference for the Darlington Transistor including advantages and disadvantages:

http://www.electronics-tutorials.ws/transistor/darlington-transistor.html

Code

Sample Code for powering a servo on or off using a Darlington transistorArduino
/*
 Servo Power Control with a Transistor (TIP 120)

 Created on 9/8/2016
 by Kevin Gagnon 

 This example code is in the public domain.
 */

#include <Servo.h>
Servo servo;

int powerControl = 8;
int servoPin = 10;

void setup() {
  	//Debug
	Serial.begin(9600);
  	
  	// pin 8 to base of Transistor
  	pinMode(powerControl, OUTPUT);
  	Serial.println("Transistor base set to pin " + String(powerControl, DEC));
  	
  	//pin 10 to Servo signal line
  	pinMode(servoPin, OUTPUT);
	Serial.println("Servo signal set to pin " + String(servoPin, DEC));   	


}

void loop() {
  	
  
  	/*--------------------------------
	ATTACH servo signal to pin 10, turn
    ON servo power and MOVE (0 to 180)
    --------------------------------*/

    // turn on the pwm signal to the servo
  	servo.attach(servoPin);
  	Serial.println("Servo attached to " + String(servoPin, DEC));
  
  	// turn on servo power
    digitalWrite(powerControl, HIGH);
  	Serial.println("Servo Power is ON");
	
	//Sweep the servo 0 to 180
	for (int servoPosition = 0; servoPosition < 181; servoPosition += 5) {
    	servo.write(servoPosition);
      	Serial.println("Position: " + String(servoPosition, DEC));      
      	delay(15);
    }
	
  	//Wait for servo to execute last position
  	delay(500);
  	
  
  	/*--------------------------------
	Turn OFF servo, DETACH pin 10 and
    WAIT for 1 second
    --------------------------------*/  
  
	//turn off servo power
  	digitalWrite(powerControl, LOW);
  	Serial.println("Servo power is OFF");
  
  	//turn off the pwm signal to the servo
  	servo.detach();
  	Serial.println("Servo detached");
  
  	//wait for 1 second
  	delay(1000);
  
  	/*--------------------------------
	ATTACH servo signal to pin 10, turn
    ON servo power and MOVE (0 to 180)
    --------------------------------*/

  	// turn on the pwm signal to the servo
  	servo.attach(servoPin);
  	Serial.println("Servo attached to " + String(servoPin, DEC));  

	// turn on servo power
    digitalWrite(powerControl, HIGH);
  	Serial.println("Servo Power is ON");

  	//Sweep the servo 180 to 0
  	for (int servoPosition = 180; servoPosition >= 0; servoPosition -= 5) {
    	servo.write(servoPosition);
      	Serial.println("Position: " + String(servoPosition, DEC));
      	delay(15);
    }
  	
  	//Wait for servo to process last position
  	delay(500);
  
  
  	/*--------------------------------
	Turn OFF servo, DETACH pin 10 and
    WAIT for 1 second
    --------------------------------*/  
  
  	// turn off servo power
    digitalWrite(powerControl, LOW);
	Serial.println("Servo Power is OFF");
  
	//turn off the pwm signal to the servo
  	servo.detach();
  	Serial.println("Servo detached");
  
  	//wait for 1 second
  	Serial.println("Waiting for 1 sec...");
  	delay(1000);
  
  


}

Schematics

Wiring a TIP120 to control servo power with an Arduino digital pin.
Breadboard

Comments

Similar projects you might like

Servo Control with TV Remote Control

Project showcase by eldo85

  • 5,594 views
  • 5 comments
  • 17 respects

Arduino/Android - BLUETOOTH Multi Servo Motor Control

Project tutorial by Danny van den Brande

  • 13,196 views
  • 8 comments
  • 18 respects

Servo Control Panel

Project tutorial by dancili

  • 1,202 views
  • 0 comments
  • 6 respects

Take Control Over Lego Power Functions

Project tutorial by Patrick Müller

  • 43,673 views
  • 3 comments
  • 60 respects
Add projectSign up / Login