Attach and detach

I seemed to have attached(11) properly, but when I went to detach(), it did not detach. I said detach(), but nothing happened. I said detach(11), but I got an error message.

????

Attach and detach what? Which library?

Attach MegaServo and Detach MegaServo

detach does not take a parameter - it detaches whatever pin was attached.

see: http://arduino.cc/en/Reference/ServoDetach

you simply do:
myServo.detach() ;

edit:
I just double checked using a logic analyzer to view the pulses on the pins to make sure that a channel does stop pulsing when detached and starts pulsing when attached again.

// detach test
// sending the channel number (0 through 11) followed by ] detaches a servo pin 
// sending the channel followed by [ re-attaches the servo pin
#include <MegaServo.h> 

#define NBR_SERVOS 12         // the number of servos, up to 48 for Mega, 12 for other boards
#define FIRST_SERVO_PIN 2

MegaServo Servos[NBR_SERVOS] ; // max servos is 48 for mega, 12 for other boards

void setup() 
{ 
  Serial.begin(9600); 
  for(int i=0; i < NBR_SERVOS; i++)
    Servos[i].attach(FIRST_SERVO_PIN +i);  
} 


void loop()
{
  static int Channel = 0;

  if ( Serial.available())
  {
    char ch = Serial.read();

    if(ch >= '0' && ch <= '9')              // is ch a number?  
      Channel = Channel * 10 + ch - '0';           // yes, accumulate the value
    else if (ch == '[')
    {
      if(Channel >=0 && Channel < NBR_SERVOS){    
         Servos[Channel].attach(FIRST_SERVO_PIN +Channel); 
         Serial.print("Attaching servo on pin "); 
         Serial.println(FIRST_SERVO_PIN + Channel, DEC);    
      }
      Channel = 0;  
    }
    else if (ch == ']')
    {
      if(Channel >=0 && Channel < NBR_SERVOS){
         Servos[Channel].detach(); 
         Serial.print("Detaching servo on pin "); 
         Serial.println(FIRST_SERVO_PIN + Channel, DEC);    
      }
      Channel = 0;  
    }
  }
}

Do you want to post the code you are using to test.

Thanks, Mem. I don’t always want to waste valuable space on this forum for so many Thanks, but they are all in my heart. I apreciate anything that anyone does to speedup my robots progress.

Here is my code:

#include <MegaServo.h>
MegaServo myservo;

// Begin Robot Code

int pos =0; //brow position 0 = UP // 25-28 = down
int micVal; //microphone
int cdsVal; //photocell
int irLval; // Left IR
int irCval; // Center IR
int irRval; // Right IR
int irRRval; //Rear IR
int i; // Generic Counter
int x; // Generic Counter
int PLval; // Pulse Width for Left Servo
int PRval; // Pulse Width for Right Servo
int cntr; // Generic Counter Used for Determining amt. of Object Detections
int counter; // Generic Counter
int clrpth; // amt. of Milliseconds Of Unobstructed Path
int objdet; // Time an Object was Detected
int task; // Routine to Follow for Clearest Path
int pwm; // Pulse Width for Pan Servo
boolean add; // Whether to Increment or Decrement PW Value for Pan Servo
int distance; // Distance to Object Detected via Ultrasonic Ranger
int oldDistance; // Previous Distance Value Read from Ultrasonic Ranger

float scale = 1.9866666666666666666666666666667; // Not Currently Used

int LeftPin = 6; // Left Servo
int RightPin = 9; // Right Servo
int PiezoPin = 4; // Piezo
int PingServoPin = 5; // Pan Servo
int irLPin = 0; // Analog 0; Left IR
int irCPin = 1; // Analog 1; Center IR
int irRPin = 2; // Analog 2; Right IR
int irRRPin = 3; // Analog 3; Rear IR
int ultraSoundSignal = 7; // Ultrasound signal pin
int val = 0; // Used for Ultrasonic Ranger
int ultrasoundValue = 0; // Raw Distance Val
int oldUltrasoundValue; // Not used
int pulseCount; // Generic Counter
int timecount = 0; // Echo counter
int ledPin = 13; // LED connected to digital pin 13
int SPKR = 4;

#define BAUD 9600
#define CmConstant 1/29.034

void setup() {
myservo.attach(11);
//pos = 0;
//myservo.write(pos);
//delay (200);
pos=40;
myservo.write(pos);
//delay(200);
myservo.detach();

Serial.begin(9600);
pinMode(PiezoPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(LeftPin, OUTPUT);
pinMode(RightPin, OUTPUT);
pinMode(PingServoPin, OUTPUT);
pinMode(irLPin, INPUT);
pinMode(irCPin, INPUT);
pinMode(irRPin, INPUT);
pinMode(irRRPin, INPUT);
// Beep!
{
for (int i = 0; i<500; i++) { // generate a 1KHz tone for 1/2 second
digitalWrite(SPKR, HIGH);
delayMicroseconds(500);
digitalWrite(SPKR, LOW);
delayMicroseconds(500);
}
}
//brows control

// pos = 0;
// myservo.write(pos);
// delay(2000);

for(i = 0; i < 20; i++) {
digitalWrite(PingServoPin, HIGH);
delayMicroseconds(655 * 2);
digitalWrite(PingServoPin, LOW);
delay(20);
}
ultrasoundValue = 600;
i = 0;
}

void loop()
{
//Scan();
Look();
Go();
}
void Look() {
irLval = analogRead(irLPin);
irCval = analogRead(irCPin);
irRval = analogRead(irRPin);

if(irLval > 200) {
PLval = 850;
PRval = 820;
x = 5;
cntr = cntr + 1;
clrpth = 0;
objdet = millis();
}
else if(irCval > 200) {
PLval = 850;
PRval = 820;
x = 10;
cntr = cntr + 1;
clrpth = 0;
objdet = millis();
}
else if(irRval > 200) {
PLval = 650;
PRval = 620;
x = 5;
cntr = cntr + 1;
clrpth = 0;
objdet = millis();
}
else {
x = 1;
PLval = 850;
PRval = 620;
counter = counter + 1;
clrpth = (millis() - objdet);
if(add == true) {
pwm = pwm + 50;
}
else if(add == false) {
pwm = pwm - 50;
}
if(pwm < 400) {
pwm = 400;
add = true;
}
if(pwm > 950) {
pwm = 950;
add = false;
}
digitalWrite(PingServoPin, HIGH);
delayMicroseconds(pwm * 2);
digitalWrite(PingServoPin, LOW);
delay(20);
readPing();
if(ultrasoundValue < 500) {
cntr = cntr + 1;
switch(pwm) {
case 400:
x = 7;
PLval = 650;
PRval = 650;
Go();
break;
case 500:
x = 10;
PLval = 650;
PRval = 650;
Go();
break;
case 600:
x = 14;
PLval = 850;
PRval = 850;
Go();
break;
case 700:
x = 10;
PLval = 850;
PRval = 850;
Go();
break;
case 950:
x = 7;
PLval = 850;
PRval = 850;
Go();
break;
}
}
}

if(cntr > 25 && clrpth < 2000) {
clrpth = 0;
cntr = 0;
Scan();
}
}
void Go() {
for(i = 0; i < x; i++) {
digitalWrite(LeftPin, HIGH);
delayMicroseconds(PLval * 2);
digitalWrite(LeftPin, LOW);
digitalWrite(RightPin, HIGH);
delayMicroseconds(PRval * 2);
digitalWrite(RightPin, LOW);
delay(20);
}
}
void readPing() { // Get Distance from Ultrasonic Ranger
timecount = 0;
val = 0;
pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output

/* Send low-high-low pulse to activate the trigger pulse of the sensor


*/

digitalWrite(ultraSoundSignal, LOW); // Send low pulse
delayMicroseconds(2); // Wait for 2 microseconds
digitalWrite(ultraSoundSignal, HIGH); // Send high pulse
delayMicroseconds(5); // Wait for 5 microseconds
digitalWrite(ultraSoundSignal, LOW); // Holdoff

/* Listening for echo pulse


*/

pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input
val = digitalRead(ultraSoundSignal); // Append signal value to val
while(val == LOW) { // Loop until pin reads a high value
val = digitalRead(ultraSoundSignal);
//pos = 0;
//myservo.write(pos);
//delay(2000);
}

while(val == HIGH) { // Loop until pin reads a high value
val = digitalRead(ultraSoundSignal);
timecount = timecount +1; // Count echo pulse time
}

/* Writing out values to the serial port


*/

ultrasoundValue = timecount; // Append echo pulse time to ultrasoundValue

//serialWrite(‘A’); // Example identifier for the sensor
//printInteger(ultrasoundValue);
//serialWrite(10);
//serialWrite(13);

/* Lite up LED if any value is passed by the echo pulse


*/

if(timecount > 0){
digitalWrite(ledPin, HIGH);
}
}
void Scan() { // Scan for the Clearest Path
oldDistance = 30;
task = 0;
for(i = 1; i < 5; i++) {
switch(i) {
case 1:
//Serial.println(“Pos. 1”);
pwm = 1125; /// incr. by 100 from 1085
break;
case 2:
//Serial.println(“Pos. 2”);
pwm = 850; //// increased by 100 from 850
break;
case 3:
//Serial.println(“Pos. 3”);
pwm = 400;
break;
case 4:
//Serial.println(“Pos. 4”);
pwm = 235;
break;
}
for(pulseCount = 0; pulseCount < 20; pulseCount++) { // Adjust Pan Servo and Read USR
digitalWrite(PingServoPin, HIGH);
delayMicroseconds(pwm * 2);
digitalWrite(PingServoPin, LOW);
readPing();
delay(20);
}
distance = ((float)ultrasoundValue * CmConstant); // Calculate Distance in Cm
if(distance > oldDistance) { // If the Newest distance is longer, replace previous reading with it
oldDistance = distance;
task = i; // Set task equal to Pan Servo Position
}
}
distance = 50; // Prevents Scan from Looping
switch(task) { // Determine which task should be carried out
case 0: // Center was clearest
x = 28;
PLval = (850);
PRval = (850);
Go();
break;
case 1: // 90 degrees Left was Clearest
x = 14;
PLval = (650);
PRval = (650);
Go();
break;
case 2: // 45 degrees left
x = 7;
PLval = (650);
PRval = (650);
Go();
break;
case 3: // 45 degrees right
x = 7;
PLval = (850);
PRval = (850);
Go();
break;
case 4: // 90 degrees right
x = 14;
PLval = (850);
PRval = (850);
Go();
break;
}
}

// End Robot Code

I have a servo on pin(11). It is a small servo going to the robots eyebrows. I have done this before in Pbasic without a problem, but I am new to c. I made the eyebrows go up whenever the robot did something. Also, I made the ping servo turn to face the exact direction of what was seen. This was a very cool effect. I can't figure out for the life of me WHERE to place the BrowsUP and BrowsDOWN subroutine. When I placed them in several places, it stopped the robot from working properly. I can program them in a separate program to make them go up and down, etc. I haven't got the foggiest idea HOW I am going to make the ping servo track the movement of the subject it sees yet. Right now, the robot beeps and puts it's brows down. But, it holds them there very firmly and I thought it would be nice for it to relax once it gets to it's position and just let the gears hold it in place. zero is UP and 25-40 position is Down.

Hope this helps you understand my objectives.

Thanks,

:-)

[u]Please[/u] use the "code" button (looks like a #) on the toolbar when you're posting code.

Lets take this one step at a time. I would like to understand why you think detach is not working. The relevant part of the code you posted is this:

#include <MegaServo.h>
MegaServo myservo;


void setup() {
  myservo.attach(11);
  int pos=40;
  myservo.write(pos);
  myservo.detach();

}

void loop()
{

}

I don’t see anything later in the code that does another attach so the servo should not be attached after setup is completed. Do you agree and why do you think the servo is still being pulsed?

Please use the “code” button (looks like a #) on the toolbar when you’re posting code.

I second that, please listen to the man!

the reason I think the servo is still being pulsed is you can try to move it and it has LOTS of resistance.

OK, I got it better now. I placed a delay(200) in between the write and the detach statements.

Now, on to the other problems~!

I suggest you approach the problems by taking one step at a time. Get each of your functions working in isolation: ping, scan , movement etc. For each function write a test sketch that excercises that function so you can verify it works. That is not only easier for you to debug, its also easier for you to get help from others if you need it. when you are confident with each part, you will find it easier to put all the the pieces together.

that is kinda sorta what I am doing. I have the Brow subroutine made to go up or down. It works in setup, but when I place it anywhere else, for some reason the whole program gets screwed up. I just need to know WHERE to place it. You would think that with a function called look and go, I could place it right inside the go and tell it to lower the eyebrows because when it is moving, it has nothing in front of it. And place it elsewhere and tell it to lower the brows. But, when I place it, it seems to get lost in a loop and the robot Stops going and just shakes. Wierd.

But, you have given me good advice. I have made a baby step forward. I like to work on this and try to accomplish at least ONE step forward on my day off, then back to work. And if I can get more done, so much the better. But, that delay problem cost me 18 hours of experimenting. That is why I am thankful for this forum. :-)

OK, so here what I have now that is 100% working. It starts with a BEEP!, then it lowers the brows and rests them. All I have to do is place this same routine and change the val from 40 to zero and I have my bot seeing and raising brows. But, I have still not been able to figure out WHERE to place it. It should be when it is looking with PING or IR , I guess.

#include <MegaServo.h>
MegaServo myservo;

// Begin Robot Code
int pos =0;  //brow position 0 = UP // 25-28 = down
int micVal;  //microphone
int cdsVal;  //photocell
int irLval;  // Left IR
int irCval;  // Center IR
int irRval;  // Right IR
int irRRval; //Rear IR
int i;   // Generic Counter
int x;  // Generic Counter
int PLval;  // Pulse Width for Left Servo
int PRval;  // Pulse Width for Right Servo
int cntr;  // Generic Counter Used for Determining amt. of Object Detections
int counter; // Generic Counter
int clrpth;  // amt. of Milliseconds Of Unobstructed Path
int objdet;  // Time an Object was Detected
int task;  // Routine to Follow for Clearest Path
int pwm;  // Pulse Width for Pan Servo
boolean add;  // Whether to Increment or Decrement PW Value for Pan Servo
int distance;  // Distance to Object Detected via Ultrasonic Ranger
int oldDistance;  // Previous Distance Value Read from Ultrasonic Ranger

float scale = 1.9866666666666666666666666666667;  // *Not Currently Used*

int LeftPin = 6;  // Left Servo
int RightPin = 9;  // Right Servo
int PiezoPin = 4;  // Piezo
int PingServoPin = 5;  // Pan Servo
int irLPin = 0;            // Analog 0; Left IR
int irCPin = 1;            // Analog 1; Center IR
int irRPin = 2;            // Analog 2; Right IR
int irRRPin = 3;           // Analog 3; Rear IR
int ultraSoundSignal = 7; // Ultrasound signal pin
int val = 0;              // Used for Ultrasonic Ranger
int ultrasoundValue = 0;  // Raw Distance Val
int oldUltrasoundValue;  // *Not used*
int pulseCount;        // Generic Counter
int timecount = 0; // Echo counter
int ledPin = 13; // LED connected to digital pin 13
int SPKR = 4;

#define BAUD 9600
#define CmConstant 1/29.034

void setup() {
  myservo.attach(11);
  pos=40;
  myservo.write(pos);
  delay(200);
  myservo.detach();
  
  Serial.begin(9600);
  pinMode(PiezoPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(LeftPin, OUTPUT);
  pinMode(RightPin, OUTPUT);
  pinMode(PingServoPin, OUTPUT);
  pinMode(irLPin, INPUT);
  pinMode(irCPin, INPUT);
  pinMode(irRPin, INPUT);
  pinMode(irRRPin, INPUT);
  // Beep! 
  {
    for (int i = 0; i<500; i++) {  // generate a 1KHz tone for 1/2 second
      digitalWrite(SPKR, HIGH);
      delayMicroseconds(500);
      digitalWrite(SPKR, LOW);
      delayMicroseconds(500);
    } 
  }
  for(i = 0; i < 20; i++) {
    digitalWrite(PingServoPin, HIGH);
    delayMicroseconds(655 * 2);
    digitalWrite(PingServoPin, LOW);
    delay(20);
  }
  ultrasoundValue = 600;
  i = 0;      
}

void loop()
{
  //Scan();
  Look();
  Go();
}
void Look() {
  irLval = analogRead(irLPin);
  irCval = analogRead(irCPin);
  irRval = analogRead(irRPin);

  if(irLval > 200) {
    PLval = 850;
    PRval = 820;
    x = 5;
    cntr = cntr + 1;
    clrpth = 0;
    objdet = millis();
  }
  else if(irCval > 200) {
    PLval = 850;
    PRval = 820;
    x = 10;
    cntr = cntr + 1;
    clrpth = 0;
    objdet = millis();
  }
  else if(irRval > 200) {
    PLval = 650;
    PRval = 620;
    x = 5;
    cntr = cntr + 1;
    clrpth = 0;
    objdet = millis();
  }
  else {
    x = 1;
    PLval = 850;
    PRval = 620;
    counter = counter + 1;
    clrpth = (millis() - objdet);
    if(add == true) {
      pwm = pwm + 50;
    }
    else if(add == false) {
      pwm = pwm - 50;
    }
    if(pwm < 400) {
      pwm = 400;
      add = true;
    }
    if(pwm > 950) {
      pwm = 950;
      add = false;
    }
    digitalWrite(PingServoPin, HIGH);
    delayMicroseconds(pwm * 2);
    digitalWrite(PingServoPin, LOW);
    delay(20);
    readPing();
    if(ultrasoundValue < 500) {
      cntr = cntr + 1;
      switch(pwm) {
      case 400:
        x = 7;
        PLval = 650;
        PRval = 650;
        Go();
        break;
      case 500:
        x = 10;
        PLval = 650;
        PRval = 650;
        Go();
        break;
      case 600:
        x = 14;
        PLval = 850;
        PRval = 850;
        Go();
        break;
      case 700:
        x = 10;
        PLval = 850;
        PRval = 850;
        Go();
        break;
      case 950:
        x = 7;
        PLval = 850;
        PRval = 850;
        Go();
        break;
      }
    }
  }

  if(cntr > 25 && clrpth < 2000) {
    clrpth = 0;
    cntr = 0;
    Scan();
  }
}
void Go() {
  for(i = 0; i < x; i++) {
    digitalWrite(LeftPin, HIGH);
    delayMicroseconds(PLval * 2);
    digitalWrite(LeftPin, LOW);
    digitalWrite(RightPin, HIGH);
    delayMicroseconds(PRval * 2);
    digitalWrite(RightPin, LOW);
    delay(20);
  }
}
void readPing() {  // Get Distance from Ultrasonic Ranger
  timecount = 0;
  val = 0;
  pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output
  /* Send low-high-low pulse to activate the trigger pulse of the sensor
   * -------------------------------------------------------------------
   */
  digitalWrite(ultraSoundSignal, LOW); // Send low pulse
  delayMicroseconds(2); // Wait for 2 microseconds
  digitalWrite(ultraSoundSignal, HIGH); // Send high pulse
  delayMicroseconds(5); // Wait for 5 microseconds
  digitalWrite(ultraSoundSignal, LOW); // Holdoff
  /* Listening for echo pulse
   * -------------------------------------------------------------------
   */
  pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input
  val = digitalRead(ultraSoundSignal); // Append signal value to val
  while(val == LOW) { // Loop until pin reads a high value
    val = digitalRead(ultraSoundSignal);
  }
  while(val == HIGH) { // Loop until pin reads a high value
    val = digitalRead(ultraSoundSignal);
    timecount = timecount +1;            // Count echo pulse time
  }
  /* Writing out values to the serial port
   * -------------------------------------------------------------------
   */
  ultrasoundValue = timecount; // Append echo pulse time to ultrasoundValue
  /* Lite up LED if any value is passed by the echo pulse
   * -------------------------------------------------------------------
   */
  if(timecount > 0){
    digitalWrite(ledPin, HIGH);
      }
} 
void Scan() {   // Scan for the Clearest Path
  oldDistance = 30;
  task = 0;
  for(i = 1; i < 5; i++) {
    switch(i) {
    case 1:
      //Serial.println("Pos. 1");
      pwm = 1125;    ///  incr. by 100 from 1085
      break;
    case 2:
      //Serial.println("Pos. 2");
      pwm = 850; //// increased by 100 from 850
      break;
    case 3:
      //Serial.println("Pos. 3");
      pwm = 400;
      break;
    case 4:
      //Serial.println("Pos. 4");
      pwm = 235;
      break;
    }
    for(pulseCount = 0; pulseCount < 20; pulseCount++) {  // Adjust Pan Servo and Read USR
      digitalWrite(PingServoPin, HIGH);
      delayMicroseconds(pwm * 2);
      digitalWrite(PingServoPin, LOW);
      readPing();
      delay(20);
    }
    distance = ((float)ultrasoundValue * CmConstant);   // Calculate Distance in Cm
    if(distance > oldDistance) {  // If the Newest distance is longer, replace previous reading with it
      oldDistance = distance;
      task = i;   // Set task equal to Pan Servo Position
    }
  }
  distance = 50;  // Prevents Scan from Looping
  switch(task) {   // Determine which task should be carried out
  case 0:  // Center was clearest
    x = 28;
    PLval = (850);
    PRval = (850);
    Go();
    break;
  case 1:  // 90 degrees Left was Clearest
    x = 14;
    PLval = (650);
    PRval = (650);
    Go();
    break;
  case 2:  // 45 degrees left
    x = 7;
    PLval = (650);
    PRval = (650);
    Go();
    break;
  case 3:  // 45 degrees right
    x = 7;
    PLval = (850);
    PRval = (850);
    Go();
    break;
  case 4:  // 90 degrees right
    x = 14;
    PLval = (850);
    PRval = (850);
    Go();
    break;
  }
}

// End Robot Code

OK, I got it better now. I placed a delay(200) in between the write and the detach statements.

But, that delay problem cost me 18 hours of experimenting

Sorry to go back to your earlier post, but as this thread is titled ‘Attach and detach’ I would like to understand what you are saying.

It should not matter if detach is called after a delay or immediately. The servo that is detached should not begin another pulse immedialty after detach is called.

Something is wrong if you are seeing a different behaviour. Did you run the test code I posted in reply #7. If not and that does work for you then I hope that will provide evidence of the importance of simple test code for each function that you are having problems with. Spending a few minutes running a simple test can save hours looking for a needle in a haystack

To verify that a delay is not required, I ran the following code:

#include <MegaServo.h>
MegaServo myservo1;
MegaServo myservo2;
MegaServo myservo3;


void setup() {
  myservo1.attach(3);
  myservo2.attach(4);
  myservo3.attach(5);

  int pos=40;
  myservo1.write(pos);
  myservo2.write(pos);
  myservo3.write(pos);

  myservo1.detach();
  delay(20);
  myservo2.detach();
  delay(200);
  myservo3.detach();
  
  pinMode(6, OUTPUT); // this is just a trigger for the logic analyzer

}

void loop()
{  
 digitalWrite(6, HIGH);
 delay(1);
 digitalWrite(6, LOW);
 delay(1);  
}

The result were that no servos were pulsing by the time loop started sending the marker pulses on pin 6. This was verified by monitoring the pin state using a logic analyzer.

Servos on Pins 3 and 4 detached so quickly they never had time to produce any pulses on their pins. The servo on pin 5 (the one with the 200ms delay) produced 10 pulses and stopped just before the code in loop started producing the first marker pulses on pin 6.

In short, the servo code responded immediately to the detach command – with or without a delay after the attach.

If you run that code with your servo attached to pin 3 do you think it is being pulsed?

I realized that pin 11 was being pulsed. That was the browservo. Because, it was being magnetically held there.

I ran your code and changed it to the pins that matched my setup. Your code ran fine without the delay.

I did notice on mine that I am having a DCpoweJack problem that I have to correct. I will do that and be right back.

I am back now. I had really thick wires comming from the battery going into a RadioShack Plug that I wired. I do a good job of wiring, but the wires were too big to have room to place the plastic shield around them and the plug. So, I just made a pigtail out of a factory power plug that I spliced. It is going to work better now.

Now back to the project at hand, knowing Where to place the subroutine to raise the brows and make another subroutine to have the PING Servo track the item that either Ping Or IR senses. Or should I move the next step to another subject line since I am attaching an detaching now fine?

I realized that pin 11 was being pulsed. That was the brow servo. Because, it was being magnetically held there.

I don't understand what that means, could you clarify if your problem was with the detach function or was there some other issue.

The code posted in reply#7 attached and detached pin 11. Your replies #8 and #9 seem to be saying that the servo only appeared to detach after a delay. Did you actually try to run the code posted in reply#7? If so, did it detach?

The code posted in reply#7 attached and detached pin 11. Your replies #8 and #9 seem to be saying that the servo only appeared to detach after a delay. Did you actually try to run the code posted in reply#7? If so, did it detach?

I ran your code and it worked fine. It all started working fine with or without the delay as you said. I am now moving on to my OTHER problem of trying to know WHERE to place the subroutine to make the brows move up when it notices something and also track the object with the ping and IR sensors to the PING servo

Can you get the brows to move as you want in a test sketch, perhaps triggered by a switch? Do you think your problem is that you don't have a working function that moves the brows as you need, or can you get the brows moving ok but you can't get the thing that triggers the brows to work?

The test sketch works fine. I just need to know where to place them for maximum effect. I tried so many the other night but it did not work. I have just found a place that works for part of it. Now, I have to find the other part. I will let you know as it changes. I am happy with my progress today so far.

:slight_smile: