Blinking LED In Arduino Mega 2560

Introduction:

In this article I will explain how to blink an LED in Arduino Mega 2560.

Parts Of List:
  • Arduino Mega 2560
  • LED-3
  • Bread Board
  • USB Cable.
LED:
  • Light Emitting Diode (LED) can emit the light.
  • The LED glows when the voltage is applied.
         Figure 1: LED

Connection: 
Take three LEDs and fix in the Bread Board.

First LED connection:
  • Positive pin = 13;
  • Negative pin = Gnd.
Second LED connection:
  • Positive pin = 12;
  • Negative pin = Gnd.
Third LED connection:
  • Positive pin = 11;
  • Negative pin = Gnd.
Programming:
  1. int led1 = 13;  
  2. int led2 = 12;  
  3. int led3 = 11;  
  4. void setup()  
  5. {  
  6.     pinMode(13, OUTPUT);  
  7.     pinMode(12, OUTPUT);  
  8.     pinMode(11, OUTPUT);  
  9. }  
  10. void loop()   
  11. {  
  12.     digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)  
  13.     delay(1000); // wait for a second  
  14.     digitalWrite(13, LOW); // turn the LED off by making the voltage LOW  
  15.     delay(1000); // wait for a second  
  16.     digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)  
  17.     delay(1000); // wait for a second  
  18.     digitalWrite(12, LOW); // turn the LED off by making the voltage LOW  
  19.     delay(1000); // wait for a second  
  20.     digitalWrite(11, HIGH); // turn the LED on (HIGH is the voltage level)  
  21.     delay(1000); // wait for a second  
  22.     digitalWrite(11, LOW); // turn the LED off by making the voltage LOW  
  23.     delay(1000); // wait for a second  
  24. }  
Explanation:
  • When the first LED is ON then automatically take the delay time.
  • And the second LED is ON and finally the third LED is also ON.
  • It can be repeatedly done.
Output:

Read more articles on Arduino:

Up Next
    Ebook Download
    View all
    Learn
    View all