Position: Index > Simple Circuit >

Simple Arduino LED projects

2015-01-08 12:16  
Declaration:We aim to transmit more information by carrying articles . We will delete it soon, if we are involved in the problems of article content ,copyright or other problems.

In this article I will add some simple Arduino LED projects starting with basic ones like how to turn on an LED, blinking, and more. Every step will have the code, the schematic, photos of the project and sometimes a video tutorial.

Let’s start with the simplest led project which consists in turn on an LED. You can use an external one or use the one soldered on the board (pin 13).

Turn ON an LED Sketch
arduino led projectThis is a very simple arduino project where a led is turned on by setting the pin 13 as output, then write it with a high value, in our case that means that pin 13 will deliver 5 volts.

void setup() {
  pinMode(13, OUTPUT); // set pin 13 as output
  digitalWrite(13, HIGH); // set pin 13 as high or 1
}

void loop() {
  // left empty
}

If you want to turn on more leds then set other pins as OUTPUT and HIGH.
Next lets blink some leds.

Blinking leds sketch

void setup() {
  pinMode(13, OUTPUT); // set pin 13 as output
  pinMode(12, OUTPUT); // set pin 12 as output
}

void loop() {
  digitalWrite(13, HIGH); // set pin 13 as high or 1
  digitalWrite(12, LOW); // set pin 12 as low or 0
  delay(1000); // wait 1000 ms
  digitalWrite(12, HIGH); // set pin 13 as high or 1
  digitalWrite(13, LOW); // set pin 12 as low or 0
  delay(1000); // wait 1000 ms
}

“Knight Rider” effect sketch

int del=100; // sets a default delay time
void setup() {
  // initialize the digital pins as outputs:
  for (int i = 2; i<=8 ; i  ) {
    pinMode(i, OUTPUT);
  } // end of for loop
} // end of setup

void loop() {
  for (int i = 2; i<=8; i  ) { // blink from LEDs 2 to 8
    digitalWrite(i, HIGH);
    delay(del);
    digitalWrite(i, LOW);
  }
  for (int i = 7; i>=3; i--) { // blink from LEDs 8 to 3
    digitalWrite(i, HIGH);
    delay(del);
    digitalWrite(i, LOW);
  }
}

Fading LED sketch

int ledPin = 9;    // LED connected to digital pin 9

void setup()  { 
  // nothing happens in setup 
} 

void loop()  { 
  // fade in from min to max in increments of 5 points:
  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue  =5) { 
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect    
    delay(30);                            
  } 

  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) { 
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect    
    delay(30);                            
  } 
}

More arduino led projects will be added soon. Thank you!


Reprinted Url Of This Article:
http://electroschematics.com/6766/simple-arduino-led-projects/