digitalWrite(3,LOW);

int switchState = 0;

  void setup(){
    pinMode(3,OUTPUT);
    pinMode(4,OUTPUT);
    pinMode(5,OUTPUT);
    pinMode(2,INPUT);
  }

  void loop(){
    switchState = digitalRead(2);
 //Lee el voltaje del pin 2
     if (switchState == LOW){
  //El boton no esta pulsado
        digitalWrite(3,LOW);//LED verde
        digitalWrite(4,HIGH);//LED rojo
        digitalWrite(5,HIGH);//LED rojo
   }
     else { //El boton esta pulsado
       digitalWrite(3,LOW);
       digitalWrite(4,HIGH);
       digitalWrite(5,HIGH);
       delay(250);//Espera 250 milisegundos
       digitalWrite(4,LOW);
       digitalWrite(5,HIGH);
       delay (250);//Vuelve a esperar otro cuarto de segundo
       digitalWrite(3,HIGH);
       delay (250);
     }
   } //Vuelve al inicio del bucle

I've this code and the objective of the program is: If the LED (pin 3) is connected and the button isn't held down. I need know how I can make that the program don't make any instruction if the LED (pin 3) is connected. But: The LEDs 4 and 5 have to connect and the program have to wait 250ms.

Can I make this objetive with this code?

how I can make that the program don’t make any instruction if the LED (pin 3) is connected.

Do you mean do nothing if the LED on pin 3 is already turned on or do you really mean do nothing if there is an LED connected to pin 3 ?

The LED is on pin 3. I need that the program knows if the LED is connect, the program don't need make any instruction...

I need that the program knows if the LED is connect,

The Arduino has no idea whether there is anything connected to any of the pins. It simply assumes that you wouldn't tell it to read from/write to a pin with nothing connected to it.

The pin 3 has a green LED…
The pin 4 and 5 have a red LED…

vinnycss: The pin 3 has a green LED... The pin 4 and 5 have a red LED...

So there IS something connected. You know that. The Arduino does NOT. Nor does it care. It is perfectly happy turning a pin with nothing connected to it on or off.

that's right... thanks

vinnycss: that's right... thanks

I still don't understand the original question...

You could use an analog pin with the internal pull up resistor enabled. Do an analog read and you would see the forward voltage of the LED if it is installed. If not, you would see VCC. Then if you like, you could set the analog pin to output and drive the LED.

However I am baffled about why you would need to do this.

aarg: You could use an analog pin with the internal pull up resistor enabled. Do an analog read and you would see the forward voltage of the LED if it is installed. If not, you would see VCC. Then if you like, you could set the analog pin to output and drive the LED.

However I am baffled about why you would need to do this.

Can I generalize ? Is he not just looking for a presence or absence of DC input level? The LED role is pretty irrelevant, resistor connected to any DC ( + or GND) would do.

Vaclav: Is he not just looking for a presence or absence of DC input level?

Actually, OP has never stated clearly what they are looking for. :(