6

How can I have an LED turn on when a push button is pressed, turn off when the button is pressed again, and keep its state unchanged when the button is not pressed?

I don't want the LED to oscillate if the button is held down for a while, and I want immediate action (not having to hold the button down while waiting for a capacitor to charge).

Ilmari Karonen
  • 832
  • 6
  • 13
skyler
  • 10,136
  • 27
  • 80
  • 130

2 Answers2

11

Assuming you don't want to do this with a simple microcontroller, I'd recommend you an easy logic gate circuit as from here:

enter image description here

Imagine Vout is low for a start. This will make the first gate (G1) output high. That makes the second gate (G2) output low, so this situation is stable.

Now, someone presses the button. That connects the high output of G1 to its input, so that the output becomes low. The low on the inputs of G2 makes the output of G2 high. We're in a stable situation again.

When someone presses the button again, the same happens, but in the opposite way: the low output of G1 is connected to its input, making the output high. That is connected to the input of G2, making the output of G2 low. We're back to the first situation.

  • 2
    I'll add that the 0.01uF capacitor causes the circuit to power-up in a defined state - the 10nF is stopping the input to G1 (left) from rising quickly and so G1's output will want to be high and G2's output will be low. – Andy aka Apr 08 '13 at 17:53
5

The simplest way is with a latching pushbutton such as this one Push it and it turns on and stays on. Push it again and it turns off and stays off.

lyndon
  • 4,366
  • 1
  • 16
  • 11