Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Pushbutton-Controlled LED

View and Edit Project In Cirkit DesignerImage of Arduino UNO Pushbutton-Controlled LED

Circuit Documentation

Summary

This circuit consists of an Arduino UNO microcontroller, a pushbutton, and a red LED. The pushbutton is used to control the LED. When the pushbutton is pressed, the LED turns on; otherwise, the LED remains off.

Component List

Arduino UNO

Pushbutton

LED: Two Pin (red)

Wiring Details

Arduino UNO

Pushbutton

LED: Two Pin (red)

Code Documentation

Arduino UNO Code

// Pin assignments
const int buttonPin = 2;  // Push button connected to digital pin 2
const int ledPin = 13;    // LED connected to digital pin 13

void setup() {
  pinMode(buttonPin, INPUT);  // Set button pin as input
  pinMode(ledPin, OUTPUT);    // Set LED pin as output
}

void loop() {
  int buttonState = digitalRead(buttonPin);  // Read the state of the push button
  
  if (buttonState == HIGH) {                 // If button is pressed
    digitalWrite(ledPin, HIGH);              // Turn ON the LED
  } else {
    digitalWrite(ledPin, LOW);               // Turn OFF the LED
  }
}

This code sets up the Arduino UNO to read the state of the pushbutton and control the LED accordingly. The buttonPin is configured as an input, and the ledPin is configured as an output. In the loop function, the state of the pushbutton is read, and the LED is turned on or off based on whether the button is pressed.