Working on a key fob controlled air valve project... thanks for any help...

It is a program to open four different air valve solenoids with an Arduino four button key fob transmitter and receiver, Arduino Uno Board, Diodes, and 2.2k Resistors. So far, I can get the valves to open and close. However, once a button is pressed and the program has run, the same solenoid will not respond again until a different button is pressed first. This is what I have so far:

// Set pin #'s:
const int ButtonPinA = 2;           // # of Button 'A' Pin
const int SolenoidPinA =  12;       // # of Solenoid 'A' Pin

const int ButtonPinB = 3;           // # of Button 'B' Pin
const int SolenoidPinB =  11;       // # of Solenoid 'B' Pin

const int ButtonPinC = 4;           // # of Button 'C' Pin
const int SolenoidPinC =  10;       // # of Solenoid 'C' Pin

const int ButtonPinD = 5;           // # of Button 'D' Pin
const int SolenoidPinD =  9;        // # of Solenoid 'D' Pin

// Set all variables to 0 for reading button status
int ButtonStateA = 0;
int ButtonStateB = 0;
int ButtonStateC = 0;
int ButtonStateD = 0;

void setup()
{
  Serial.begin(9600);

  // initialize as output pin:
  pinMode(SolenoidPinA, OUTPUT);  
  // initialize as input pin:
  pinMode(ButtonPinA, INPUT);

  // initialize as output pin:
  pinMode(SolenoidPinB, OUTPUT);  
  // initialize as input pin:
  pinMode(ButtonPinB, INPUT);
  
  // initialize as output pin:
  pinMode(SolenoidPinC, OUTPUT);  
  // initialize as input pin:
  pinMode(ButtonPinC, INPUT);
  
  // initialize as output pin:
  pinMode(SolenoidPinD, OUTPUT);
  // initialize as input pin:
  pinMode(ButtonPinD, INPUT);
}

void loop()
{  
  // read state of button values:
  ButtonStateA = digitalRead(ButtonPinA);
  ButtonStateB = digitalRead(ButtonPinB);
  ButtonStateC = digitalRead(ButtonPinC);
  ButtonStateD = digitalRead(ButtonPinD);

  // Check if button 'A' is pressed
  if (ButtonStateA == HIGH)
  {
    //Open Solenoid
    digitalWrite(SolenoidPinA, HIGH);
    delay(400);

    //Close Solenoid
    digitalWrite(SolenoidPinA, LOW);
    delay(400);

    // keep looping if switch is still HIGH
    while (digitalRead(ButtonPinA) == HIGH);

     loop();
   }
  
  else  
  {
    // Open Solenoid
    digitalWrite(SolenoidPinA, LOW);

    loop();
  }

  // Check if button 'B' is pressed
  if (ButtonStateB == HIGH)
  {
    // Open Solenoid
    digitalWrite(SolenoidPinB, HIGH);
    delay(400);

    //Close Solenoid
    digitalWrite(SolenoidPinB, LOW);
    delay(400);

    // keep looping if switch is still HIGH
    while (digitalRead(ButtonPinB) == HIGH);
    
    loop();
  }
  
  else
  {
    // Open Solenoid
    digitalWrite(SolenoidPinB, LOW);
    
    loop();
  }

  // Check if button 'C' is pressed
  if (ButtonStateC == HIGH)
  {
    // Open Solenoid
    digitalWrite(SolenoidPinC, HIGH);
    delay(400);

    //Close Solenoid
    digitalWrite(SolenoidPinC, LOW);
    delay(400);
    
    // keep looping if switch is still HIGH
    while (digitalRead(ButtonPinC) == HIGH);
    
    loop();
  }
  
  else
  {
    // Open Solenoid
    digitalWrite(SolenoidPinC, LOW);

    loop();
  }

  // Check if button 'D' is pressed
  if (ButtonStateD == HIGH)
  {
    // Open Solenoid
    digitalWrite(SolenoidPinD, HIGH);
    delay(400);

    //Close Solenoid
    digitalWrite(SolenoidPinD, LOW);
    delay(400);
    
    // keep looping if switch is still HIGH
    while (digitalRead(ButtonPinD) == HIGH);
    
    loop();
  }
  
  else
  {
    // Open Solenoid
    digitalWrite(SolenoidPinD, LOW);
    
    loop();
  }

  loop();
}

Your mistake is calling loop() from loop(). That is called ‘recursion’ and unless it is carefully controlled it will use up all available stack space and crash the sketch.

When you have more than two variables that have the same use and name and only differ in a counter (1, 2, 3, or A, B, C) you should change them into an array. This will greatly simplify your sketch, as shown below.

const byte ChannelCount = 4;

const byte ButtonPins[ChannelCount] = {2, 3, 4, 5};
const byte SolenoidPins[ChannelCount] = {12, 11, 10, 9};

// Set all variables to 0 for reading button status
boolean ButtonStates[ChannelCount];

void setup()
{
  Serial.begin(9600);

  for (int i = 0; i < ChannelCount; i++)
  {
    pinMode(SolenoidPins[i], OUTPUT);
    pinMode(ButtonPins[i], INPUT);
  }
}

void loop()
{
  for (int i = 0; i < ChannelCount; i++)
  {
    ButtonStates[i] = digitalRead(ButtonPins[i]);
    digitalWrite(SolenoidPins[i], ButtonStates[i]);
  }
}

I will give it a go. Thank you

so i tried that and essentially ended up where i was already… but with a much more clean code lol

i just added:

delay(400);
digitalWrite(SolenoidPins*, LOW);*
_ while (digitalRead(ButtonPins*) == HIGH);_
_
…and the solenoid will turn on and then off like i want it to, but will not go again unless a different button is pressed first (i.e. setting off a different solenoid. Thanks for any information.*_

It sounds like it might be a limitation of the remote control.

OMG... I bought a "Simple RF M4 Receiver - 315MHz Momentary Type" but I was sent a 'Toggle type' ...I feel so dumb now. But I did learn how to simplify my code so that's good. :) Thank you guys so much for your help. I guess I'll be waiting a few days to try this again. (And) I won't just "assume" I received the correct parts from now on.