Arduino Mega 2560 Pinout: GPIO, PWM, ADC, UART, SPI and I2C

Arduino Mega 2560 Rev3 pinout guide: all GPIO, PWM, ADC, UART, SPI, I2C and interrupt pins, ATmega2560 port mapping, analog pins as D54-D69, power limits and timer assignments.

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:

There is one important detail that is easy to miss:

So the current Arduino AVR core defines:

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:

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:

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:

for a normal Mega 2560 sketch.

Why SRAM Is the Real Limitation

For many Mega projects, Flash is plentiful but:

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:

Each can be configured with:

and used with:

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:

They are connected to the ATmega2560 ADC through:

The ATmega2560 ADC has:

so the normal Arduino result is:

Analog Pins Are Also Digital Pins

The Arduino AVR core maps:

So this is valid:

and equivalent to using digital pin 54.

Why the Core Says 70 Digital Pins

In the current Mega AVR variant:

because:

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:

Use:

with values:

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:

may change.

Likewise, Timer0 is important to Arduino’s:

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:

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:

for PC debugging and use:

for external hardware.

Example: Using Two Hardware Serial Devices

I2C / TWI Pins

The main I²C bus is:

Use:

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:

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:

The same SPI signals are also available on the ICSP header.

Important Shield Compatibility Detail

On an UNO R3:

but on Mega 2560 the main SPI signals are:

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:

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:

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:

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:

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:

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:

Use:

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:

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:

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:

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:

The 3.3 V pin is not intended to power large radio modules or high-current peripherals.

AREF

The:

pin provides an external analog reference option.

It can be used with:

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:

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:

as the USB-to-serial interface.

This is why:

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:

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:

not:

as on UNO.

Common Pinout Mistake 2: Forgetting A0-A15 Can Be Digital

If you run out of digital pins, you can use:

as normal GPIO.

That effectively gives the Mega up to:

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:

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:

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:

with:

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

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:

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.

Share your love