If you are new to electronics, and Arduino you may be wondering about Pull Up and Pull Down Resistors.....
Using Pull Up or Pull Down resistors on an input pin allows you to ensure the pin is in a known state when disconnected e.g. when a switch is open.
The reason for this is electrical interference is picked up by the pins of the microcontroller, so if left completely disconnected it will "float" between different values constantly. This is the same as the static you see on an old TV or hear on a radio....
A resistor must be used instead of just connecting the pin directly to GND/VCC, as it allows the pin to be pulled in that direction given no other input. If you connect them without a resistor the input can never change....
When another input is supplied it wins against the resistor, as the route to VCC/GND via the resistor is harder than simply going from the device to your input pin.
If you add a Pull Up resistor (between the pin and 3.3v/5v depending on your board), then you will know that when the switch isn't pressed, the pin will be HIGH.
If you add a Pull Down resistor (between the pin and GND), then you will know that when the switch isn't pressed, the pin will be LOW.
Often these resistors are from 1-10K depending on how "strong" you need the pull to be to stabilize the pin.
In the below Picture: (Left) Pull Up Resistor between IO Pin and VCC, (Right) Pull Down resistor between IO Pin and GND
If you're less fond of wiring, there may be an alternative built into your chip aready!
Many of the different chips used on Arduino boards, have internal pull up / down resistors which can be configured from the software depending on your board.
NOTE - the resistor values on each board vary, and they are often very weak pull up/down signals, which are fine for a disconnected pin, but you may need an external resistor in some scenarios.
To use these simply run the pinMode() function as normal, and instead of INPUT, use INPUT_PULLUP, or INPUT_PULLDOWN as needed. This can be seen below for the ESP32 board which offers both:
Showing Pull Up / Down Resistors in Action
Using the Serial Debugger you can actually watch the noise on a pin, or bounce on a switch visually, allowing you to assess the impact of different resistor values, or to visually explain what this is all about.