Arduino Mega 2560
Interactive Arduino Mega 2560 pinout with all 54 digital pins, 16 analog inputs, four serial ports, I2C on 20/21 and SPI on 50–53, plus a compile-checked blink.
Community draft — report a mistake
The Mega 2560 is the big brother of the Uno: the same 5 V, 16 MHz AVR family, but with eight times the flash, four times the RAM, 54 digital pins, 16 analog inputs and four hardware serial ports.
It is the board to reach for when a project simply runs out of pins — a 3D printer controller, a large LED matrix, a weather station with several serial modules, or an exhibition model with a keypad, a display and a dozen sensors.
Most Uno code runs unchanged. The two things that catch people are the moved I2C pins (20/21) and SPI pins (50–53) — the pinout below highlights both.
Interactive pinout
Hover or tap a pin for its functions and traps. Filter to light up every I2C, ADC or boot pin.
- Safe for most uses
- Works, with a caveat
- Avoid unless you know why
- Power / control
I2C is on 20 and 21 — not A4/A5. Shields designed for the Uno that use A4/A5 for I2C need jumpers to 20/21 (or the SDA/SCL pins near AREF).
SPI moved too: 50 MISO, 51 MOSI, 52 SCK, 53 SS. Keep pin 53 an OUTPUT when the Mega is SPI master, even if your chip-select is elsewhere.
Three spare hardware serial ports. Serial1–3 on pins 14–19 are perfect for GPS, GSM or RS-485 modules while Serial stays free for the USB monitor.
Set up your computer
- Install Arduino IDE 2.x from arduino.cc.
- Boards Manager → install Arduino AVR Boards (we compile against avr 1.8.8).
- Tools → Board → Arduino Mega or Mega 2560, then pick the port that appears when you plug the board in.
Your platformio.ini:
[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
framework = arduino
monitor_speed = 9600[env:megaatmega2560] platform = atmelavr board = megaatmega2560 framework = arduino monitor_speed = 9600
First program
// First program for the Arduino Mega 2560: blink the on-board "L" LED (D13)
// and print to all four hardware serial ports' main one (Serial = USB).
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
Serial.println(F("FlashReady: Mega 2560 blink"));
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
}// First program for the Arduino Mega 2560: blink the on-board "L" LED (D13)
// and print to all four hardware serial ports' main one (Serial = USB).
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
Serial.println(F("FlashReady: Mega 2560 blink"));
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
}Components with Arduino Mega 2560
- DHT22 (AM2302) Arduino C++
- DS3231 real-time clock (RTC) module Arduino C++
- HC-05 Bluetooth serial module Arduino C++
- HC-12 433 MHz wireless serial module Arduino C++
- 4×4 matrix membrane keypad Arduino C++
- 20×4 LCD + I2C backpack Arduino C++
- MAX485 TTL to RS485 module Arduino C++
- MicroSD card module (SPI) Arduino C++
- NEO-6M GPS module (GY-NEO6MV2) Arduino C++
- nRF24L01+ 2.4 GHz transceiver Arduino C++
- RC522 RFID reader (MFRC522, 13.56 MHz) Arduino C++
- SIM800L GSM/GPRS module (2G) Arduino C++
- SSD1306 OLED 0.96″ (128×64, I2C) Arduino C++
- 1.8" ST7735 colour TFT (128×160) Arduino C++
- WS2812B addressable RGB LED strip (NeoPixel) Arduino C++
Common errors
avrdude: stk500v2_ReceiveMessage(): timeout
Wrong board or port selected, or a missing CH340 driver on clones. Choose "Arduino Mega or Mega 2560" and the port that appears when you plug in.
Uno I2C shield does nothing on the Mega
The shield expects I2C on A4/A5. Wire SDA to pin 20 and SCL to pin 21, or use a shield that also routes the SDA/SCL header.
Servo library breaks PWM on some pins
On the Mega the Servo library uses Timer5 first, which disables analogWrite() on pins 44–46 (and pins 11–12 once more than 12 servos are attached).