# Two toggle button to activate a LED

**URL:** <https://forum.arduino.cc/t/two-toggle-button-to-activate-a-led/957648>\
**Category:** General Guidance\
**Created:** [February 10, 2022, 1:43pm UTC](https://forum.arduino.cc/t/two-toggle-button-to-activate-a-led/957648 "2022-02-10T13:43:56Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![devinbabu](https://avatars.discourse-cdn.com/v4/letter/d/f17d59/32.png) [@devinbabu](https://forum.arduino.cc/u/devinbabu)\
**Post date:** [February 10, 2022, 1:43pm UTC](https://forum.arduino.cc/t/two-toggle-button-to-activate-a-led/957648/1 "2022-02-10T13:43:56Z")

</div>

Hi, i have a problem in using 2 toggle buttons to light up an led.

let's say toggle A (TA) and toggle B (TB) are the toggle buttons.  
The LED should light up only when TA then TB is pressed. When TB is released LED should be off.

In my mind:  
a) Since its a toggle button, how do we hold or keep TA value and compare to TB (both high) to activate the LED ?  
b) how do we set all button state in off before running ?

Thank you all in advance.

---

<div class="post-metadata">

**Author:** ![kgray9](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kgray9/32/671408_2.png) [@kgray9](https://forum.arduino.cc/u/kgray9)\
**Post date:** [February 10, 2022, 1:57pm UTC](https://forum.arduino.cc/t/two-toggle-button-to-activate-a-led/957648/2 "2022-02-10T13:57:35Z")

</div>

> [@devinbabu](#):
>
> should light up only when TA then TB is pressed

In that order? Or just when both are pressed at the same time?

> [@devinbabu](#):
>
> When TB is released LED should be off

What about TA?

---

<div class="post-metadata">

**Author:** ![paulpaulson](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paulpaulson/32/363643_2.png) [@paulpaulson](https://forum.arduino.cc/u/paulpaulson)\
**Post date:** [February 10, 2022, 2:01pm UTC](https://forum.arduino.cc/t/two-toggle-button-to-activate-a-led/957648/3 "2022-02-10T14:01:56Z")

</div>

Hello  
Is this a school assigment, isn´t it?

---

<div class="post-metadata">

**Author:** ![devinbabu](https://avatars.discourse-cdn.com/v4/letter/d/f17d59/32.png) [@devinbabu](https://forum.arduino.cc/u/devinbabu)\
**Post date:** [February 10, 2022, 2:04pm UTC](https://forum.arduino.cc/t/two-toggle-button-to-activate-a-led/957648/4 "2022-02-10T14:04:10Z")

</div>

1st : yeap thats the order TA then TB.  
press TA then release, then press TB (LED light up) , release TB(LED off)

2nd: TA press once before TB.

---

<div class="post-metadata">

**Author:** ![devinbabu](https://avatars.discourse-cdn.com/v4/letter/d/f17d59/32.png) [@devinbabu](https://forum.arduino.cc/u/devinbabu)\
**Post date:** [February 10, 2022, 2:05pm UTC](https://forum.arduino.cc/t/two-toggle-button-to-activate-a-led/957648/5 "2022-02-10T14:05:25Z")

</div>

yea some kind like it, trying to get the basics right.

---

<div class="post-metadata">

**Author:** ![kgray9](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kgray9/32/671408_2.png) [@kgray9](https://forum.arduino.cc/u/kgray9)\
**Post date:** [February 10, 2022, 2:14pm UTC](https://forum.arduino.cc/t/two-toggle-button-to-activate-a-led/957648/6 "2022-02-10T14:14:03Z")

</div>

> [@devinbabu](#):
>
> yea some kind like it

Since this is a _school_ project, ill give you a _small_ code piece that explains what happens:

```arduino
void loop(){
  if (digitalRead(TA) == HIGH){ // if the TA button is pressed
    while (digitalRead(TB) != HIGH); //wait for the TB button to be pressed
    while (digitalRead(TB) == HIGH); //wait for the TB button to be released
    digitalWrite(LED, HIGH); //turn on the LED
    while (digitalRead(TB) != HIGH); //wait for the TB button to be pressed
    while (digitalRead(TB) == HIGH); //wait for the TB button to be released
    digitalWrite(LED, LOW); //turn off the LED
  }
}

```

---

<div class="post-metadata">

**Author:** ![devinbabu](https://avatars.discourse-cdn.com/v4/letter/d/f17d59/32.png) [@devinbabu](https://forum.arduino.cc/u/devinbabu)\
**Post date:** [February 10, 2022, 2:54pm UTC](https://forum.arduino.cc/t/two-toggle-button-to-activate-a-led/957648/7 "2022-02-10T14:54:02Z")

</div>

thank you, kind of clear now.

---

<div class="post-metadata">

**Author:** ![Grumpy\_Mike](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grumpy_mike/32/213521_2.png) [@Grumpy\_Mike](https://forum.arduino.cc/u/Grumpy_Mike)\
**Post date:** [February 10, 2022, 3:40pm UTC](https://forum.arduino.cc/t/two-toggle-button-to-activate-a-led/957648/8 "2022-02-10T15:40:14Z")

</div>

> [@devinbabu](#):
>
> i have a problem in using 2 toggle buttons

Now do you actually mean a toggle button? The word toggle means change the state, so a toggle button would mean every time it is pressed it will change its state. This is also known as a latching switch or a push on push off switch.

I suspect you actually mean a momentary push button which is what that code is written for.

---

<div class="post-metadata">

**Author:** ![kgray9](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kgray9/32/671408_2.png) [@kgray9](https://forum.arduino.cc/u/kgray9)\
**Post date:** [February 10, 2022, 3:42pm UTC](https://forum.arduino.cc/t/two-toggle-button-to-activate-a-led/957648/9 "2022-02-10T15:42:29Z")

</div>

Yes. I assumed he meant momentary "tactile" buttons, but I forgot to confirm that with @devinbabu .

---

<div class="post-metadata">

**Author:** ![devinbabu](https://avatars.discourse-cdn.com/v4/letter/d/f17d59/32.png) [@devinbabu](https://forum.arduino.cc/u/devinbabu)\
**Post date:** [February 10, 2022, 3:55pm UTC](https://forum.arduino.cc/t/two-toggle-button-to-activate-a-led/957648/10 "2022-02-10T15:55:34Z")

</div>

> [@Grumpy\_Mike](#):
>
> momentary push button

hi, yea i meant by momentary push button

---

<div class="post-metadata">

**Author:** ![devinbabu](https://avatars.discourse-cdn.com/v4/letter/d/f17d59/32.png) [@devinbabu](https://forum.arduino.cc/u/devinbabu)\
**Post date:** [February 10, 2022, 3:56pm UTC](https://forum.arduino.cc/t/two-toggle-button-to-activate-a-led/957648/11 "2022-02-10T15:56:11Z")

</div>

i meant the toggle as momentary push button, sorry for the miss concept.

---

<div class="post-metadata">

**Author:** ![Grumpy\_Mike](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grumpy_mike/32/213521_2.png) [@Grumpy\_Mike](https://forum.arduino.cc/u/Grumpy_Mike)\
**Post date:** [February 10, 2022, 4:08pm UTC](https://forum.arduino.cc/t/two-toggle-button-to-activate-a-led/957648/12 "2022-02-10T16:08:26Z")

</div>

> [@devinbabu](#):
>
> i meant the toggle as momentary push button,

OK but remember in future to use the right words. It is important in all walks of life but especially in a technical / science subject.

---

<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:** [August 9, 2022, 4:08pm UTC](https://forum.arduino.cc/t/two-toggle-button-to-activate-a-led/957648/13 "2022-08-09T16:08:52Z")

</div>

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