PCBX
Published

Arduino UNO LED Delay Circuit Simulation

Bring your projects to life with our Arduino UNO LED Delay Circuit Simulation! It's perfect for beginners who to master timing and circuits.

BeginnerFull instructions provided41
Arduino UNO LED Delay Circuit Simulation

Things used in this project

Story

Read more

Schematics

Arduino UNO LED Delay Circuit

Code

Arduino UNO LED Delay Circuit

Arduino
// Define the pins connected to the LED and the switch
const int ledPin = 8;  // Pin connected to the LED
const int switchPin = 2;  // Pin connected to the switch

// Variable to store the LED state
bool ledState = false;  // Initial LED state is off

void setup() {
  // Set the LED pin mode to output
  pinMode(ledPin, OUTPUT);
  // Set the switch pin mode to input with internal pull-up resistor
  pinMode(switchPin, INPUT_PULLUP);  // Using internal pull-up resistor
}

void loop() {
  // Read the switch state
  int switchState = digitalRead(switchPin);
  
  // If the switch is pressed (switch state is LOW because of the internal pull-up resistor)
  if (switchState == LOW) {
    // Turn on the LED
    digitalWrite(ledPin, HIGH);
    // Delay for a period of time, for example, 5 seconds
    delay(5000);
    // Turn off the LED
    digitalWrite(ledPin, LOW);
  }
}

Credits

PCBX
33 projects • 10 followers
Customer Success: Your one-stop solution for PCB and PCBA services, plus component sourcing. Enjoy FREE online simulation and EDA.
Contact

Comments

Please log in or sign up to comment.