user52990: 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.

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.

user4143: 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.

user27653: 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.

52990: <p>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.</p>

<p><a href="https://i.stack.imgur.com/U6iKd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U6iKd.png" alt="enter image description here"></a></p>

<p>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.</p>

<p>Many thanks.</p>
 4143: <p>No, you don't.</p>

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

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

<p>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.</p>
 27653: <p>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.</p>

<p>Often for a button-controlling-LED sketch, you will have a button connected between GND and an I/O pin defined as an <code>INPUT_PULLUP</code>, which means the Arduino will be able to read the state of the pin as <code>HIGH</code> (5V) or <code>LOW</code> (0V). The <code>PULLUP</code> 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.</p>

<p>A pull-up resistor causes an otherwise un-driven pin to go to logic <code>HIGH</code>. A pull-down resistor causes an otherwise un-driving pin to go to logic <code>LOW</code>.</p>

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