🛠 Faire clignoter une LED avec l’Arduino Mega 2560
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
- 1 × Arduino Mega 2560 (Rev3) + USB-B cable
- 1 × 5 mm red LED
- 1 × 330 Ω resistor
- 1 × breadboard and connecting wires
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
- Wrong board selected in the IDE: make sure to choose "Arduino Mega 2560", otherwise the upload will fail (the original bootloader communicates at 115200 bauds via the serial protocol).
- Clone based on a CH340 chip: you must install the CH340/CH341 serial driver, which is absent from official boards with the ATmega16U2.
- Resistor forgotten or LED connected backwards (the short leg, the cathode, goes to ground).
- Forgetting to wait ~1 s after opening the serial port: the automatic DTR reset causes the first bytes sent to be lost.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-led.inoArduinodouble-servo.inoArduinopont-uart.inoArduinopwm-respiration.inoArduinopotentiometre-plotter.inoArduino