Help detaching servo

Hello,

I was wondering if anybody could help me detach my servo when it is not being moved. The servo is switching between two positions each time a button is pressed on an IR remote. There is also a relay switching between open and closed each time this button is pressed. I am hoping to get the servo to detach after it is moved each time.

Here is my code so far with out the ServoDetach:

#include <Servo.h>
#include <IRremote.h>

unsigned long Value1 = 0xFF02FD; // where XXXXXXXX is on our your remote's values (OK button)

int relay_pin = 13;
int recv_pin = 11;
int actual_state = LOW;

// Postions for even, odd clicks
const byte oddPosition = 160;
const byte evenPostion =  70;
int clickCount = 0; // # of clicks

IRrecv irrecv(recv_pin);
decode_results results;

Servo servo1;

void setup() {
  pinMode(relay_pin, OUTPUT);
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  servo1.attach(9); // attach servo to digital pin 9
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    if (results.value == Value1) { //  button
      actual_state = (actual_state == LOW) ? HIGH : LOW;
      digitalWrite(relay_pin, actual_state);
    }
    irrecv.resume(); // Receive the next value
    if(results.value == Value1) {

      // increment click count
      clickCount++;

      // move to even or odd position based on click count
      servo1.write( (clickCount % 2) ? oddPosition : evenPostion);

    }

  } 
}

Thank you all!

Why do you want to detach the servo?

I want to detach so that the servo doesn't chatter and make noise when it stays in one position. My other question is, do servos hold there position after they are detached?

My other question is, do servos hold there position after they are detached?

No. Which is why we wanted to know why you wanted to detach the servo.

A servo won't "chatter and make noise" unless it is overloaded or is being told to move in tiny amounts.