Published:2012/9/24 4:02:00 Author:muriel | Keyword: Arduino, LED | From:SeekIC
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 This 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 sketchvoid 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 sketchint 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 sketchint 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!?
2 Responses to “Simple Arduino LED projects”
Reprinted Url Of This Article:
http://www.seekic.com/circuit_diagram/LED_and_Light_Circuit/Simple_Arduino_LED_projects.html
Print this Page | Comments | Reading(3)
Code: