Arduino - Blinking a LED

Today I want to show you how to use Arduino to blinking a LED, this is very simple for newbie when you first time to get starting Arduino.

Here you needs to notice that Anode and Cathode for LED. Anode is connect to Arduino pin 13 and Cathode is connect to pin GND.



Open the Arduino IDE and starting coding C programming. 


When you press Verify button, it's will start to compiling source code.


After compiled code are successful you can press Upload button, this function will update your source to Arduino board. Actually it is burning HEX code to ATmega328.  

When you upload complete you can see your Arduino board, LED will starting to blinking.
Here I want to show you when digitalWrite(13, HIGH); the LED to blink the voltage is about 3V,

that means the maximum voltage for the I/O pin, not 5V, therefore we don't need use 200 ohm resistor in here.



 As below are source code, you can copy it and paste to your Arduino IDE.

unsigned int delay_time = 10;

void setup(){
  // setup the pin 13
  pinMode(13, OUTPUT);
}

void loop(){
  // writing the pin 13 to ON
  digitalWrite(13, HIGH);
  // delay 1 second
  delay(1000);
  // writing the pin 12 to OFF
  digitalWrite(13, LOW);
  // delay a moment, the delay_time will increase
  delay(delay_time);
  
  // increase the delay_time value of variable
  delay_time += 10;
  // check when the delay_time are more then 500, reset the value to 10
  if(delay_time >= 500)
    delay_time = 10;
}

The source code really really simple for Arduino newbie, trying it!

Comments

Popular Posts