Selasa, Maret 19, 2013

Turn on, turn off, and blink 10 Led with Arduino via PC

This article is continuation of previous article , on this article we need red led and 150 Ω resistor each as much as 10.

Checking Arduino Safety
Actually, its circuit same with circuit controlling 1 Led lamp which use 1 input/output pin, while now we make circuit controlling 10 Led which use 10 input/output pin, the circuit image is below:


We will use voltage source from PC USB at 5 Volt, so that voltage out from each digital input/output pin at 5 Volt, while Arduino operating voltage is 5 Volt, it means safe for Arduino. Then current current flow on Arduino is 20 mA, while maximum DC current each I/O pin is allowed is 40 mA, it means 20 mA still safe for Arduino. (see details on previous article)

Turn 10 Led on
Its sketch as follows:

int ledpin2 = 2;
int ledpin3 = 3;
int ledpin4 = 4;
int ledpin5 = 5;
int ledpin6 = 6;
int ledpin7 = 7;
int ledpin8 = 8;
int ledpin9 = 9;
int ledpin10 = 10;
int ledpin11 = 11;

void setup() {
        pinMode(ledpin2, OUTPUT);
        pinMode(ledpin3, OUTPUT);
        pinMode(ledpin4, OUTPUT);
        pinMode(ledpin5, OUTPUT);
        pinMode(ledpin6, OUTPUT);
        pinMode(ledpin7, OUTPUT);
        pinMode(ledpin8, OUTPUT);
        pinMode(ledpin9, OUTPUT);
        pinMode(ledpin10, OUTPUT);
        pinMode(ledpin11, OUTPUT);
}

void loop() {
        digitalWrite(ledpin2, HIGH);
        digitalWrite(ledpin3, HIGH);
        digitalWrite(ledpin4, HIGH);
        digitalWrite(ledpin5, HIGH);
        digitalWrite(ledpin6, HIGH);
        digitalWrite(ledpin7, HIGH);
        digitalWrite(ledpin8, HIGH);
        digitalWrite(ledpin9, HIGH);
        digitalWrite(ledpin10, HIGH);
        digitalWrite(ledpin11, HIGH);
}

Turn 10 Led off
Its sketch as follws:

int ledpin2 = 2;
int ledpin3 = 3;
int ledpin4 = 4;
int ledpin5 = 5;
int ledpin6 = 6;
int ledpin7 = 7;
int ledpin8 = 8;
int ledpin9 = 9;
int ledpin10 = 10;
int ledpin11 = 11;

void setup() {
        pinMode(ledpin2, OUTPUT);
        pinMode(ledpin3, OUTPUT);
        pinMode(ledpin4, OUTPUT);
        pinMode(ledpin5, OUTPUT);
        pinMode(ledpin6, OUTPUT);
        pinMode(ledpin7, OUTPUT);
        pinMode(ledpin8, OUTPUT);
        pinMode(ledpin9, OUTPUT);
        pinMode(ledpin10, OUTPUT);
        pinMode(ledpin11, OUTPUT);
}

void loop() {
        digitalWrite(ledpin2, LOW);
        digitalWrite(ledpin3, LOW);
        digitalWrite(ledpin4, LOW);
        digitalWrite(ledpin5, LOW);
        digitalWrite(ledpin6, LOW);
        digitalWrite(ledpin7, LOW);
        digitalWrite(ledpin8, LOW);
        digitalWrite(ledpin9, LOW);
        digitalWrite(ledpin10, LOW);
        digitalWrite(ledpin11, LOW);
}

Blink 10 Led by turn
To turn led on by turn, its logic like this, for example we have 4 Led, its way is tun Led 1 on and give time delay, turn Led 1 off then turn Led 2 on directly and give time delay, turn Led 2 off then turn Led 3 on directly and give time delay, turn Led 3 off then turn Led 4 on directly and give time delay, turn Led 4 off then turn Led 1 on directly and give time delay, and like that forward

For 10 Leds, the sketch as follows:

int ledpin2 = 2;
int ledpin3 = 3;
int ledpin4 = 4;
int ledpin5 = 5;
int ledpin6 = 6;
int ledpin7 = 7;
int ledpin8 = 8;
int ledpin9 = 9;
int ledpin10 = 10;
int ledpin11 = 11;

void setup() {
        pinMode(ledpin2, OUTPUT);
        pinMode(ledpin3, OUTPUT);
        pinMode(ledpin4, OUTPUT);
        pinMode(ledpin5, OUTPUT);
        pinMode(ledpin6, OUTPUT);
        pinMode(ledpin7, OUTPUT);
        pinMode(ledpin8, OUTPUT);
        pinMode(ledpin9, OUTPUT);
        pinMode(ledpin10, OUTPUT);
        pinMode(ledpin11, OUTPUT);
}

void loop() {
        digitalWrite(ledpin2, HIGH);
        delay(100);
        digitalWrite(ledpin2, LOW);
        digitalWrite(ledpin3, HIGH);
        delay(100);
        digitalWrite(ledpin3, LOW);
        digitalWrite(ledpin4, HIGH);
        delay(100);
        digitalWrite(ledpin4, LOW);
        digitalWrite(ledpin5, HIGH);
        delay(100);
        digitalWrite(ledpin5, LOW);
        digitalWrite(ledpin6, HIGH);
        delay(100);
        digitalWrite(ledpin6, LOW);
        digitalWrite(ledpin7, HIGH);
        delay(100);
        digitalWrite(ledpin7, LOW);
        digitalWrite(ledpin8, HIGH);
        delay(100);
        digitalWrite(ledpin8, LOW);
        digitalWrite(ledpin9, HIGH);
        delay(100);
        digitalWrite(ledpin9, LOW);
        digitalWrite(ledpin10, HIGH);
        delay(100);
        digitalWrite(ledpin10, LOW);
        digitalWrite(ledpin111, HIGH);
        delay(100);
        digitalWrite(ledpin111, LOW);
}

The result can be watched on following video:


Oke, as mush as this, if there is something not understood… please contact sahabat… up to friends… in facebook ar others… ^_^
Salam alaik… :)

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

0 komentar: