1

When reading up on how to make a circuit that turns an LED on when a button is held down, I keep finding people saying a pull up or down resistor must be involved, to avoid the flickering state of the LED seen with a floating pin. There's also code being implemented, where the state of a pin is read and monitored as the button is pressed down or left raised. What I don't understand, is why this is all necessary. Surely it isn't, considering the circuit below allows the button to be pressed with the LED turning on/off depending on the state of the button.

enter image description here

I made this circuit before drawing it online, and it works exactly as intended. No need for a pull up/down resistor or any code. I must be missing something here, can anyone please explain? It works perfectly with a buzzer as well.

Many thanks.

2
  • 2
    That problem of turning an led on when a button is pressed is a nice first exercises for getting started with learing arduino, as it makes you learn how to read an input pin, and how to turn on an output pin, and make an led light. What you are doing is sidestepping the whole Arduino part. There isn't anything wrong with that, as as you said, it work the way you want it to work. But you haven't learned anything about inputs and outputs.
    – Gerben
    Jan 14, 2019 at 16:36
  • your arduino is not doing anything other than supplying power to the LED ..... you can replace the arduino with a battery
    – jsotola
    Jan 14, 2019 at 23:24

3 Answers 3

6

The circuit you have made is only using Arduino as a 5V power source. You aren't using any GPIO pins to read the state of the button or to control the LED by an output pin. You've just made a plain-old circuit with a button and LED in series with a power source.

Often for a button-controlling-LED sketch, you will have a button connected between GND and an I/O pin defined as an INPUT_PULLUP, which means the Arduino will be able to read the state of the pin as HIGH (5V) or LOW (0V). The PULLUP part indicates that when the button is not completing the circuit between GND and the pin, a weak voltage is applied to get it up to 5V. In this way it's not "floating" at an unspecified voltage, but is being actively driven to 5V. When you press the button, the input pin is shorted to GND.

A pull-up resistor causes an otherwise un-driven pin to go to logic HIGH. A pull-down resistor causes an otherwise un-driving pin to go to logic LOW.

In the case of a pull-up resistor, reading a logic LOW means the button is pressed, which is kind of the reverse of your circuit operation, so in your sketch code, you would look for LOW to turn on the LED.

2

No, you don't.

The thing to remember is that you don't put a pulldown (or pullup) resistor on the button - you actually put it on the input.

And since you aren't using an input there is nowhere to put the resistor.

A pullup or pulldown resistor is used to set an input to a pre-defined state. The button or switch is then used to override that pre-defined state. With your circuit you are just controlling the flow of electrons around a simple loop, from power, through resistor, through LED and back to power. The button just completes that circuit. There is no "input" to place into a pre-defined state. Hence no pullup or pulldown resistor.

0

A series resistor is needed to prevent excess current thru the LED or thru the IO pin. 270 ohm to 1K ohm works well.

schematic

simulate this circuit – Schematic created using CircuitLab

The internal pullup in the Arduino processer is 30-50K ohm. The external resistor is a current limit resistor. (5V - Vf-led)/resistor = current. (5V - 2.2V)/270 ohm = 10.3mA. Vf of the LED will vary by color from say 2.2V for a Red to 3.5V for a blue or white. Insert values if known, or use a 270 to 1K resistor and measure Vf across the LED, then adjust resistor as needed for desired brightness (more current = brighter).

2
  • 270Ohm pull-up? Isn't that a bit excessive? That would result in 18.5mA of current when the button is pressed, which is a bit wasteful.
    – Gerben
    Jan 14, 2019 at 16:30
  • See additonal explanation above.
    – CrossRoads
    Jan 14, 2019 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.