project with two servo motors

I need help with programming two servo motors, an IR led and an IR receiver.
The first is triggered by a pressure switch,and which opens up to 90 degrees and only goes down after a certain time.
The second servo motor is also actuated by a push button, but it must only lower when the vehicle is no longer detected after a certain time, where it is detected by an IR.
Thank you.

Are these two processes completely independent? There's two separate buttons, two separate servos, and the button sequence can be thought of as being separate things? Or are their rules like "the second servo should only actuate if the first button no longer is pressed" or "the first servo should only actuate of the IR reciver is not detecting anything", or "the first servo should only actuate after the second door has been closed for 1 second"?

This is not a difficult project. I could easily write the skeleton of the logic that will do what you describe. You'd have to fill in pin numbers, the open/close values for the servos. I haven't worked with IR leds and IR receivers. I assume that a simple digitalWrite to turn the led on and a digital read to get the receiver result would work.

Something like:

#include <Servo.h>



class Button {
    const byte pin;
    long lastRead_ms;
    boolean falling;
    byte state;

  public:

    Button(byte pin) : pin(pin) {}

    void setup() {
      pinMode(pin, INPUT_PULLUP);
      lastRead_ms = millis();
    }

    byte loop() {
      falling = false;
      if (millis() - lastRead_ms < 50) return;
      byte oldState = state;
      state = digitalRead(pin);
      if (state == LOW && oldState == HIGH)  falling = true;
    }

    boolean isFalling() {
      return falling;
    }

    boolean isLow() {
      return state == LOW;
    }
};

class DoorA {
    Button button;
    const byte servoPin;
    const int servoClosedVal;
    const int servoOpenVal;
    const long timeout_ms;

    long startTimeout_ms;

    Servo servo;

    enum state {
      CLOSED,
      OPEN
    } state;

  public:
    DoorA(byte buttonPin, byte servoPin, int servoClosedVal, int servoOpenVal, long timeout_ms) :
      button(buttonPin),
      servoPin(servoPin),
      servoClosedVal(servoClosedVal),
      servoOpenVal(servoOpenVal),
      timeout_ms(timeout_ms)
    {
    }

    void setup() {
      button.setup();
      pinMode(servoPin, OUTPUT);
      servo.attach(servoPin);
      servo.write(servoClosedVal);
      state = CLOSED;
    }

    void loop() {
      button.loop();
      
      switch (state) {
        case CLOSED:
          if (button.isLow()) {
            servo.write(servoOpenVal);
            startTimeout_ms = millis();
            state = OPEN;
          }
          break;

        case OPEN:
          if (millis() - startTimeout_ms >= timeout_ms) {
            servo.write(servoClosedVal);
            state = CLOSED;
          }
          break;
      }
    }
};

class DoorB {
    Button button;
    const byte irSendPin;
    const byte irRecievePin;
    const byte servoPin;
    const int servoClosedVal;
    const int servoOpenVal;
    const long timeout_ms;

    long startTimeout_ms;

    Servo servo;

    enum State {
      CLOSED,
      OPEN
    } state;

  public:
    DoorB(byte buttonPin, byte irSendPin, byte irRecievePin, byte servoPin, int servoClosedVal, int servoOpenVal, long timeout_ms) :
      button(buttonPin),
      irSendPin(irSendPin),
      irRecievePin(irRecievePin),
      servoPin(servoPin),
      servoClosedVal(servoClosedVal),
      servoOpenVal(servoOpenVal),
      timeout_ms(timeout_ms)
    {}

    void setup() {
      button.setup();
      pinMode(irSendPin, OUTPUT);
      pinMode(irRecievePin, INPUT);
      pinMode(servoPin, OUTPUT);

      digitalWrite(irSendPin, LOW); // turn ir off
      servo.attach(servoPin);
      servo.write(servoClosedVal);
      state = CLOSED;
    }

    void loop() {
      button.loop();
      
      switch (state) {
        case CLOSED:
          if (button.isLow()) {
            servo.write(servoOpenVal);
            digitalWrite(irSendPin, HIGH);
            state = OPEN;
            startTimeout_ms = millis();
          }
          break;

        case OPEN:
          if (digitalRead(irRecievePin) == HIGH) {
            // restart the timeout from now
            startTimeout_ms = millis();
          }
          else if (millis() - startTimeout_ms >= timeout_ms) {
            digitalWrite(irSendPin, LOW);
            servo.write(servoClosedVal);
            state = CLOSED;
          }
          break;
      }
    }

};

DoorA doorA(
  4, // the button pin
  5, // the servo pin
  0, // servo value when the door is closed
  90, // servo value when the door is open
  2000 // time the door remains open, in ms
);

DoorB doorB(
  6, // the button pin
  7, // the ir SEND pin
  8, // the ir RECEIVE pin
  9, // the servo pin
  0, // servo value when the door is closed
  90, // servo value when the door is open
  1000 // time the door remains open after the ir goes off, in ms
);

void setup() {
  doorA.setup();
  doorB.setup();
}

void loop() {
  doorA.loop();
  doorB.loop();
}

the goal is for the servos to work independently.
Thank you very much for the programming, but until now without result!

AleFASantos:
Thank you very much for the programming, but until now without result!

? Do you mean that you tried this sketch and nit dion't work for you?

class Button {
    const byte pin;

You are not going to be able to set the value of pin later.

I wanted to say was that the program was initially not working the servos, but later I verified that it was a technical problem with the arduino