SBRDIYables
Published © GPL3+

Working with LED

A step by step procedure to work with LED using Arduino.

BeginnerProtip6,296
Working with LED

Things used in this project

Story

Read more

Schematics

Circuit Diagram

Created using Visio Professional

Breadboard Diagram

Make connections as shown in the figure.

Schematic Diagram

Code

LED forever ON

Arduino
const int LED = 3;

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

void loop() {
    digitalWrite (LED, HIGH);
    
}

Blinking of LED

Arduino
const int LED = 3;

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

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

LED ON for 2s and OFF for 3s

Arduino
const int LED = 3;

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

void loop() {
    digitalWrite (LED, HIGH);
    delay (2000);
    digitalWrite (LED, LOW);
    delay (3000);
}

Fading Effects of LED

Arduino
const int LED_ao = 3;

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

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

Fade IN and Fade OUT at different speeds

Arduino
const int LED_ao = 3;

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

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

Credits

SBR
37 projects • 52 followers
Mechanical Engineer
Contact
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
Contact

Comments

Please log in or sign up to comment.