
Video
Circuit Diagram

Source Code
1void setup() {
2 pinMode(13, INPUT);
3 pinMode(7, OUTPUT);
4}
5
6void loop() {
7 if (digitalRead(13) == HIGH) {
8 digitalWrite(7, HIGH);
9 } else {
10 digitalWrite(7, LOW);
11 }
12}FAQ
What is a 10 kΩ resistor used for?▾
It is a pull-down resistor: it ensures a stable LOW reading by pulling the pin to GND when the button is not pressed. Without this resistor, the pin would be left floating and would read a random HIGH or LOW, causing the LED to flicker on its own.
Can I connect a button without using a resistor?▾
Yes, using `pinMode(pin, INPUT_PULLUP)` enables the Arduino's internal pull-up resistor. In this case, the button is connected between the pin and GND, and the logic is reversed: it reads LOW when pressed and HIGH when released.
Which pins on the button should I use?▾
On 4-pin buttons, the two opposite pins are already connected internally. Place the button over the empty space in the center of the breadboard and use the diagonal pins; this way, you can be sure you’re selecting the correct pins.
What is the difference between "Push" and "On-Off"?▾
In push mode, the LED lights up only while you hold down the button. In on-off (toggle) mode, each press changes the LED's state, and the LED stays on even after you release the button; this requires a state variable.
