SBRDIYables
Published © GPL3+

Working with Two LEDs

This project demonstrates working with two LEDs and Arduino.

BeginnerProtip26,770
Working with Two LEDs

Things used in this project

Story

Read more

Schematics

Circuit: Working with two LED

Make Connections as shown in the figure

Schematic Diagram

Code

Blinking of two LED

Arduino
const int LED_red = 3;
const int LED_green = 6;

void setup() {
    pinMode (LED_red, OUTPUT);
    pinMode (LED_red, OUTPUT);
}

void loop() {
    digitalWrite (LED_red, HIGH);
    digitalWrite (LED_green, LOW);
    delay (1000);
    digitalWrite (LED_red, LOW);
    digitalWrite (LED_green, HIGH);
    delay (1000);
}

Fading effects of two LEDs

Arduino
const int LED_red = 3;
const int LED_green = 6;

void setup() {
    pinMode (LED_red, OUTPUT);
    pinMode (LED_green, OUTPUT);
}

void loop() {
    for (int brightness=1; brightness<=255; brightness++)
    {
      analogWrite (LED_red, brightness);
      delay (5);
    }
    for (int brightness=255; brightness>0; brightness--)
    {
      analogWrite (LED_green, brightness);
      delay (5);
    }
    for (int brightness=255; brightness>0; brightness--)
    {
      analogWrite (LED_red, brightness);
      delay (5);
    }
    for (int brightness=1; brightness<=255; brightness++)
    {
      analogWrite (LED_green, brightness);
      delay (5);
    }
}

Credits

SBR
37 projects • 52 followers
Mechanical Engineer
DIYables
0 projects • 88 followers
I would like to invite you to join and add your projects to DIYables platform https://www.hackster.io/diyables

Comments