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

Arduino Leonardo-Based Sequential LED Lighting System with Pushbutton Control

View and Edit Project In Cirkit DesignerImage of Arduino Leonardo-Based Sequential LED Lighting System with Pushbutton Control

Circuit Documentation

Summary

This circuit consists of an Arduino Leonardo microcontroller, five red LEDs, a pushbutton, and a resistor. The circuit is designed to light up the LEDs sequentially when the pushbutton is pressed. The LEDs will remain lit for a random duration before turning off.

Component List

Arduino Leonardo (Rev3b)

LED: Two Pin (red)

Pushbutton

Resistor

Wiring Details

Arduino Leonardo (Rev3b)

LED: Two Pin (red)

Pushbutton

Resistor

Code Documentation

const int red1 = 9;
const int red2 = 8;
const int red3 = 7;
const int red4 = 6;
const int red5 = 5;
const int buttonPin = 12;

int buttonState = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(red1, OUTPUT);
  pinMode(red2, OUTPUT);
  pinMode(red3, OUTPUT);
  pinMode(red4, OUTPUT);
  pinMode(red5, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  int randNumber = random(3000,8000);

  buttonState = digitalRead(buttonPin);
  
  if (buttonState == HIGH) {
    digitalWrite(red1, HIGH);
    delay(1000);
    digitalWrite(red2, HIGH);
    delay(1000);
    digitalWrite(red3, HIGH);
    delay(1000);
    digitalWrite(red4, HIGH);
    delay(1000);
    digitalWrite(red5, HIGH);
    delay(randNumber);
    digitalWrite(red1, LOW);
    digitalWrite(red2, LOW);
    digitalWrite(red3, LOW);
    digitalWrite(red4, LOW);
    digitalWrite(red5, LOW);
  } else {
    // Do nothing
  }
}

This code initializes the pins connected to the LEDs as outputs and the pin connected to the pushbutton as an input. In the main loop, it checks the state of the pushbutton. If the button is pressed, it sequentially lights up the LEDs with a delay of 1 second between each LED. After all LEDs are lit, they stay on for a random duration between 3 to 8 seconds before turning off.