#9Beginner

Led Burning with Push Button (Push)

4.9(110)
179 completed
Led Burning with Push Button (Push)
Push control project that turns on the LED when the button is pressed and turns it off when it is released. Teaches button reading and conditional expression usage with digitalRead.

Video

Circuit Diagram

Led Burning with Push Button (Push) - Circuit

Source Code

Arduino (C++)
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.

Led Burning with Push Button (Push) | BlueGrays