The Arduino Mega 2560 Rev3 is still one of the most useful Arduino boards when a project needs a large number of physical I/O pins.
Its ATmega2560 provides:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
54 dedicated digital header pins 16 analog inputs 15 PWM outputs 4 hardware UARTs SPI I2C / TWI 6 external interrupt pins 256 kB Flash 8 kB SRAM 4 kB EEPROM 16 MHz clock 5 V logic |
There is one important detail that is easy to miss:
|
1 2 3 4 5 6 7 8 9 |
D0-D53 = 54 dedicated digital pins A0-A15 = analog inputs = also digital D54-D69 |
So the current Arduino AVR core defines:
|
1 2 3 4 |
70 digital pin numbers |
even though Arduino’s product specification correctly describes the board as having 54 dedicated digital I/O pins plus 16 analog inputs.
Arduino Mega 2560 Quick Pinout
| Function | Pins |
|---|---|
| Dedicated digital GPIO | D0-D53 |
| Analog inputs | A0-A15 |
| Analog pins as digital | D54-D69 |
| PWM | D2-D13, D44-D46 |
| UART0 | D0 RX0, D1 TX0 |
| UART1 | D19 RX1, D18 TX1 |
| UART2 | D17 RX2, D16 TX2 |
| UART3 | D15 RX3, D14 TX3 |
| I2C / TWI | D20 SDA, D21 SCL |
| SPI | D50 MISO, D51 MOSI, D52 SCK, D53 SS |
| External interrupts | D2, D3, D18, D19, D20, D21 |
| Built-in LED | D13 |
| Logic level | 5 V |
Main Microcontroller: ATmega2560
The Mega 2560 Rev3 is based on the:
|
1 2 3 4 5 6 |
ATmega2560 8-bit AVR 16 MHz |
The board is much less powerful computationally than modern Arduino R4, ESP32 or STM32 boards, but its strength is the amount of I/O exposed in a simple 5 V architecture.
It remains particularly useful for:
- large relay panels;
- 3D printers and CNC controllers;
- many switches or limit sensors;
- multiple serial devices;
- robotics;
- large LED/control panels;
- legacy 5 V shields.
Memory
The ATmega2560 provides:
|
1 2 3 4 5 6 |
256 kB Flash 8 kB SRAM 4 kB EEPROM |
The Arduino AVR core reserves part of Flash for the bootloader, so the maximum application image is slightly smaller than the physical 256 kB.
The current board definition allows approximately:
|
1 2 3 4 |
253,952 bytes |
for a normal Mega 2560 sketch.
Why SRAM Is the Real Limitation
For many Mega projects, Flash is plentiful but:
|
1 2 3 4 |
8 kB SRAM |
is the limiting resource.
Large:
- strings;
- display buffers;
- JSON documents;
- arrays;
- network buffers;
can consume SRAM surprisingly quickly.
Use PROGMEM and the Arduino F() macro where appropriate when storing large constant text.
Digital GPIO: D0-D53
The board exposes 54 dedicated digital pins numbered:
|
1 2 3 4 |
D0-D53 |
Each can be configured with:
|
1 2 3 4 5 6 |
pinMode(pin, INPUT); pinMode(pin, INPUT_PULLUP); pinMode(pin, OUTPUT); |
and used with:
|
1 2 3 4 5 6 |
digitalRead(pin); digitalWrite(pin, HIGH); digitalWrite(pin, LOW); |
Complete Digital Pin to AVR Port Mapping
| Arduino pin | ATmega2560 port pin | Important alternate function |
|---|---|---|
| D0 | PE0 | RX0 |
| D1 | PE1 | TX0 |
| D2 | PE4 | PWM / INT4 |
| D3 | PE5 | PWM / INT5 |
| D4 | PG5 | PWM |
| D5 | PE3 | PWM |
| D6 | PH3 | PWM |
| D7 | PH4 | PWM |
| D8 | PH5 | PWM |
| D9 | PH6 | PWM |
| D10 | PB4 | PWM |
| D11 | PB5 | PWM |
| D12 | PB6 | PWM |
| D13 | PB7 | PWM / LED_BUILTIN |
| D14 | PJ1 | TX3 |
| D15 | PJ0 | RX3 |
| D16 | PH1 | TX2 |
| D17 | PH0 | RX2 |
| D18 | PD3 | TX1 / INT3 |
| D19 | PD2 | RX1 / INT2 |
| D20 | PD1 | SDA / INT1 |
| D21 | PD0 | SCL / INT0 |
| D22-D29 | PA0-PA7 | GPIO |
| D30-D37 | PC7-PC0 | GPIO |
| D38 | PD7 | GPIO |
| D39 | PG2 | GPIO |
| D40 | PG1 | GPIO |
| D41 | PG0 | GPIO |
| D42-D49 | PL7-PL0 | GPIO |
| D50 | PB3 | MISO |
| D51 | PB2 | MOSI |
| D52 | PB1 | SCK |
| D53 | PB0 | SS |
Analog Pins A0-A15
The Mega provides 16 analog inputs:
|
1 2 3 4 |
A0-A15 |
They are connected to the ATmega2560 ADC through:
|
1 2 3 4 5 6 7 8 |
A0-A7 → PF0-PF7 A8-A15 → PK0-PK7 |
The ATmega2560 ADC has:
|
1 2 3 4 |
10-bit resolution |
so the normal Arduino result is:
|
1 2 3 4 |
0-1023 |
Analog Pins Are Also Digital Pins
The Arduino AVR core maps:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
A0 = D54 A1 = D55 A2 = D56 A3 = D57 A4 = D58 A5 = D59 A6 = D60 A7 = D61 A8 = D62 A9 = D63 A10 = D64 A11 = D65 A12 = D66 A13 = D67 A14 = D68 A15 = D69 |
So this is valid:
|
1 2 3 4 5 |
pinMode(A0, OUTPUT); digitalWrite(A0, HIGH); |
and equivalent to using digital pin 54.
Why the Core Says 70 Digital Pins
In the current Mega AVR variant:
|
1 2 3 4 |
NUM_DIGITAL_PINS = 70 |
because:
|
1 2 3 4 5 6 7 8 |
D0-D53 + D54-D69 / A0-A15 = 70 addressable digital positions |
This does not contradict Arduino’s product specification of 54 digital pins; it simply reflects the dual use of the analog header.
PWM Pins
The Mega has 15 hardware PWM outputs:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
D2 D3 D4 D5 D6 D7 D8 D9 D10 D11 D12 D13 D44 D45 D46 |
Use:
|
1 2 3 4 |
analogWrite(pin, value); |
with values:
|
1 2 3 4 |
0-255 |
for the normal 8-bit Arduino API.
PWM Timer Mapping
| Pin | AVR timer output |
|---|---|
| D2 | Timer3B |
| D3 | Timer3C |
| D4 | Timer0B |
| D5 | Timer3A |
| D6 | Timer4A |
| D7 | Timer4B |
| D8 | Timer4C |
| D9 | Timer2B |
| D10 | Timer2A |
| D11 | Timer1A |
| D12 | Timer1B |
| D13 | Timer0A |
| D44 | Timer5C |
| D45 | Timer5B |
| D46 | Timer5A |
Why Timer Mapping Matters
Libraries for:
- Servo;
- motor control;
- tone generation;
- frequency measurement;
- custom PWM;
may reconfigure an AVR timer.
If a library takes control of Timer5, for example, PWM behaviour on:
|
1 2 3 4 5 6 |
D44 D45 D46 |
may change.
Likewise, Timer0 is important to Arduino’s:
|
1 2 3 4 5 6 |
millis() micros() delay() |
timekeeping, so low-level changes to Timer0 require care.
Four Hardware UARTs
This is one of the Mega’s greatest advantages over an UNO.
| Arduino object | RX | TX |
|---|---|---|
| Serial | D0 | D1 |
| Serial1 | D19 | D18 |
| Serial2 | D17 | D16 |
| Serial3 | D15 | D14 |
This allows the board to talk simultaneously to several serial devices such as:
- GPS;
- RS-232/RS-485 adapters;
- motor controllers;
- GSM/LTE modems;
- industrial instruments;
- another microcontroller.
Serial vs Serial1/2/3
The main:
|
1 2 3 4 |
Serial |
port on D0/D1 is also connected to the board’s ATmega16U2 USB interface.
That means USB serial communication shares the UART0 signals.
If possible, keep:
|
1 2 3 4 |
Serial |
for PC debugging and use:
|
1 2 3 4 5 6 |
Serial1 Serial2 Serial3 |
for external hardware.
Example: Using Two Hardware Serial Devices
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
void setup() { Serial.begin(115200); // PC Serial1.begin(9600); // GPS Serial2.begin(19200); // RS-485 interface } void loop() { if (Serial1.available()) { Serial.write(Serial1.read()); } } |
I2C / TWI Pins
The main I²C bus is:
|
1 2 3 4 5 |
D20 = SDA D21 = SCL |
Use:
|
1 2 3 4 5 6 |
#include <Wire.h> Wire.begin(); |
On Rev3 boards, SDA/SCL are also duplicated at the dedicated SDA/SCL header positions near AREF.
Those are not a second I²C bus; they connect to the same D20/D21 signals.
I2C Voltage
The Mega is a:
|
1 2 3 4 |
5 V logic |
board.
Be careful with modern 3.3 V I²C devices.
Some breakout boards include level shifting or safe pull-ups; others do not.
Check the sensor board rather than assuming every I²C module is 5 V tolerant.
SPI Pins
The hardware SPI bus is:
|
1 2 3 4 5 6 7 |
D50 = MISO D51 = MOSI D52 = SCK D53 = SS |
The same SPI signals are also available on the ICSP header.
Important Shield Compatibility Detail
On an UNO R3:
|
1 2 3 4 |
SPI is also on D10-D13 |
but on Mega 2560 the main SPI signals are:
|
1 2 3 4 |
D50-D53 |
Good R3-compatible shields take SPI from the ICSP header, which lets the same shield work on both UNO and Mega.
Older shields that hard-wire SPI to D11-D13 may not work correctly on a Mega without modification.
SS Pin and SPI Master Mode
The hardware slave-select pin is:
|
1 2 3 4 |
D53 / PB0 |
If the Mega is operating as an SPI master, it is good practice to keep the hardware SS pin configured as an output even if another GPIO is used as the actual peripheral chip-select.
External Interrupt Pins
The Mega has six commonly exposed external interrupt pins:
|
1 2 3 4 5 6 7 8 9 |
D2 D3 D18 D19 D20 D21 |
The current Arduino core maps them as:
| Arduino pin | Arduino interrupt number | AVR interrupt |
|---|---|---|
| D2 | 0 | INT4 |
| D3 | 1 | INT5 |
| D21 | 2 | INT0 |
| D20 | 3 | INT1 |
| D19 | 4 | INT2 |
| D18 | 5 | INT3 |
Use digitalPinToInterrupt()
Do not hard-code the interrupt number unless you have a specific low-level reason.
Use:
|
1 2 3 4 5 6 7 8 |
attachInterrupt( digitalPinToInterrupt(2), myISR, RISING ); |
This is clearer and more portable.
Pin-Change Interrupts Are More Limited
The ATmega2560 also has pin-change interrupts, but they are not available on every Mega header pin.
The current Arduino AVR core exposes PCINT support on groups including:
|
1 2 3 4 5 6 |
D10-D13 D50-D53 D62-D69 / A8-A15 |
This matters for libraries such as software serial or custom pulse-capture code that depend on pin-change interrupts rather than the six dedicated external interrupts.
SoftwareSerial Limitation on Mega
Because pin-change interrupt support is limited, not every Mega pin can be used as a SoftwareSerial receive pin.
The current AVR core specifically identifies receive-capable groups such as:
|
1 2 3 4 5 6 |
D10-D13 D50-D53 A8-A15 |
In practice, Mega already has four hardware UARTs, so hardware serial is usually the better choice.
Built-In LED
The onboard LED is connected to:
|
1 2 3 4 5 |
D13 PB7 |
Use:
|
1 2 3 4 |
LED_BUILTIN |
instead of hard-coding 13 when writing portable Arduino examples.
Power Pins
The power header includes:
- IOREF;
- RESET;
- 3.3 V;
- 5 V;
- GND;
- VIN.
VIN
Arduino’s current pinout specifies:
|
1 2 3 4 5 |
VIN input 6-20 V |
The commonly recommended operating range is typically narrower than the absolute accepted input range because the linear regulator must dissipate heat.
For sustained loads, a regulated 5 V supply or efficient external converter is often preferable to dropping a high VIN through the onboard linear regulator.
Logic Voltage
The Mega 2560 is a:
|
1 2 3 4 |
5 V logic board |
This is important when connecting:
- ESP32 modules;
- modern sensors;
- SD cards;
- 3.3 V displays;
- radio modules.
Do not connect a 5 V Mega output directly to a 3.3 V-only input unless the receiving device is explicitly 5 V tolerant.
GPIO Current Limit
Arduino’s official pinout specifies:
|
1 2 3 4 5 |
maximum recommended current per I/O pin 20 mA |
Do not drive:
- motors;
- relays;
- high-power LEDs;
- solenoids;
directly from the microcontroller.
Use a transistor, MOSFET, driver IC or relay driver.
3.3 V Pin Limit
The official Arduino pinout lists:
|
1 2 3 4 5 |
maximum current from 3.3 V pin 50 mA |
The 3.3 V pin is not intended to power large radio modules or high-current peripherals.
AREF
The:
|
1 2 3 4 |
AREF |
pin provides an external analog reference option.
It can be used with:
|
1 2 3 4 |
analogReference(EXTERNAL); |
when a carefully controlled ADC reference voltage is required.
Do not apply an external reference blindly while using the default internal reference configuration.
RESET
Pulling:
|
1 2 3 4 |
RESET |
low restarts the ATmega2560.
The board also contains a physical reset button and automatic reset circuitry used during upload.
ICSP Headers
The board contains ICSP headers for:
- ATmega2560 programming/SPI;
- ATmega16U2 USB-interface programming.
The main MCU ICSP header exposes the hardware SPI bus and is important for shield compatibility.
ATmega16U2 USB Interface
The Mega 2560 Rev3 does not have native USB in the ATmega2560 itself.
Instead, the board uses a separate:
|
1 2 3 4 |
ATmega16U2 |
as the USB-to-serial interface.
This is why:
|
1 2 3 4 |
Serial |
maps to hardware UART0 on D0/D1 while USB communication is translated by the second AVR chip.
Mega 2560 vs Modern 32-Bit Boards
The Mega’s:
|
1 2 3 4 5 6 |
16 MHz 8-bit CPU 8 kB SRAM |
is slow and memory-limited compared with modern boards.
But it still offers several practical advantages:
- large physical I/O count;
- four UARTs;
- 5 V logic;
- mature libraries;
- huge shield ecosystem;
- predictable AVR timing.
Common Pinout Mistake 1: Using UNO SPI Pins
On Mega:
|
1 2 3 4 5 6 7 8 |
SPI D50 MISO D51 MOSI D52 SCK D53 SS |
not:
|
1 2 3 4 |
D11-D13 |
as on UNO.
Common Pinout Mistake 2: Forgetting A0-A15 Can Be Digital
If you run out of digital pins, you can use:
|
1 2 3 4 |
A0-A15 |
as normal GPIO.
That effectively gives the Mega up to:
|
1 2 3 4 |
70 addressable digital pin numbers |
when the analog inputs are not required for ADC use.
Common Pinout Mistake 3: Using D20/D21 for Interrupts and I2C at the Same Time
D20/D21 are both:
|
1 2 3 4 5 6 |
SDA/SCL and external-interrupt-capable pins |
The electrical pins can only carry one actual signal at a time.
If they are actively used for I²C, do not assume they are also freely available for unrelated interrupt inputs.
Common Pinout Mistake 4: Treating Serial as an Independent USB Port
The ATmega2560’s:
|
1 2 3 4 |
Serial |
uses D0/D1.
The USB interface is connected to those same UART0 signals through the ATmega16U2.
External hardware on D0/D1 can therefore interfere with uploads or PC serial communication.
Common Pinout Mistake 5: Driving Too Much Current
The large number of Mega pins can encourage designs with many LEDs or relays connected directly to GPIO.
Do not confuse:
|
1 2 3 4 |
many pins |
with:
|
1 2 3 4 |
high current capability |
Use external drivers for significant loads and consider the ATmega2560’s port-group and total-current limits as well as the per-pin recommendation.
Quick Pinout Reference
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
Arduino Mega 2560 Rev3 MCU ATmega2560 16 MHz 5 V logic Memory 256 kB Flash 8 kB SRAM 4 kB EEPROM Dedicated digital D0-D53 Analog A0-A15 10-bit ADC Analog as digital A0 = D54 ... A15 = D69 PWM D2-D13 D44-D46 UART0 D0 RX0 D1 TX0 UART1 D19 RX1 D18 TX1 UART2 D17 RX2 D16 TX2 UART3 D15 RX3 D14 TX3 I2C D20 SDA D21 SCL SPI D50 MISO D51 MOSI D52 SCK D53 SS External interrupts D2 D3 D18 D19 D20 D21 Built-in LED D13 GPIO current 20 mA recommended maximum per pin 3.3 V output 50 mA maximum VIN 6-20 V documented input |
Final Thoughts
The Arduino Mega 2560 is old hardware, but its pinout remains extremely useful when a project needs lots of conventional 5 V I/O.
Its strongest features are:
- 54 dedicated digital pins;
- 16 analog inputs that can also become D54-D69;
- 15 PWM outputs;
- four hardware UARTs;
- hardware SPI and I²C;
- six external interrupt pins;
- large, easy-to-probe headers.
The most important pinout rules to remember are:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
SPI → D50-D53 I2C → D20/D21 Serial1 → D19/D18 Serial2 → D17/D16 Serial3 → D15/D14 PWM → D2-D13 + D44-D46 A0-A15 → can also be D54-D69 |
For projects that need large amounts of RAM, Wi-Fi or modern 32-bit processing, a newer board will be faster and easier.
For large 5 V control systems with many sensors, switches and serial devices, the Mega 2560 remains one of Arduino’s most straightforward platforms.