Site Guide

Find your way around the Engineering Club.

Know what you need? Search for a component, concept or project.

Around the site

Start

Labs

TestingExperimental

Build

Club

LearnExperimental

Go a little deeper

Entry points to larger collections. Use Search for individual records.

Learning paths & reference

Inside PiCrawlerExperimental

Inside Inventory

← Mega Components

ELEGOO MEGA · LESSON 2

Blink

Blink the Mega’s onboard L LED once per second.

Configure a digital output and set its timing with delay().

Parts List

  • ELEGOO Mega 2560 R3 is a 5 V ATmega2560 AVR board with many I/O pins and four hardware UARTs for control systems with several peripherals. Long ELEGOO-branded Mega PCB with USB-B and barrel connector, ATmega2560 marking, extended side headers and a large double-row digital header at the end. Read printed Mega labels; its SPI hardware placement is not the same numeric pins as an Uno.
  • A USB-A to USB-B cable carries USB power and, when its data conductors are present, a host/device data link. USB-A plug and square USB-B plug. Inspect the plug shape; micro-USB is not USB-C, and USB-B is the squarer device connector.

Assembly

  1. Leave the external headers unconnected.
  2. Connect the Mega with a USB data cable.
Illustration © ELEGOO. All rights reserved.
Illustration © ELEGOO. All rights reserved. Open full-size ↗
Reviewed pin-to-pin connections
FromToPurpose / notes
Mega: USB-BHost: USB data cable
Mega: LED_BUILTIN / D13Onboard LED: L (already fitted)
Open vector connection diagram ↗

Code

PlatformIO configuration
platformio.ini
[env:mega]
platform = atmelavr@5.3.0
board = megaatmega2560
framework = arduino
monitor_speed = 9600
main.cpp
// Arduino.h provides Arduino functions such as pinMode(), digitalWrite(), and delay().
#include <Arduino.h>

// setup() runs once after power-on or reset. "void" means this function returns no value.
void setup() {
  // The board already has an LED. OUTPUT lets this pin drive that LED.
  pinMode(LED_BUILTIN, OUTPUT);
}

// loop() repeats as long as the board is running.
void loop() {
  // HIGH turns the LED on for this board.
  digitalWrite(LED_BUILTIN, HIGH);
  // delay() waits in milliseconds: 1000 ms is one second.
  delay(1000);
  // LOW turns the LED off.
  digitalWrite(LED_BUILTIN, LOW);
  // Then wait another second before loop() starts again.
  delay(1000);
}

Expected behavior

The L LED repeats about one second on, one second off. No serial output is expected.

Experiments & Challenges

  • Change both 1000 ms delays to 500 ms and compare the period.