In this tutorial, we’re going to show you how to blink an LED.  If you want to control Led more than, don’t worry! Let’s read for and array lesson, then you can do self-actualization what you want!  

HARDWARE REQUEST

  • x01 Arduino Uno
  • x01 5mm LED
  • x01 220Ohm resistor 

CIRCUIT

image developed using Fritzing. For more circuit examples, see the Fritzing project page

CODE AND EXPLAIN

 

First, when using an LED, we have to pinMode OUTPUT at Digital pin used for the LED. For example, now we connect the LED to pin 13. The following code should be in void setup ().

pinMode(13, OUTPUT);

For turning on the LED, we ’ll need to change the code that tells the Arduino which pins will get the HIGH and LOW output signals. That’s done everywhere there’s a digitalWrite() function. We specify that pin 13 get the HIGH signal.

digitalWrite(13,HIGH);

The above code will supply 5V voltage to pin 13. The voltage will go through the 220ohm resistor to the LED (the led will be lighted without burning, otherwise we can choose other resistors <= 10kOhm). To turn off the LED, we use the function below: (see more about LOW)

digitalWrite(13,LOW);

Now At pin 13, the voltage is 0V => LED is off. For seeing the LED state is turned on or off that you have to stop compiling for a time enough feeling by our eyes (just say that but you only stop the compiling in a few milliseconds). So that the delay function is created to do this (How many milliseconds to stop this!)

The following code is full code of today’s lesson

int led = 13;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}

Source: Arduino.vn