🚫 Office Closed (Holiday) 📅 We will reopen on Monday 🙏 Thanks for your patience 🚫 Office Closed (Holiday) 📅 We will reopen on Monday 🙏 Thanks for your patience
Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

Insight

Arduino Mega 2560 Pinout: Complete Pin Diagram, Functions & Mapping

The Arduino Mega 2560 Rev3 is a microcontroller development board for projects that need more input/output connections, communication interfaces, and memory than smaller Arduino boards provide. Built around the ATmega2560, it has 54 digital I/O pins, 16 analog inputs, 15 PWM-capable pins, and four hardware UART ports. It also supports SPI and I2C, making it useful for robotics, automation, CNC-related projects, and embedded systems.

This guide explains the Arduino Mega 2560 pin diagram, digital and analog pin functions, PWM timer assignments, communication interfaces, power connections, pin conflicts, and practical wiring examples.

Arduino Mega 2560 Pinout Diagram and Layout

The pinout identifies the board’s main connections and their functions. Use it to locate digital and analog pin groups, communication interfaces, and power connections before wiring your circuit. For physical header orientation and connector placement, use the official Arduino Mega 2560 Rev3 pinout PDF. This logical reference article is not a scale drawing of the board.

Arduino Mega 2560 board connection reference showing the main controller, USB interface, headers, power pins and communication interfaces.
Board-level reference for locating the Arduino Mega 2560 connectors and major components.

Arduino Mega 2560 Specifications and Pin Numbering

Compared with the Arduino Uno, the Mega 2560 offers more memory, additional I/O connections, and four hardware serial ports.

SpecificationDetails
MicrocontrollerATmega2560
Board revisionRev3
Operating voltage5V
Clock speed16 MHz
Digital I/O pins54
Analog inputs16
PWM outputs15
Hardware UART ports4
Flash memory256 KB (8 KB used by bootloader)
SRAM8 KB
EEPROM4 KB
ADC resolution10-bit

Understanding Arduino Mega 2560 Pin Numbers

The board has 54 digital connections numbered D0–D53 and 16 analog inputs labelled A0–A15. The analog inputs can also be addressed as digital pins D54–D69. These are aliases for the same physical connections, not 16 extra connectors.

Analog PinDigital AliasAnalog PinDigital Alias
A0D54A8D62
A1D55A9D63
A2D56A10D64
A3D57A11D65
A4D58A12D66
A5D59A13D67
A6D60A14D68
A7D61A15D69

Arduino Mega 2560 Pin Configuration and Description

Arduino Mega 2560 Rev3 pinout infographic showing power pins, digital and analog pins, PWM, UART, SPI and I2C connections.
Arduino Mega 2560 Rev3 pinout overview with digital, analog, power and communication pin groups.

The pins support general digital input/output and alternate functions such as PWM, serial communication, external interrupts, and SPI. Check for function conflicts before assigning a pin to a device.

Digital I/O Pins D0–D53

Digital PinsMain / Alternate Function
D0Digital I/O, RX0 / Serial0
D1Digital I/O, TX0 / Serial0
D2PWM, Timer3B, interrupt index 0
D3PWM, Timer3C, interrupt index 1
D4PWM, Timer0B
D5PWM, Timer3A
D6–D8PWM, Timer4
D9–D10PWM, Timer2
D11–D12PWM, Timer1
D13PWM, onboard LED, Timer0A
D14–D15Serial3 TX/RX
D16–D17Serial2 TX/RX
D18–D19Serial1 TX/RX, external interrupts
D20–D21I2C SDA/SCL, external interrupts
D22–D43General-purpose digital I/O
D44–D46PWM, Timer5
D47–D49General-purpose digital I/O
D50–D53SPI communication
Detailed Arduino Mega 2560 pin description, including AVR port mappings and analog-to-digital aliases.

Use pinMode(), digitalRead(), and digitalWrite() to control digital pins. This example blinks an external LED connected to D22:

const int ledPin = 22;

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  digitalWrite(ledPin, HIGH);
  delay(1000);
  digitalWrite(ledPin, LOW);
  delay(1000);
}

LED safety: Connect the LED in series with a suitable current-limiting resistor. D0 and D1 connect to the USB-to-serial interface, so external devices on these pins can interfere with sketch uploads or Serial Monitor use.

Onboard LED and Internal Pull-Up Resistors

The built-in LED connects to D13 and can be controlled through LED_BUILTIN. Digital inputs also support internal pull-up resistors, which help prevent a switch input from floating.

const int buttonPin = 22;

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {
  if (digitalRead(buttonPin) == LOW) {
    Serial.println("Button pressed");
  }
}

Connect the push button between D22 and GND. The input reads HIGH while the button is open and LOW when pressed. Learn more in our guide to pull-up resistors and their working principles.

Analog Input Pins A0–A15 and ADC

The Mega 2560 has 16 analog inputs. Its 10-bit ADC converts the input voltage into a value from 0 to 1023. With the default 5V reference, 0V is approximately 0, 2.5V is approximately 512, and 5V is approximately 1023. Actual readings depend on the reference voltage, supply conditions, and input signal.

const int sensorPin = A0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(sensorPin);
  Serial.println(sensorValue);
  delay(500);
}

Analog Reference (AREF)

The AREF pin provides an option for an external ADC reference voltage. The Mega 2560 supports the default 5V reference, internal 1.1V and 2.56V references, and an external reference. Do not apply an external voltage to AREF without configuring the reference correctly. For an external reference, select analogReference(EXTERNAL) before reading analog inputs.

PWM Pins and Hardware Timer Mapping

PWM (Pulse Width Modulation) produces a digital signal with an adjustable duty cycle. The Mega 2560 has 15 PWM-capable pins: D2–D13 and D44–D46.

PWM PinHardware TimerOutput Compare Channel
D2Timer3OC3B
D3Timer3OC3C
D4Timer0OC0B
D5Timer3OC3A
D6Timer4OC4A
D7Timer4OC4B
D8Timer4OC4C
D9Timer2OC2B
D10Timer2OC2A
D11Timer1OC1A
D12Timer1OC1B
D13Timer0OC0A
D44Timer5OC5C
D45Timer5OC5B
D46Timer5OC5A

For example, analogWrite(6, 128) produces an approximately 50% duty cycle with the standard 8-bit PWM configuration. Use a series resistor if the output controls an LED directly.

The ATmega2560 has six hardware timers, Timer0 through Timer5. Arduino timing functions such as millis(), micros(), and delay() depend on Timer0. Changing its configuration can affect those functions. Libraries that configure other timers can also interfere with PWM outputs assigned to the same timer. The Arduino core uses Timer0A for standard analogWrite() on D13; the physical port pin also has an OC1C alternate function at the microcontroller level.

External Interrupt Pins

The Mega 2560 supports six external interrupt inputs through attachInterrupt().

Arduino Interrupt IndexDigital PinAdditional Function
0D2PWM
1D3PWM
2D21I2C SCL
3D20I2C SDA
4D19Serial1 RX
5D18Serial1 TX

Use digitalPinToInterrupt() to select the correct interrupt for a board pin. The FALLING mode triggers when the input changes from HIGH to LOW. Arduino also supports LOW, RISING, and CHANGE modes where the hardware supports them.

Power, Ground, and Reference Pins

PinFunctionDescription
VINExternal power inputReceives external supply voltage
5VRegulated 5V railBoard 5V supply rail
3.3VRegulated outputSupplies compatible 3.3V modules
GNDGroundCommon electrical reference
IOREFI/O referenceIndicates board logic voltage
RESETReset inputResets the microcontroller when pulled LOW
AREFAnalog referenceSets ADC reference when configured

Arduino recommends an external input voltage between 7V and 12V. The specified input voltage limit is 6V–20V, but that wider range is not the preferred operating range. A higher input voltage can cause the onboard regulator to overheat.

Arduino specifies 20mA as the recommended DC current per digital I/O pin. The ATmega2560 datasheet lists 40mA per I/O pin as an absolute maximum rating, not a normal operating target. The official Mega 2560 Rev3 specification lists a maximum current of 50mA for the 3.3V output. The current available from the 5V rail depends on the power source, USB limits, regulator temperature, and total board load.

If peripherals require significant current, use a separate regulated power supply and connect grounds appropriately. See our guide to power supplies for embedded systems.

Arduino Mega 2560 Communication Pin Mapping

UART and Serial Communication Pins

The Mega 2560 has four hardware serial ports:

Serial PortRX PinTX Pin
Serial0D0D1
Serial1D19D18
Serial2D17D16
Serial3D15D14
void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  if (Serial1.available()) {
    char receivedData = Serial1.read();
    Serial.write(receivedData);
  }
}

When connecting two UART devices, cross their TX and RX signals and connect their grounds. Serial0 shares its connection with the board’s USB-to-serial interface. On the official Rev3 board, the ATmega16U2 handles USB-to-TTL serial communication. Use Serial1, Serial2, or Serial3 for external serial devices when you want to keep Serial0 available for programming and Serial Monitor use. Check logic-voltage compatibility first.

SPI Pins and ICSP Header

The Mega 2560 exposes four main SPI signals:

SPI SignalArduino Mega PinFunction
MISOD50Master In, Slave Out
MOSID51Master Out, Slave In
SCKD52Serial Clock
SSD53Slave Select

The same SPI signals are available on the main ATmega2560 ICSP header. Multiple SPI devices can share MISO, MOSI, and SCK; each normally needs its own chip-select signal. The main microcontroller ICSP header is different from the separate programming header for the ATmega16U2 USB interface.

I2C Pins: SDA and SCL

The Mega 2560 uses D20 for SDA and D21 for SCL. Start I2C communication with the Arduino Wire library:

#include <Wire.h>

void setup() {
  Wire.begin();
}

void loop() {
}

Multiple I2C devices can share SDA and SCL when their addresses and electrical requirements allow it. D20 and D21 also support external interrupts, so do not assign them to unrelated functions at the same time. For a closer look at the differences, read our comparison of I2C, SPI, and UART communication protocols.

Arduino Mega 2560 Pin Conflicts and Safe Pin Selection

Digital PinAlternate FunctionImportant Caution
D0–D1Serial0 RX/TXUSB serial interaction
D2–D3PWM and external interruptsShared hardware functions
D4–D5PWM / Timer0 or Timer3Timer configuration
D6–D8PWM / Timer4Timer4 sharing
D9–D10PWM / Timer2Timer2 sharing
D11–D12PWM / Timer1Timer1 sharing
D13PWM and onboard LEDLED and Timer0A
D18–D19Serial1 and interruptsUART/interrupt overlap
D20–D21I2C and interruptsI2C/interrupt overlap
D44–D46PWM / Timer5Timer5 sharing
D50–D53SPISPI peripheral usage

Before wiring a circuit, identify the communication interfaces your devices need, reserve UART/SPI/I2C pins, choose PWM pins after checking timer use, keep D0 and D1 available for USB serial when needed, and compare each component’s voltage and current requirements with the board limits. Check the shield or module pinout instead of assuming every accessory uses the same mapping.

Practical Wiring Example: I2C Module and Digital Input

In this example, an I2C module uses D20 and D21, while a push button connects to D22.

I2C Module PinArduino Mega 2560
SDAD20
SCLD21
GNDGND
VCCAccording to module specifications
Push Button TerminalArduino Mega 2560
First terminalD22
Second terminalGND
const int buttonPin = 22;

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {
  if (digitalRead(buttonPin) == LOW) {
    Serial.println("Button pressed");
  }
  delay(50);
}

When the button is open, the internal pull-up keeps D22 HIGH. Pressing the button connects the pin to GND, so the reading changes to LOW. Check the I2C module’s voltage requirements before connecting power and signal pins. Some modules need level shifting because they do not support the Mega’s 5V logic. Also check whether the module already includes I2C pull-up resistors.

Arduino Mega 2560 Compatibility with CNC and RAMPS Projects

The Arduino Mega 2560 is used in some CNC and 3D-printer controller configurations. Compatible RAMPS hardware and firmware such as GRBL-Mega-5X can use the board as part of a motion-control system. However, the standard Mega pinout does not define the assignments used by every CNC shield or firmware. The controller configuration determines stepper signals, limit switches, spindle controls, and other connections. Check the exact shield and firmware mapping. For one example, see the GRBL-Mega-5X pinout documentation for RAMPS 1.4.

Official Arduino Mega 2560 Pinout PDF, Datasheet, and Schematic

Use manufacturer documentation to confirm pin functions, electrical specifications, and microcontroller connections.

Arduino Mega 2560 wiring example connecting an I2C I/O expander module, an infrared sensor module and a push button with color-coded power, ground, SDA and SCL wires.
Illustrative I2C expander wiring example. Confirm the exact expander board pinout and sensor voltage requirements before building the circuit.
ResourcePurpose
Arduino Mega 2560 Rev3 DocumentationOfficial board information
Official Arduino Mega 2560 Pinout PDFComplete board-level pin diagram
Arduino Mega 2560 DatasheetTechnical and electrical documentation
Arduino Mega 2560 Rev3 Store SpecificationsOfficial board specifications
Arduino Mega 2560 SchematicCircuit connections and board design
Arduino External Interrupt ReferenceInterrupt configuration
Arduino Mega Pin Mapping SourceDigital aliases and timer assignments

Download the Arduino Mega 2560 Pinout Cheat Sheet

Use this printable reference when wiring a circuit or checking pin assignments during development: Download the Arduino Mega 2560 Pinout Cheat Sheet (PDF).

Frequently Asked Questions

How many digital and analog pins does Arduino Mega 2560 have?

It has 54 digital I/O pins (D0–D53) and 16 analog inputs (A0–A15). The analog inputs can also be addressed as D54–D69.

How many PWM pins does Arduino Mega 2560 have?

It has 15 PWM-capable pins: D2–D13 and D44–D46. Use analogWrite() to set the PWM output value.

Which pins support external interrupts?

The six pins are D2, D3, D18, D19, D20, and D21. Their Arduino interrupt indexes are 0, 1, 5, 4, 3, and 2 respectively when listed in that pin order.

What are the SPI pins?

D50 is MISO, D51 is MOSI, D52 is SCK, and D53 is SS. The main ATmega2560 ICSP header also exposes these signals.

Which pins are used for I2C?

D20 is SDA and D21 is SCL. Use the Arduino Wire library.

What are the four UART pin pairs?

Serial0: RX D0, TX D1. Serial1: RX D19, TX D18. Serial2: RX D17, TX D16. Serial3: RX D15, TX D14.

Can I use analog pins as digital pins?

Yes. A0–A15 can also be used as digital pins D54–D69. Both names refer to the same physical connections.

What is the recommended current per digital pin?

Arduino specifies 20mA as the recommended DC current per digital I/O pin. The 40mA figure is an absolute maximum rating, not a normal operating target.

How much current can the 3.3V pin supply?

The official Mega 2560 Rev3 specification lists a maximum current of 50mA for the 3.3V output.

What is the recommended input voltage?

Arduino recommends 7V to 12V external input. The specified input voltage limit is 6V–20V.

Can Arduino Uno shields work with Mega 2560?

Many Uno shields physically fit, but physical fit does not guarantee electrical or signal compatibility. Check pin assignments, SPI connections, ICSP routing, and voltage requirements.

Where can I download the official pinout PDF?

Download it from the official Arduino Mega 2560 Rev3 pinout PDF.

Conclusion

The Arduino Mega 2560 pinout gives you a practical reference for connecting sensors, displays, motors, and communication modules. Its 54 digital I/O pins, 16 analog inputs, 15 PWM outputs, and four hardware UART ports provide plenty of options for projects that need multiple connections.

Account for alternate functions, timer assignments, communication overlaps, and electrical limits before connecting hardware. Keep the official pinout diagram nearby, and check the relevant shield or module documentation whenever a connection depends on a specific hardware configuration.

Printable reference: Download the Arduino Mega 2560 Pinout Cheat Sheet (PDF).

Build with Confidence

Working on Project

Project Completion Rate
84%
Client Satisfaction
94%
Client Happiness & Trust
100%
Facebook
Twitter
LinkedIn

Related Articles

Leave a Comment

Your email address will not be published. Required fields are marked *