🛠 Faire clignoter une LED avec l’Arduino Mega 2560

Arduino Mega 2560 (Rev3) · debutant · Schéma : IMG-mega-2560-debutant-1-clignotement-led.svg — Arduino Mega 2560, LED avec résistance 330 Ω sur la broche 13, cathode vers la masse

Objectives

Discover the Arduino Mega 2560 board (ATmega2560 at 16 MHz, 256 KB of flash, 8 KB of SRAM) by turning an LED on and off regularly. By the end of this tutorial, you will know how to wire an LED with its current-limiting resistor, write a complete Arduino sketch (setup and loop), and upload it to the board.

Hardware

Each pin on the Mega provides 20 mA under recommended use and 40 mA at absolute maximum: exceeding this value risks permanently damaging the microcontroller. The 330 Ω resistor protects the LED (approximately 8 mA at 5 V).

Complete code

// Clignotement LED — Arduino Mega 2560
const uint8_t LED_PIN = 13;   // broche de la LED externe

void setup {
  pinMode(LED_PIN, OUTPUT);   // la broche devient une sortie
}

void loop {
  digitalWrite(LED_PIN, HIGH);  // LED allumée
  delay(500);                   // 500 ms
  digitalWrite(LED_PIN, LOW);   // LED éteinte
  delay(500);                   // 500 ms
}

Expected verification

In the Arduino IDE, select the "Arduino Mega 2560" board (the ATmega2560 microcontroller is selected automatically) and the correct serial port, then upload. The LED should blink periodically every 500 ms. The onboard LED (pin 13, physical pin PB7 of port B) blinks at the same time.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials