Pages

Monday, March 4, 2013

Arduino: LEDs

Arduino LED

Working with LEDs on the arduino? You've come to the right place for some extra information or beginning Code. Note that this is NOT a tutorial and I'll only explain the code quick-'n-easy.
Light-Emitting-Diode (LED) Is a small electronic component that only allows elektricity to flow from one side to the other.

Read on for more information


How to program LEDs with Arduino!
Awsome! Seems like you wanna make a LED light up with the arduino!
Easy just follow these steps and It'll light up in No-time!
It's really easy. Follow the schematic below:

Schematic for LED:

Done making the schematic? Let me explain it quick.
You've connected your LED's Anode to pin 13 and you connected a resistor from the LED's cathode to the power rows. And finally you've connected the power row to the Ground (GND)
(Ofcourse, you can connect the resistor immediatly to the GND.)

Now time to program. The first part of the following code will just activate the LED to make it shine. The second part will add a pause ( DELAY(...); ) and let it blink.

Constant glowing LED:
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
}
Blinking LED with 1 second delay:
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}


Ok the above code can be directly copied to your arduino IDE and be editted.
In the next 'introduction' on arduino I will cover the Servos!

Thanks, Tim.  

2 comments: