Hello and thank you to anyone willing to help.
The code as copied here works as desired.
I would like to add in code so that push button 19 can only change the status of relay pin 2 if pin 9 is HIGH. If pin 9 is LOW relay pin 2 should not become LOW and if relay pin 2 is HIGH, it should become LOW when pin 9 goes LOW.
then mirror it for the following 2 buttons
-push button 19 can only bring relay pin 2 low if pin 9 is HIGH
-push button 18 can only bring relay pin 3 low if pin 10 is HIGH
-push button 17 can only bring relay pin 4 low if pin 11 is HIGH
/*
* Arduino code to push-ON and push-OFF 4 relays
* when button pushed, relay ON and stay ON
* push again to make it OFF and stay OFF
* this can be done with 4 push button to control 4 relays.
*
* written by Ahmad Shamshiri for Robojax.com
* on December 11, 2018 at 19:39 in Ajax, Ontario, Canada
watch video instruction for this code:https://youtu.be/3EZecphNdAI
Get this code and other Arduono codes from Robojax.com
*
* This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.*
* This code has been download from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const int pushButton[] ={1,19,18,17,16,15,14};// define push button inputs ("1" is placeholder for "alive" status led)
const int relayPin[]={8,2,3,4,5,6,7};// output pins where 4 relays will be connected ("8" is for "alive" status led)
String relayNames[] ={"CH1", "CH2","CH3","CH4","CH5","CH6","CH7"};// Just put name for 4 relays
int pushed[] ={0,0,0,0,0,0,0};// status of each buttons (first "0" is for "alive" status led)
int relayStatus[] ={LOW,HIGH,HIGH,HIGH,HIGH,LOW,LOW};// initial status of relay (first "LOW" is for "alive" status led)
void setup() {
// Robojax.com 4-Relay-4-Push button 20181211
Serial.begin(9600);// initialize serial monitor
for(int i=0; i<7; i++)
{
pinMode(pushButton[i], INPUT_PULLUP);
pinMode(relayPin[i], OUTPUT);
digitalWrite(relayPin[i], HIGH);// initial relay status to be OFF
}
// Robojax.com 4-Relay-4-Push button 20181211
}
void loop() {
// Robojax.com 4-Relay-4-Push button 20181211
for(int i=0; i<7; i++)
{
int val = digitalRead(pushButton[i]);
if(val == HIGH && relayStatus[i] == LOW){
pushed[i] = 1-pushed[i];
delay(100);
}// if
relayStatus[i] = val;
if(pushed[i] == HIGH){
Serial.print(relayNames[i]);
Serial.println(" ON");
digitalWrite(relayPin[i], LOW);
}else{
Serial.print(relayNames[i]);
Serial.println(" OFF");
digitalWrite(relayPin[i], HIGH);
}// else
}// for
Serial.println("==");
delay(100);
// Robojax.com 4-Relay-4-Push button 20181211
}// loop end



