Simple Labs' Quick Start Kit for Arduino - LED Interfacing - How To?
The world of LEDS
LEDs (Light Emitting Diodes) are the most commonly used of electronic components. They are everywhere – torches, displays, indicators, etc. Every project will eventually end up having atleast one led. The Official Arduino Boards and most of the Clones do come with an on-board LED which you can try with the default blink program found in the File->Examples->Basic menu of Arduino IDE.
So How to Connect a LED?
The Long of the LED is the Anode (Positive Terminal!) and the short led is the Cathode(Negative Terminal).
The Terminals of the LED
Place the LED as shown
Place a Current Limiting Resistor (too much current passing through an LED can burn it!) between the negative terminal of the LED and the '-'ve terminal on the power rail (we will soon connect this to the '-'ve (aka ground) of our Arduino Board!)
Take a wire from the pin marked 'GND' of your arduino and connect it to the '-'ve power rail of the breadboard. Now all points of the '-' ve power rail will be connected to the ground of the arduino!
Next, Connect a wire between the 11th pin of the arduino(yes the 11th pin and not the 13th pin!) and the positive terminal of the LED. This is going to be our control line for the LED
Programming to control the LED
So how can you control a LED? Well there are only 2 ways to control an LED. you can either switch it ON / OFF or you can control the intensity with which it glows (Very much like a fan!). So lets see how to do the first control - ON/OFF (we can call this digital control! Very much 0s & 1s)
Try the following code. [Blink.ino]
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
void setup() {
// initialize the digital pin as an output.
// We have our LED connected to Pin 11
pinMode(11, OUTPUT); // Sets the 11th pin as an Output pin
}
void loop() {
digitalWrite(11, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(11, LOW); // set the LED off
Next, Lets see how to control the intensity of the LED.
The Intensity can be varied by controlling the voltage applied to the individual pins. If you take a look at the 11th PIN on the arduino, you would see a marking 'PWM' next to it (Remember we connected our LED to the 11th pin). The PWM pins in addition to generating digital HIGH / LOW signals can generate analog voltages between 0 & 5.The PWM Pins [Pins 3,5,6,9,10,11] that can generate a PWM signal of 8-bit resolution.[8-bits can represent a maximum value of 255, and a 8-bit resolution here means that 5 volts is represented by 255 divisions. So if you want to generate 1 volt, you would use the value 51]The analogWrite function will take a 8-bit numerical value as a parameter [called duty cycle] and produce an output voltage corresponding to this value. It will set the pin to generate a steady square wave of the specified duty cycle at roughly 490Hz frequency.Finally, when using a pin in the PWM mode, we don't have to use the pinMode() function.Try the following code with the same setup and see how the intensity increases and decreases...[Intensity.ino]
Intensity
Increases the Intensity of a LED from 0 to maximum and on reaching maximum
starts decreasing back to 0
int intensity = 0;
while(intensity < 255) // Check if intensity has reached maximum value, if yes then exit the loop
{
analogWrite(11,intensity);
delay(25);
intensity++;
while(intensity > 0) // Check if intensity has reached minimum value, if yes then exit the loop
intensity--;
Simple Labs' Quick Start Kit for Arduino - RGB LED Interfacing - How To?
The RGB LEDThe RGB led aka the tricolor led is a led that can help generate a multitude of colors by mixing red, blue & green colors. Its more like 3 leds (red, green & blue) put together into a single led.It has 4 pins with 1 of the pins being a common cathode and the other 3 pins acting as anodes for the 3 different colours. by varying the intensity of each of the 3 colours individually, we can generate various colours. This led is the same as 1 pixel of a LED TV!.Here is how to wire it up
Pin Mappings of the RGB LED
Place resistor between the common cathode and the '-'ve terminal
Connect RED to Pin 11, Blue to Pin 10 & Green to Pin 9 on the Arduino (these are PWM pins)
Now try the following code first. This code is a normal digital control of all the three colors separately.[RGB_Blink.ino]
RGB_Blink
Turns on each of the color spectrums for 4 seconds, repeatedly.
// initialize the digital pins as an output.
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(9,LOW);
digitalWrite(11, HIGH);
delay(4000);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
Next Lets get generating Colors, try the following code. Play around with the values and get yourselves comfortable.[RGB.ino]
/* RGB
Sets some random intensity value to the various colours of...
MamToCzegoChcesz