Selasa, Februari 05, 2013

Turn LED on Turn LED off and Blink Led with Arduino via PC

Turn on, turn off, and blink LED with Arduino board via computer/laptop/notebook/netbook/PC.

What are needed to turn LED on, turn LED off, and blink LED with Arduino? Exactly the first is Arduino board, then what else?

Breadboard
Red LED lamp
Resistor 150 Ω
Jumper Wires

Why do we use 150 Ω resistor?
Because we will string up components like this picture below:

Certain, what we want is LED on with maximal bright due to LED’s ability. More large current flow on LED, then more bright LED’s light, however very important to known that current range is allowed is 10 mA – 20 mA and range voltage is 1,6 V – 3,5 V due to its color character produced.

Voltage work/voltage drop on a LED due to color produced:
  1. Infrared : 1,6 Volt
  2. Red : 1,8 – 2 Volt
  3. Orange : 2,2 Volt
  4. Yellow : 2,4 Volt
  5. Green : 2,6 Volt
  6. Blue : 3 – 3,5 Volt
  7. White : 3 – 3,6 Volt
  8. Ultraviolet : 3,5 Volt

Acconrding to LED Red diffused 5mm datasheet, maximal VF (tegangan work) is 2 Volt, as while voltage is produced of PC USB is 5 Volt. According to Kirchoff Low about voltage at picture above:
VSumber = VLED + VResistor

If current flow more than 20 mA then LED will be burned. To keep LED is not burned, we need resistor as current resistor. It means what we want now is so that current value flow on LED is 20 mA (so that maximal bright)

So, so that voltage value flow on LED is 3 Volt and current value flow is 20 mA, needed a resistor with its resistance value is 150 Ω

Connecting the components
Now, first make sure that Arduino in off position. We can turn off Arduino by unplug USB Cable or by unplug Power Selector Jumper on Arduino board. Then connect all components like picture below:

Make sure, longer Led’s foot (Anode) is connected to digital pin 10 and must always connected to 5 Volt supply and shorter Led’s foot (Katode) is connected to ground (Gnd). Then turb Led on and connect USB cable

Checking Arduino safety
We need to check is current/voltage will flow on Arduino still in range is allowed.
In this case we use voltage source from USB PC at 5 Volt, as while Arduino operating voltage is 5 Volt, its mean safe for Arduino.
Then current flow on Arduino is at 20 mA, as while maximal DC current for each I/O pin is allowed is 40 mA, its mean 20 mA is still safe for Arduino.

Turn LED On
Now open Arduino IDE dan type code below:

int ledpin = 10;

void setup() {
        pinMode(ledpin, OUTPUT);
}

void loop() {
        digitalWrite(ledpin, HIGH);
}

int is abbreviation of integer, integer is a number within the range of 32768 to 32767. Ledpin word on sketch must not ledpin, can be change with anything, like abjad, someone name, etc., please try...
There are definition of using of capital letter and majuscule on writing Arduino sketch. Orange and blue letter on sketch must be written like that in using its capital letter and majuscule.
Now press Verify/Compile button on top of Arduino IDE to make sure there is no fault/error on the code. If this is success, now we can click on upload button to upload code/sketch to Arduino.
If has finished, we can look at the red LED lamp on breadboard ON.

Turn LED off
To turn LED off, just change HIGH letter be LOW, so that our sketch now be like below:

int ledpin = 10;

void setup() {
        pinMode(ledpin, OUTPUT);
}

void loop() {
        digitalWrite(ledpin, LOW);
}

Blink LED
To blink LED lamp, its logic is turn LED on, give time delay, turn LED off, give time delay.
To give time delay its code is delay(time_in_milisecond), example:

delay(1000)

It is code to give time delay for 1000 ms / 1 second, so that sketch to blink LED is:

int ledpin = 10;

void setup() {
        pinMode(ledpin, OUTPUT);
}

void loop() {
        digitalWrite(ledpin, HIGH);
        delay(1000);
        digitalWrite(ledpin, LOW)
        delay(1000);
}

As much as this, if there is something is ununderstood... please ask soon, hopefully useful...
Oh ya... thank’s for visiting... :)

source:
http://www.4shared.com/office/28jkyxPc/ASKManualRev5.html

0 komentar: