Advertisement
arduino led project

Simple Arduino LED Projects

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 project 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 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!

15 Comments

Join the conversation!

Error! Please fill all fields.
  • r de vreede

    I see that you just can use c/c++. I’m more an anolgue guy but seeing some nice thing done and the small costs, i think i’m bying one, and programming those things, older ones , i have done a lot, also assembler .
    It can saves you a lot of time, but i thought this was a school-project thing. Thx for the info

  • Zum1UDontNo

    Uh, is there any setup with the Arduino you need? Like, wires or something? Most Arduino projects require an LED setup.

  • STEVE MENS

    I need a circuit dat can light my 12v. LED lamps of 50-60 pcs. in sequential. 1-2-3 to 10. en reset en start over

  • txdo_msk

    Is this guy always a d1( |<?

    Hey, justaminute, how about I pay for a class in manners for you? Obviously you can't afford a book on the subject.

    Anyway, folks, do google Arduino, DIY, programming, there's a wealth of knowledge to start from. Venture out on your own. Please ask questions when truly stuck.

  • ashok kumar v

    may I know how to write the program? or can teach me how to learn to program to controller.. Please inform me.. It will useful for me because Iam an engineering student.

    • justaminute

      Ashok, are you expecting P.Marian to provide you with a private tutorial or instruction course to teach you to write assembler or C or C++? Would you also like P.Marian to provide hotel accommodation with all expenses paid? No of course not. You can enrol in Internet courses for a a few thousand pounds because P.Marian certainly will not help you — In fact P.Marian is not even talking to you.
      Do yourself a favour and Google for some excellent free tutorials on the Internet to teach you C or C++ for Arduino controllers or Assembler language for PIC controllers. It’s fun, it’s and it’s free!

  • Spencer

    This is very useful stuff while I’m just beginning. Thanks for the examples – especially with the videos. Question: To get the “fade” is there a special LED required? I tried that out and it just turns on and off…

    • bob

      to learn how to program go to

      http://www.jeremyblum.com/category/arduino-tutorials/page/3/

      This guy is awesome (a word he uses frequently) but his tutorials are verry good.

    • justaminute

      As you have been dumped by P.Marian, let me answer your question:
      No there is no special fade LED. The fade effect is achieved by switching off and on a standard LED very quickly in short bursts. It can be done using a techniques called PWM (pulse width modulation). If it doesn’t work for you then you failed to load the program into the Arduino. P.Marian just copied code from another site but you can get more information to help you from the Arduion playground site.

  • chris

    whats the cost

    • justaminute

      £15.00 to £50.00. Whay don’t you Google it yourself? Just search for “Arduino UNO uk price” or US$ price or Euro price or whatever currency you use. By the way Would you like to be fed and dressed while you are waiting for everyone to Googles your prices?

  • hilario

    Hi,
    i appreciate this project simple LED arduino.

    How to buy this arduino?

    • justaminute

      Google Ebay, Amazon, Adafriut, Maplin or just about anywhere. Let your fingers do the walking. Prices vary for the same thing from £15.00 to %50.00 just look for best prices. Don’t wait for the author as P.Marian seems to have deserted you.

  • olaniyi lukman

    i appreciate ds project

Looking for the latest from TI?