Button controlled led using Arduino Uno

A button-controlled LED project is a simple yet useful Arduino project. Here's a guide to get you started:

Components Needed
- Arduino Board (e.g., Arduino Uno)
- LED
- Pushbutton Switch
- Resistor (220-ohm or suitable for your LED)
- Breadboard and jumper wires

Circuit Setup
1. Connect the LED to a digital pin on the Arduino (e.g., pin 13).
2. Connect the pushbutton switch to a digital pin on the Arduino (e.g., pin 2).
3. Connect the LED's cathode (short leg) to a resistor, and then connect the other end of the resistor to a GND pin on the Arduino.

Code
const int buttonPin = 2;
const int ledPin = 13;

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  int buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }
}
How it Works
1. The pushbutton switch is connected to a digital pin on the Arduino.
2. When the button is pressed, the digital pin reads HIGH, and the LED turns on.
3. When the button is released, the digital pin reads LOW, and the LED turns off.

Tips
- You can add a pull-down resistor to the button circuit to prevent floating inputs.
- You can also use the `buttonState == LOW` condition to invert the button's behavior.

Do you have any questions about this project or would you like to explore more advanced button-controlled projects?

Popular posts from this blog

Blink led light using Arduino r3

Temperature sensor using Arduino Uno

Traffic light using Arduino Uno