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 Specifications and Pin Numbering
Compared with the Arduino Uno, the Mega 2560 offers more memory, additional I/O connections, and four hardware serial ports.
| Specification | Details |
|---|---|
| Microcontroller | ATmega2560 |
| Board revision | Rev3 |
| Operating voltage | 5V |
| Clock speed | 16 MHz |
| Digital I/O pins | 54 |
| Analog inputs | 16 |
| PWM outputs | 15 |
| Hardware UART ports | 4 |
| Flash memory | 256 KB (8 KB used by bootloader) |
| SRAM | 8 KB |
| EEPROM | 4 KB |
| ADC resolution | 10-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 Pin | Digital Alias | Analog Pin | Digital Alias |
|---|---|---|---|
| A0 | D54 | A8 | D62 |
| A1 | D55 | A9 | D63 |
| A2 | D56 | A10 | D64 |
| A3 | D57 | A11 | D65 |
| A4 | D58 | A12 | D66 |
| A5 | D59 | A13 | D67 |
| A6 | D60 | A14 | D68 |
| A7 | D61 | A15 | D69 |
Arduino Mega 2560 Pin Configuration and Description

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 Pins | Main / Alternate Function |
|---|---|
| D0 | Digital I/O, RX0 / Serial0 |
| D1 | Digital I/O, TX0 / Serial0 |
| D2 | PWM, Timer3B, interrupt index 0 |
| D3 | PWM, Timer3C, interrupt index 1 |
| D4 | PWM, Timer0B |
| D5 | PWM, Timer3A |
| D6–D8 | PWM, Timer4 |
| D9–D10 | PWM, Timer2 |
| D11–D12 | PWM, Timer1 |
| D13 | PWM, onboard LED, Timer0A |
| D14–D15 | Serial3 TX/RX |
| D16–D17 | Serial2 TX/RX |
| D18–D19 | Serial1 TX/RX, external interrupts |
| D20–D21 | I2C SDA/SCL, external interrupts |
| D22–D43 | General-purpose digital I/O |
| D44–D46 | PWM, Timer5 |
| D47–D49 | General-purpose digital I/O |
| D50–D53 | SPI communication |

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 Pin | Hardware Timer | Output Compare Channel |
|---|---|---|
| D2 | Timer3 | OC3B |
| D3 | Timer3 | OC3C |
| D4 | Timer0 | OC0B |
| D5 | Timer3 | OC3A |
| D6 | Timer4 | OC4A |
| D7 | Timer4 | OC4B |
| D8 | Timer4 | OC4C |
| D9 | Timer2 | OC2B |
| D10 | Timer2 | OC2A |
| D11 | Timer1 | OC1A |
| D12 | Timer1 | OC1B |
| D13 | Timer0 | OC0A |
| D44 | Timer5 | OC5C |
| D45 | Timer5 | OC5B |
| D46 | Timer5 | OC5A |
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 Index | Digital Pin | Additional Function |
|---|---|---|
| 0 | D2 | PWM |
| 1 | D3 | PWM |
| 2 | D21 | I2C SCL |
| 3 | D20 | I2C SDA |
| 4 | D19 | Serial1 RX |
| 5 | D18 | Serial1 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
| Pin | Function | Description |
|---|---|---|
| VIN | External power input | Receives external supply voltage |
| 5V | Regulated 5V rail | Board 5V supply rail |
| 3.3V | Regulated output | Supplies compatible 3.3V modules |
| GND | Ground | Common electrical reference |
| IOREF | I/O reference | Indicates board logic voltage |
| RESET | Reset input | Resets the microcontroller when pulled LOW |
| AREF | Analog reference | Sets 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 Port | RX Pin | TX Pin |
|---|---|---|
| Serial0 | D0 | D1 |
| Serial1 | D19 | D18 |
| Serial2 | D17 | D16 |
| Serial3 | D15 | D14 |
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 Signal | Arduino Mega Pin | Function |
|---|---|---|
| MISO | D50 | Master In, Slave Out |
| MOSI | D51 | Master Out, Slave In |
| SCK | D52 | Serial Clock |
| SS | D53 | Slave 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 Pin | Alternate Function | Important Caution |
|---|---|---|
| D0–D1 | Serial0 RX/TX | USB serial interaction |
| D2–D3 | PWM and external interrupts | Shared hardware functions |
| D4–D5 | PWM / Timer0 or Timer3 | Timer configuration |
| D6–D8 | PWM / Timer4 | Timer4 sharing |
| D9–D10 | PWM / Timer2 | Timer2 sharing |
| D11–D12 | PWM / Timer1 | Timer1 sharing |
| D13 | PWM and onboard LED | LED and Timer0A |
| D18–D19 | Serial1 and interrupts | UART/interrupt overlap |
| D20–D21 | I2C and interrupts | I2C/interrupt overlap |
| D44–D46 | PWM / Timer5 | Timer5 sharing |
| D50–D53 | SPI | SPI 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 Pin | Arduino Mega 2560 |
|---|---|
| SDA | D20 |
| SCL | D21 |
| GND | GND |
| VCC | According to module specifications |
| Push Button Terminal | Arduino Mega 2560 |
|---|---|
| First terminal | D22 |
| Second terminal | GND |
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.

| Resource | Purpose |
|---|---|
| Arduino Mega 2560 Rev3 Documentation | Official board information |
| Official Arduino Mega 2560 Pinout PDF | Complete board-level pin diagram |
| Arduino Mega 2560 Datasheet | Technical and electrical documentation |
| Arduino Mega 2560 Rev3 Store Specifications | Official board specifications |
| Arduino Mega 2560 Schematic | Circuit connections and board design |
| Arduino External Interrupt Reference | Interrupt configuration |
| Arduino Mega Pin Mapping Source | Digital 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).


























