How to Blink a LED with Arduino Mega

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, 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 on the first line of the code below, inserting “//” before “#” and replacing 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 the upload button.

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

7 thoughts on “How to Blink a LED with Arduino Mega

  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.

  4. this is the first code that has atually worked for me, all the rest had errors, thanks so much for this code 😀

Leave a Reply to togel Cancel reply

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

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.