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();
}