IR Break Sensors as Triggers

I am trying to design a linear electromagnetic accelerator(coilgun), using a series of three solenoids. I have already designed the circuit configuration necessary for the device to work, all that is left to do is figure out the necessary Arduino code to allow the trigger mechanism to work. Essentially the idea I have is that the projectile would pass between a pair of IR break sensors, changing their signal output, which the Arduino would detect and then in response send a signal through a relay, closing it and the circuit, thereby activating the solenoid. A second pair of sensors would then be placed just before the solenoid which would, as in the first case, send a signal to the Arduino when the projectile passes between them. However, in this instance, the Arduino would send a signal through a different relay which would break the circuit, so as to prevent the projectile from becoming stuck in or decelerated by the solenoid. I could almost certainly figure out how to code this without much difficulty if it was not for the fact that as the projectile would only be passing through the sensors momentarily, meaning the signal to close/open the relays would only be sent momentarily, before reverting back to its default state. In other words, is there is any way to program it so that the output signal continues to be sent even once the input has ceased, either for a set duration or until another condition is satisfied, such as a signal change from the second pair of sensors? I should probably also mention that I am very new to C++ and Arduinos. Any suggestions for solving this problem are welcome and appreciated.

search term Arduino interrupt

before void setup():

volatile int coil1   = 0;                                 // create coil1 passage variable and set to 0;
#define coil1_PIN                2                        // Pin on which coil1 break beam line is attached

the function:

void ISR()                                              // INTERRUPT SERVICE REQUEST
  coil1 = 1;                                              // Flag the coil1 input signal

keep it short and simple

in void setup()

  attachInterrupt(coil1_PIN, ISR, RISING);               // enable coil1 interrupt input

that means: use hardware interrupt 0, AKA digital pin 2, to call function ISR when a rising edge is detected on pin 2. the Arduino drops everything and does this when the sensor triggers. if you use a pullup on coil1 pin and it goes low, substitute FALLING for RISING

in void loop(), or a function called by void loop,

if (coil1 == 1)
 do what you gotta do
 coil1 = 0;

if you want to know how long the sensor pulse lasted, research pulseIn ( pulse, letter pronounced "eye", n, letter pronounced "eye" can be confused with lower case "letter pronounced ell" in this font

After you sense the object passing, set your output and ignore that input. Now wait for your second input to change back the output.

[quote author=Geek Emeritus link=msg=4156543 date=1556638557]search term Arduino interrupt[/quote]

I don't think the OP needs interrupts for this. Unless the incoming signal is so short you really can't poll for it.