Spring Sale: 5% OFF Over $89, Code: Elephant5; 10% OFF Over $149, Code:Elephant10



Arduino Project: Breathing LED

Posted by Fiona Su on

thumb

Introduction:
After the first two projects, I believe you’ve grown familiar with Arduino. In this project, we will use LED to do something else, simulating breath. Sounds cool? Well, let’s get on with it. We will still be using the same hardware from project 2.
Hardware Required:

  • Arduino board *1
  • USB Cable *1
  • Red M5 LED*1
  • 220Ω Resistor*1
  • Breadboard*1
  • Breadboard Jumper Wire*3

Connection Diagram:
Connection for REV4:

thumb

Connection for Arduino Mega 2560 R3:

thumb

Sample Code:

int ledPin = 11; // define digital pin 11
void setup()
{
pinMode(ledPin, OUTPUT);// define LED pin as output
}
void loop()
{
for (int a=0; a<=255;a++)// set the LED to be brighter gradually 
{
analogWrite(ledPin,a); // turn on LED, regulate light brightness, ranging from 0-255, 255 is the brightest
delay(10); // wait for 0.01S
}
for (int a=255; a>=0;a--) // set LED to be dimming gradually
{
analogWrite(ledPin,a); // turn on LED, regulate light brightness, ranging from 0-255, 255 is the brightest
delay(10); // wait for 0.01S
}
delay(1000);// wait for 1S
}

Result:
LED becomes brighter gradually, wait for 0.01S, then dimming gradually, wait for 1S, and then cycles on, just like the LED is breathing.

0 comments

Leave a comment

Please note, comments must be approved before they are published