# Control relays with push buttons and switch

**URL:** <https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102>\
**Category:** General Guidance\
**Created:** [August 31, 2024, 12:07pm UTC](https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102 "2024-08-31T12:07:40Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![travisd10](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/travisd10/32/1100254_2.png) [@travisd10](https://forum.arduino.cc/u/travisd10)\
**Post date:** [August 31, 2024, 12:07pm UTC](https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102/1 "2024-08-31T12:07:40Z")

</div>

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
/*
 * 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

```

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [August 31, 2024, 12:09pm UTC](https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102/2 "2024-08-31T12:09:37Z")

</div>

Welcome to the forum

> [@travisd10](#):
>
> I would like to add in code

What have you tried ?

---

<div class="post-metadata">

**Author:** ![travisd10](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/travisd10/32/1100254_2.png) [@travisd10](https://forum.arduino.cc/u/travisd10)\
**Post date:** [August 31, 2024, 12:16pm UTC](https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102/4 "2024-08-31T12:16:51Z")

</div>

> [@travisd10](#):
>
> Short story, all kinds of things. I'm an electrician not a programmer.

Short story, all kinds of things. I'm an electrician not a programmer.

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [August 31, 2024, 12:30pm UTC](https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102/5 "2024-08-31T12:30:33Z")

</div>

Is the code you posted the original from wherever you grabbed it?

You want

> [@travisd10](#):
>
> only change the status of **relay pin 2** if **pin 8** is _HIGH_

Pin 8 is being used as a relay pin. Is it you intent that the first of these 8, 9 and so forth extra condition pins actually be the first relay pin also?

```arduino
... relayPin[]={8... 

```

a7

---

<div class="post-metadata">

**Author:** ![travisd10](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/travisd10/32/1100254_2.png) [@travisd10](https://forum.arduino.cc/u/travisd10)\
**Post date:** [August 31, 2024, 12:41pm UTC](https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102/6 "2024-08-31T12:41:37Z")

</div>

No I added pin 8 for a sanity led. Sorry my bad. Should be pin 9, 10, & 11

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [August 31, 2024, 2:30pm UTC](https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102/7 "2024-08-31T14:30:53Z")

</div>

OK, I am in transit, and I know this isn't the complete answer, but in the loop across all relays is your opportunity to check the controlling pins.

For example and to illustrate, again not your requirement but shows the idea, with the assumption that there is an array for 9, 10, 11 control pins.

```arduino
  for (int ii = 0; ii < 7; ii++)
  {
// just skip this channel if it is being inhibited
    if (digitalRead(controlPin[ii] == LOW)
      continue;

// handle channel normally

  }

```

  
When I get to the lab I'll look at the actual specification. You may also need to not do any checking, if you mean only to have three relays enjoying this constraint you are coding.

a7

---

<div class="post-metadata">

**Author:** ![Terrypin](https://avatars.discourse-cdn.com/v4/letter/t/a3d4f5/32.png) [@Terrypin](https://forum.arduino.cc/u/Terrypin)\
**Post date:** [August 31, 2024, 2:34pm UTC](https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102/8 "2024-08-31T14:34:05Z")

</div>

I've shown below how to toggle a single LED (instead of a relay pin) from a single button. No 'extras' such as relay names. Adapting to several buttons and several LEDs/relay pins is trivial. Come back once that's working OK for you if you (or @alto777) has not already added the extra logic you require.

```arduino
/*
  Fri 19 Jan 2024 0820; using for discussion https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102
  Button is clean but any debouncing dobe by simple brief delay.
  This toggles an LED instead of a relay pin; adapting is trivial
*/

// Constants
const byte buttonPin = 2; // LOW going
const byte ledPin = 5; // to activate LED

// Variables
byte ledState = LOW;
byte lastButtonState;
byte currentButtonState;

void setup()
{
  Serial.begin(115200);
  delay(200);
  pinMode(buttonPin, INPUT_PULLUP); // External pull-down
  pinMode(ledPin, OUTPUT); //

  currentButtonState = digitalRead(buttonPin);

} // end setup

void loop()
{
  lastButtonState = currentButtonState; // Save last state for next loop
  currentButtonState = digitalRead(buttonPin); // Read new state
  if (lastButtonState == HIGH && currentButtonState == LOW)
  {
    Serial.println("Button was pressed");
    // toggle state of LED
    ledState = !ledState;

    // LED control
    digitalWrite(ledPin, ledState);
  }
  delay(50); // Depends on noisiness of button
} // end loop

```

Oh, and I have a toggler that uses just a cheap 4013 IC, no micro.

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [August 31, 2024, 3:08pm UTC](https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102/9 "2024-08-31T15:08:05Z")

</div>

OK, still moving but thinking. At times I can do both.

Does this pseudo code express the requirement?

```arduino
  if the relay is being inhibited
     the relay should be made, or left LOW.

  (else) the relay is not being inhibited
    handle the push button to see if the relay should be tokkled 

```

is what I make of your prose.

Now also say if it is only three relays of the N that are to have this extra control signal. The loop could do something different if an individual channel did not have athe extra control signal. In the array of pins designating the control pins, a zero flag cloud mean an uninhibitable relay. Yes that is too a word.

a7

---

<div class="post-metadata">

**Author:** ![Terrypin](https://avatars.discourse-cdn.com/v4/letter/t/a3d4f5/32.png) [@Terrypin](https://forum.arduino.cc/u/Terrypin)\
**Post date:** [August 31, 2024, 4:12pm UTC](https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102/10 "2024-08-31T16:12:16Z")

</div>

I've stayed with my much simplified version but added an extra button - what I've interpreted as your 'pin 9 inhibitor'. So pressing the button on pin 2 toggles my LED, but with the button on pin 9 held down there is no toggling.

```arduino
/*
  Fri 19 Jan 2024 0820; using for discussion https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102
  Button is clean but any debouncing dobe by simple brief delay.
  This toggles an LED instead of a relay pin; adapting is trivial

  Sat 31 Aug 2024 1634; add extra logic:
  "I would like to add in code so that push button 19 can only change
  // "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.
  // 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 2 can only bring relay pin 5 low if pin 9 is HIGH
  // -push button 19 can only bring relay pin 2 low if pin 9 is HIGH

*/

// Constants
const byte buttonPin = 2; // LOW going when pressed
const byte ledPin = 5; // to activate LED
const byte modifierButtonPin = 9; // LOW going when pressed
;
// Variables
bool ledState = LOW;

bool lastButtonState;
bool currentButtonState;

bool currentModifierButtonState;
bool lastModifierButtonState;

void setup()
{
  Serial.begin(115200);
  delay(200);
  pinMode(buttonPin, INPUT_PULLUP); // External pull-down
  pinMode(ledPin, OUTPUT);
  pinMode(modifierButtonPin, INPUT_PULLUP);

  currentButtonState = digitalRead(buttonPin);
  currentModifierButtonState = digitalRead(modifierButtonPin);

} // end setup

void loop()
{
  lastButtonState = currentButtonState; // Save last state for next loop
  currentButtonState = digitalRead(buttonPin); // Read new state

  lastModifierButtonState = currentModifierButtonState;
  currentModifierButtonState = digitalRead(modifierButtonPin);

 if ((lastButtonState == HIGH && currentButtonState == LOW)
&&
currentModifierButtonState == HIGH)
  {
    Serial.println("Button was pressed");
    // toggle state of LED
    ledState = !ledState;

    // LED control
    digitalWrite(ledPin, ledState);
  }
  delay(50); // Depends on noisiness of button
} // end loop

```

---

<div class="post-metadata">

**Author:** ![travisd10](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/travisd10/32/1100254_2.png) [@travisd10](https://forum.arduino.cc/u/travisd10)\
**Post date:** [September 1, 2024, 3:54am UTC](https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102/11 "2024-09-01T03:54:48Z")

</div>

I'm going to start this over.

The first schematic labeled current is what im working with now. the one labeled new schematic is the version 2 design to accommodate more inputs/outputs, and eliminate the second bank of relays.

 ![current-schematic](https://europe1.discourse-cdn.com/arduino/original/4X/6/b/0/6b063670230bcc34ffc832c3560b4f09bdcad4bb.jpeg)

 ![new-schematic(1)](https://europe1.discourse-cdn.com/arduino/original/4X/c/a/7/ca745b36ffa58aba996845b8b535d1bf55cc8071.jpeg)

I'll use the fog lights for an example but i would like the high beams and reverse lights to function the same way.

When button one (pin A8) is pressed it turns led 1 (pin D2) LOW and sets the relay 1 output (pin D37) "active".

When the park light signal (pin D48) goes high, because the relay has now been "activated", it should set the relay 1 output (D37) LOW.

This turns relay 1 on and in turn the fog lights.

If the relay has not been made "active", the park light signal (pin D48) should not cause the relay to turn on.

same for button 2, high beam signal, and relay 2  
same for button 6, reverse signal, and relay 6

buttons/relays 3,4 & 5 have no secondary signal

```arduino
/* Thanks to VE7JRO for giving me this solution to my problem. 
 * Thread found at https://arduino.stackexchange.com/questions/55540/push- button-control-of-multiple-relays 
 */

#include <Bounce2.h>
byte buttonOneState = 0;
byte buttonTwoState = 0;
byte buttonThreeState = 0;
byte buttonFourState = 0;
byte buttonFiveState = 0;
byte buttonSixState = 0;
const byte buttonPin1 = A0; //Button input 1
const byte buttonPin2 = A1; //Button input 2
const byte buttonPin3 = A2; //Button input 3
const byte buttonPin4 = A3; //Button input 4
const byte buttonPin5 = A4; //Button input 5
const byte buttonPin6 = A5; //Button input 6

//const byte buttonPin10 = 10; //Park Signal Input
const byte buttonPin11 = 11; //High Beam Signal Input
//const byte buttonPin12 = 12; //Reverse Signal Input

const byte relayPin1 = 2; //Relay pin 1
const byte relayPin2 = 3; //Relay pin 2
const byte relayPin3 = 4; //Relay pin 3
const byte relayPin4 = 5; //Relay pin 4
const byte relayPin5 = 6; //Relay pin 5
const byte relayPin6 = 7; //Relay pin 6
const byte relayPin8 = 8; // system boot ok
const byte debouncerInterval = 50;

// Instantiate ONE OR MORE Bounce2 object(s).
Bounce debouncer = Bounce();
Bounce debouncer2 = Bounce();
Bounce debouncer3 = Bounce();
Bounce debouncer4 = Bounce();
Bounce debouncer5 = Bounce();
Bounce debouncer6 = Bounce();
//Bounce debouncer10 = Bounce();
Bounce debouncer11 = Bounce();
//Bounce debouncer12 = Bounce();

void setup(){
  Serial.begin(9600);
  
  digitalWrite (relayPin1, HIGH); // |set output to (on) on startup
  digitalWrite (relayPin2, HIGH); // | 
  digitalWrite (relayPin3, LOW); // |set outputs to (off) on startup
  digitalWrite (relayPin4, LOW); // |
  digitalWrite (relayPin5, LOW); // |
  digitalWrite (relayPin6, LOW); // |
  digitalWrite (relayPin8, HIGH); // set status led to on (leave 'HIGH' always)
  
  pinMode(buttonPin1, INPUT); // |set button inputs 
  pinMode(buttonPin2, INPUT); // |
  pinMode(buttonPin3, INPUT); // |
  pinMode(buttonPin4, INPUT); // |
  pinMode(buttonPin5, INPUT); // |
  pinMode(buttonPin6, INPUT); // |
  //pinMode(buttonPin10, INPUT);// |
  pinMode(buttonPin11, INPUT); // |
  //pinMode(buttonPin12, INPUT);// |
  
  debouncer.attach(buttonPin1);
  debouncer.interval(debouncerInterval);
  debouncer2.attach(buttonPin2);
  debouncer2.interval(debouncerInterval);
  debouncer3.attach(buttonPin3);
  debouncer3.interval(debouncerInterval);
  debouncer4.attach(buttonPin4);
  debouncer4.interval(debouncerInterval);
  debouncer5.attach(buttonPin5);
  debouncer5.interval(debouncerInterval);
  debouncer6.attach(buttonPin6);
  debouncer6.interval(debouncerInterval);
  //debouncer10.attach(buttonPin10);
  //debouncer10.interval(debouncerInterval);
  debouncer11.attach(buttonPin11);
  debouncer11.interval(debouncerInterval);
  //debouncer12.attach(buttonPin12);
  //debouncer12.interval(debouncerInterval);
  
  pinMode(relayPin1, OUTPUT); //Define pin as output
  pinMode(relayPin2, OUTPUT); //Define pin as output
  pinMode(relayPin3, OUTPUT); //Define pin as output
  pinMode(relayPin4, OUTPUT); //Define pin as output
  pinMode(relayPin5, OUTPUT); //Define pin as output
  pinMode(relayPin6, OUTPUT); //Define pin as output
  pinMode(relayPin8, OUTPUT); //Define pin as output
}

void loop(){

  // Button 1
  if(debouncer.update()){
    if(debouncer.read() == 0){
      if(buttonOneState == 0){
        Serial.println("Turn Relay 1 ON");
        digitalWrite(relayPin1, HIGH);
        buttonOneState = 1;
      }
      else{
        Serial.println("Turn Relay 1 OFF");
        digitalWrite(relayPin1, LOW);
        buttonOneState = 0;
      }
    }
  }

  // Button 2
  if(debouncer2.update()){
    if(debouncer2.read() == 0){
      if(buttonTwoState == 0){
        Serial.println("Turn Relay 2 ON");
        digitalWrite(relayPin2, HIGH);
        buttonTwoState = 1;
      }
      else{
        Serial.println("Turn Relay 2 OFF");
        digitalWrite(relayPin2, LOW);
        buttonTwoState = 0;
      }
    }
  }

  // Button 3
  if(debouncer3.update()){
    if(debouncer3.read() == 0){
      if(buttonThreeState == 0){
        Serial.println("Turn Relay 3 ON");
        digitalWrite(relayPin3, HIGH);
        buttonThreeState = 1;
      }
      else{
        Serial.println("Turn Relay 3 OFF");
        digitalWrite(relayPin3, LOW);
        buttonThreeState = 0;
      }
    }
  }
  
  // Button 4
  if(debouncer4.update()){
    if(debouncer4.read() == 0){
      if(buttonFourState == 0){
        Serial.println("Turn Relay 4 ON");
        digitalWrite(relayPin4, HIGH);
        buttonFourState = 1;
      }
      else{
        Serial.println("Turn Relay 4 OFF");
        digitalWrite(relayPin4, LOW);
        buttonFourState = 0;
      }
    }
  }
  
  // Button 5
  if(debouncer5.update()){
    if(debouncer5.read() == 0){
      if(buttonFiveState == 0){
        Serial.println("Turn Relay 5 ON");
        digitalWrite(relayPin5, HIGH);
        buttonFiveState = 1;
      }
      else{
        Serial.println("Turn Relay 5 OFF");
        digitalWrite(relayPin5, LOW);
        buttonFiveState = 0;
      }
    }
  }
  
// Button 6
  if(debouncer6.update()){
    if(debouncer6.read() == 0){
      if(buttonSixState == 0){
        Serial.println("Turn Relay 6 ON");
        digitalWrite(relayPin6, HIGH);
        buttonSixState = 1;
      }
      else{
        Serial.println("Turn Relay 6 OFF");
        digitalWrite(relayPin6, LOW);
        buttonSixState = 0;
        }
      }
    }
}

```

hopefully this makes more sense. the reason for having the code separated the way it is makes it quick and easy to change the default status of each switch, for example button 1, 2, and 6 default to "activated" when the arduino is powered on. this way when the vehicle is turned on and the arduino gets power it "activates" relay 1 and when the park lights go on and off the fog lights go on and off respectively.

again thanks for your help.

---

<div class="post-metadata">

**Author:** ![Terrypin](https://avatars.discourse-cdn.com/v4/letter/t/a3d4f5/32.png) [@Terrypin](https://forum.arduino.cc/u/Terrypin)\
**Post date:** [September 1, 2024, 6:38am UTC](https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102/12 "2024-09-01T06:38:29Z")

</div>

So your initial post asked for an edit to a Robojax sketch. And now this latest post asks for edits to two differently sourced sketches, yes?

And so far you’ve shown no code of your own?

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [September 1, 2024, 10:48am UTC](https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102/13 "2024-09-01T10:48:17Z")

</div>

> [@travisd10](#):
>
> again thanks for your help.

So we done here? Solution provided by your inquiries elsewhere?

a7

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [September 1, 2024, 12:34pm UTC](https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102/14 "2024-09-01T12:34:52Z")

</div>

I'm still trying to make sense of your prose. I don't see that you have confirmed or corrected any of the various guesses we've made to inform our advices.

The pseudo code in #9 for example.

Perhaps you'd like to take a stab at producing an unambiguous description of the desired functionality.

Hers a timing diagram showing a button press toggling a relay. I assume that only the button press, not the state of the button, is relevant. I marked the press in bold on the diagram.

 ![IMG_4058](https://europe1.discourse-cdn.com/arduino/original/4X/6/3/d/63d8053fdc3bcb766ee792176ed5b3509e998121.jpeg)

Time goes from the left to the right; the diagram shows two presses and the reply's response to each. Use your best common sense and add a line to this diagram that illustrates the effect on what I've called the inhibiting signal.

Show how the inhibit logic level alters the state of the relay and the behavoiur of the pushbutton.

Remember when you do that there are a variety of conditions. Account for the button being pushed when the inhibit signal is present and absent, when the relay is on or off, all four possibilities.

Account for the inhibit signal to become present for both conditions the relay may be in at the time. If there is anything about the inhibit signal going away, place that in the diagram as well.

a7

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [September 1, 2024, 1:52pm UTC](https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102/15 "2024-09-01T13:52:17Z")

</div>

A helpful friend said I threw you under the bus.

So here's a timing diagram that I think corresponds to the suggestion in #9 and as such is offered as "how it should work". Try to fix it if it is wrong.

The pushbutton is represented by the spikes which are the leading edge (press).

The relay toggles. When the inhibit signal is present, the relay immediately shuts off (1). During the inhibit period, the pushbutton presses are ignored (2):

 ![IMG_4059](https://europe1.discourse-cdn.com/arduino/original/4X/3/9/3/3934a43d879e76a0900bd6a7677a357cf719665a.jpeg)

Confirm or deny and correct!

a7

---

<div class="post-metadata">

**Author:** ![travisd10](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/travisd10/32/1100254_2.png) [@travisd10](https://forum.arduino.cc/u/travisd10)\
**Post date:** [September 2, 2024, 12:00am UTC](https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102/16 "2024-09-02T00:00:25Z")

</div>

right i dont know what you dont understand. im here because i dont know how to code. im modifying other sketches to accomplish what i want. i dont have time to become a programmer to learn what to do. thats why people come here and ask questions. not everyone wants to be a programmer, some people just want their project to work.

---

<div class="post-metadata">

**Author:** ![travisd10](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/travisd10/32/1100254_2.png) [@travisd10](https://forum.arduino.cc/u/travisd10)\
**Post date:** [September 2, 2024, 12:01am UTC](https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102/17 "2024-09-02T00:01:18Z")

</div>

are you actually reading what im writing here?

---

<div class="post-metadata">

**Author:** ![travisd10](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/travisd10/32/1100254_2.png) [@travisd10](https://forum.arduino.cc/u/travisd10)\
**Post date:** [September 2, 2024, 12:08am UTC](https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102/18 "2024-09-02T00:08:30Z")

</div>

nevermind forget it. i dont have time to deal with all you fart sniffers. ill buy a commercial product. this forum is a joke

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 1, 2025, 12:08am UTC](https://forum.arduino.cc/t/control-relays-with-push-buttons-and-switch/1297102/19 "2025-03-01T00:08:37Z")

</div>

Closed on March 1, 2025, 12:08am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
