Translate

How to Toggle Two LEDs with Arduino: Pin 13 Red, Pin 12 Blue

 If you’re just starting with Arduino, one of the simplest but most fun projects is controlling multiple LEDs. In this guide, we’ll show you how to toggle two LEDs — a red one on pin 13 and a blue one on pin 12 — using Arduino.


Materials Needed

  • Arduino Uno (or any Arduino board)

  • Red LED

  • Blue LED

  • 100Ω Resistors 

  • Jumper wires


Circuit Diagram


Tip: Always connect the short leg (cathode) of the LED to GND, and the long leg (anode) to the resistor and Arduino pin.


Connection Diagram



  1. Arduino Uno

  2. Two LEDs

  3. Resistor

Then connect Pin 13 → Red LED, Pin 12 → Blue LED, and both cathodes to GND using jumper wires.


Arduino Code

Here’s the full code to toggle the LEDs:

// Pin definitions const int redLED = 13; const int blueLED = 12; void setup() { // Initialize the digital pins as outputs pinMode(redLED, OUTPUT); pinMode(blueLED, OUTPUT); } void loop() { // Turn on Red LED, turn off Blue LED digitalWrite(redLED, HIGH); digitalWrite(blueLED, LOW); delay(1000); // wait 1 second // Turn on Blue LED, turn off Red LED digitalWrite(redLED, LOW); digitalWrite(blueLED, HIGH); delay(1000); // wait 1 second }

How It Works

  1. Setup:

    • pinMode() sets pin 13 and pin 12 as outputs.

  2. Loop:

    • The red LED turns on while the blue LED turns off for 1 second.

    • Then the blue LED turns on while the red LED turns off for 1 second.

    • This creates a toggling effect between the two LEDs.

  3. Delay:

    • delay(1000) controls the speed of toggling.

    • You can change 1000 to 500 for faster blinking or 2000 for slower.


Tips for Beginners

  • Always use a resistor in series with LEDs to prevent burning them out.

  • If LEDs don’t light, check connections: anode (+) goes to pin/resistor, cathode (-) goes to GND.

  • You can extend this project by adding more LEDs or using buttons to toggle manually.

തുടക്കക്കാർക്കായി ഇലക്ട്രോണിക്സ് ലളിതമായി പഠിക്കാം.

Empowering students in Kerala with hands-on technical skills.