servo stop

Newbie here…
i have programed the futaba s3003 server to run via IR to move from 0 to 180 deg and back.
the servo stops at 0 and 180 and vibrates a bit.
what code to light a blue led at 180 and red led at 0?
I am using pin 9 to signal servo .
any way to incorporate code that doesn’t read angles but reads stop position?

any help appreciated
smdtech (its not what it seems)

Show us your existing code so we can recommend changes.

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

#define IR_RECEIVER_PIN 6
#define SERVO_PIN 9

// Arduino IR remote control
#define BT_RIGHT_PRESSED 2704 // right button keep pressed
#define BT_RIGHT_TOUCH 16 // right button single touch
#define BT_LEFT_PRESSED 2640 // left button keep pressed
#define BT_LEFT_TOUCH 17 // left button single touch
#define BT_UP_PRESSED 144 // up button keep pressed
#define BT_UP_TOUCH 1168 // up button single touch
#define BT_DOWN_PRESSED 2192 // down button keep pressed
#define BT_DOWN_TOUCH 3216 // down button single touch
#define BT_ON_OFF_PRESSED 2060 // On/Off button keep pressed
#define BT_ON_OFF_TOUCH 12 // On/OFF button single touch
#define BT_AV_TV_PRESSED 2059 // AV/TV button keep pressed
#define BT_AV_TV_TOUCH 11 // AV/TV button sigle touch

IRrecv irrecv(IR_RECEIVER_PIN);
decode_results results;

#define MIN_PULSE 510
#define MAX_PULSE 2500
#define CENTER_PULSE (MIN_PULSE + (MAX_PULSE - MIN_PULSE) / 2)

#define FINE_TUNE_STEP 1
#define NORMAL_TUNE_STEP 15

int capacitorPosition = CENTER_PULSE; // The capacitor starts in the center position;

int tuneStep = NORMAL_TUNE_STEP; // The tune mode start in normal steps

Servo capacitor;
int increment = 0;

void setup() {

// declare output pins
pinMode(SERVO_PIN, OUTPUT);

irrecv.enableIRIn(); // enable IR reading

capacitor.attach(SERVO_PIN,MIN_PULSE,MAX_PULSE); // attaches the servo

capacitor.writeMicroseconds( CENTER_PULSE );
delay(1000);

Serial.begin (9600);
}

void loop() {

increment = 0;

// check infrared
if (irrecv.decode(&results)) {

Serial.println(results.value);

switch (results.value) {
case BT_RIGHT_PRESSED:
case BT_RIGHT_TOUCH:
increment = tuneStep;
break;
case BT_LEFT_PRESSED:
case BT_LEFT_TOUCH:
increment = -tuneStep;
break;
case BT_UP_PRESSED:
case BT_UP_TOUCH:
increment = (tuneStep * -2);
break;
case BT_DOWN_PRESSED:
case BT_DOWN_TOUCH:
increment = (tuneStep * 2);
break;
case BT_ON_OFF_PRESSED:
case BT_ON_OFF_TOUCH:
capacitorPosition = CENTER_PULSE;
capacitor.writeMicroseconds( capacitorPosition );
break;
case BT_AV_TV_PRESSED:
case BT_AV_TV_TOUCH:
break;
default:
break;
}

irrecv.resume(); // Recebe o proximo valor
}

if ( increment ) {
capacitorPosition += increment;
if ( capacitorPosition < MIN_PULSE) {
capacitorPosition = MIN_PULSE;
}
else if ( capacitorPosition > MAX_PULSE ) {
capacitorPosition = MAX_PULSE;
}
else {
capacitor.writeMicroseconds(capacitorPosition);
delay(10);
}
}

}

smdtech: what code to light a blue led at 180 and red led at 0?

Assuming the LED draws less than about 20mA, wire it between a digital pin and ground with a suitable current limiting resistor in series. Use pinMode to set the pin as an output, and digitalWrite to turn it on and off.

In my experience there is a lot of variation between servos. For example I have two (Futaba, I think) and one has its extremes at 150 and 2300 milliseconds and the other at 550 and 2500. By the way these move through about 200 degrees.

I suspect that the vibration is caused by trying to make them go too far. Experiment with slightly smaller angles and see does it stop.

...R

i got the digital write to turn the led on/off, but how do i set the parameter so the led turns on when the end of servo travel is reached?

smdtech: how do i set the parameter so the led turns on when the end of servo travel is reached?

Arrange for the code that switches the LED to execute when the end of servo travel is reached. You might already have some code that executes at the right point, in which case you could just add the call. Otherwise, you'd need to add code to test whether the end of servo travel had been reached, and switch the LED appropriately when it has.

PeterH:

smdtech: how do i set the parameter so the led turns on when the end of servo travel is reached?

Arrange for the code that switches the LED to execute when the end of servo travel is reached. You might already have some code that executes at the right point, in which case you could just add the call. Otherwise, you'd need to add code to test whether the end of servo travel had been reached, and switch the LED appropriately when it has.

   else {   
          capacitor.writeMicroseconds(capacitorPosition);
          if (capacitorPosition ==  MIN_PULSE || capacitorPosition == MAX_PULSE )
                 // Insert code to turn LED on
         else
                // Insert code to turn LED off
          delay(10);
    }

Thank you ! That's what I have been looking for.

Smdtech