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

Arduino UNO Button-Controlled LED Project

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

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 button is pressed, the LED turns on, and when the button is released, the LED turns off.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. Pushbutton

    • Description: A simple pushbutton switch.
    • Pins: Pin 3 (out), Pin 4 (out), Pin 1 (in), Pin 2 (in)
  3. LED: Two Pin (red)

    • Description: A red LED with two pins.
    • Pins: cathode, anode

Wiring Details

Arduino UNO

Pushbutton

LED: Two Pin (red)

Code Documentation

/*
 * This Arduino sketch controls a green LED using a button with a pull-down
 * resistor configuration. When the button is pressed, the LED will turn on.
 * When the button is released, the LED will turn off.
 */

const int buttonPin = 2; // Pin connected to the button
const int ledPin = 13;   // Pin connected to the green LED

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 button
  if (buttonState == HIGH) {
    digitalWrite(ledPin, HIGH); // Turn the LED on
  } else {
    digitalWrite(ledPin, LOW);  // Turn the LED off
  }
}

This code initializes the button pin as an input and the LED pin as an output. In the main loop, it reads the state of the button and turns the LED on or off based on the button's state.