Arduino Mega – Blinking a LED

In this tutorial I am going to show you how to blink a LED using Arduino Mega 2560. You can use any Arduino board. If you don’t have the optional parts written below, you can do this tutorial without them.

Parts Required

  • Arduino Mega 2560;
  • Breadboard (optional);
  • 1x LED (optional);
  • 1x 330 ohm or 220 ohm resistor (optional);
  • Jumper wires (optional).

This tutorial uses a LED attached to an Arduino digital pin. I use pin 7 to connect LED, but you can use any of the digital pins.

Building the Circuit and Schematic

In case you have the LED, the resistor and breadboard you can connect all together following the schematic below. Here we are using “D7” pin from Arduino Mega.
If you don’t have these parts, so you can also use the built-in LED of the Arduino board, which in this case is connected internally to the “D13” pin.

Code

Step 1: Start from open Arduino IDE. If you don´t have it installed yet you can download the last version from here: https://www.arduino.cc/en/Main/Donate

Step 2: Select your board on “Tools -> Board -> Board Manager…”.

Step 3: Select your COM Port “Tools -> Port->…”.

Step 4: Then copy the code below to your Arduino IDE project and save it. In case you don´t have a LED you can use the built-in LED from the Arduino development board, just comments the first line of the code below, inserting “//” before “#” and replaces LED with LED_BUILTIN throughout the code;

#define LED 7
// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED as an output.
  pinMode(LED , OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED , HIGH);//turn the LED On by making the voltage HIGH
  delay(500);                       // wait half a second
  digitalWrite(LED , LOW);// turn the LED Off by making the voltage LOW
  delay(500);                       // wait half a second
}

Step 5: Connect your Arduino to your PC using micro-usb to usb cable and upload the code, pressing upload button.

If you upload the code without errors, the LED blink every half a second.

5 thoughts on “Arduino Mega – Blinking a LED

  1. Nice post. I be taught something more challenging on totally different blogs everyday. It would all the time be stimulating to learn content material from other writers and apply a little one thing from their store. I’d prefer to use some with the content material on my weblog whether you don’t mind. Natually I’ll provide you with a hyperlink on your web blog. Thanks for sharing.

  2. It抯 actually a cool and useful piece of information. I抦 glad that you shared this helpful information with us. Please keep us informed like this. Thanks for sharing.

  3. I blog frequently and I truly thank you for your information. This article has really peaked my interest. I’m going to take a note of your website and keep checking for new details about once per week. I opted in for your RSS feed too.

Leave a Reply

Your email address will not be published. Required fields are marked *