Why do you use 2 resistors in the first project? And when should I use a resistor? I know you should use one with a led, but i am just a beginner.

bekathwia2 months ago

The LED's resistor limits current so the LED doesn't draw more than it can handle, and the button's resistor is used as a pull-up, explained in this lesson:

So the resistor is "pulling the pin up" to 5V, and so it's called a pull-up resistor. Without one, pin 2 would be not connected to anything until the button is pressed. This is called "floating", and can result in random noise from static electricity and electromagnetic interference. Similarly a resistor can be used to tie a pin to ground, which is called a pull-down resistor.

To learn more about resistors, try Randy's Electronics Class: