Simple LED Blinking with Arduino using Wokwi Simulator

Simple LED Blinking with Arduino

In this post, we’ll explore a basic Arduino sketch that demonstrates how to control multiple LEDs using digital pins. This example will help you get started with pin control and timing using the Arduino Wokwi platform.

 

Circuit Setup:
1. Connect the anode (long leg) of each LED to pins 3, 4, and 5 on the Arduino.
2. Connect the cathode (short leg) of each LED to ground through a resistor.

The Code:
Below is the Arduino code that will blink the LEDs in sequence, turning one on at a time while keeping the others off.

void setup()
{
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
}

void loop()
{
digitalWrite(3, HIGH); // Turn LED on pin 3 ON
digitalWrite(4, LOW); // Turn LED on pin 4 OFF
digitalWrite(5, LOW); // Turn LED on pin 5 OFF
delay(2000); // Wait for 2 seconds

digitalWrite(3, LOW); // Turn LED on pin 3 OFF
digitalWrite(4, HIGH); // Turn LED on pin 4 ON
digitalWrite(5, LOW); // Turn LED on pin 5 OFF
delay(2000); // Wait for 2 seconds

digitalWrite(3, LOW); // Turn LED on pin 3 OFF
digitalWrite(4, LOW); // Turn LED on pin 4 OFF
digitalWrite(5, HIGH); // Turn LED on pin 5 ON
delay(2000); // Wait for 2 seconds
}

Explanation:
setup() Function: This function initializes the digital pins 3, 4, and 5 as output pins.
loop() Function: This function continuously cycles through turning each LED on for 2 seconds while the others are off.

Conclusion:
This simple project demonstrates how to control multiple outputs using Arduino. You can modify the code to add more LEDs or change the timing to suit your needs. Happy coding!

©Postnetwork-All rights reserved.