Inquire: Call 0086-755-23203480, or reach out via the form below/your sales contact to discuss our design, manufacturing, and assembly capabilities.
Quote: Email your PCB files to Sales@pcbsync.com (Preferred for large files) or submit online. We will contact you promptly. Please ensure your email is correct.
Notes: For PCB fabrication, we require PCB design file in Gerber RS-274X format (most preferred), *.PCB/DDB (Protel, inform your program version) format or *.BRD (Eagle) format. For PCB assembly, we require PCB design file in above mentioned format, drilling file and BOM. Click to download BOM template To avoid file missing, please include all files into one folder and compress it into .zip or .rar format.
Arduino Mega 2560 Pinout: Complete Pin Reference Guide
Getting the Arduino Mega 2560 pinout right is essential before you wire up anything. I’ve seen countless projects fail during prototyping simply because someone connected a sensor to the wrong pin or didn’t account for shared pin functions. This guide gives you the complete pin mapping so you can plan your connections properly from the start.
The Arduino Mega 2560 packs 86 pins into its 101.5mm × 53.3mm footprint, making it the most pin-rich board in the standard Arduino lineup. Knowing what each pin does—and more importantly, what alternate functions it supports—saves debugging time and prevents hardware conflicts.
Arduino Mega 2560 Pinout Overview
The Mega 2560 based on the ATmega2560 microcontroller organizes its pins into several functional groups. Here’s the high-level breakdown:
Pin Category
Quantity
Pin Numbers/Labels
Digital I/O
54
D0-D53
PWM Output
15
D2-D13, D44-D46
Analog Input
16
A0-A15
Serial (UART)
4 ports
RX0/TX0, RX1/TX1, RX2/TX2, RX3/TX3
I2C (TWI)
1 port
SDA (D20), SCL (D21)
SPI
1 port
MISO (D50), MOSI (D51), SCK (D52), SS (D53)
External Interrupts
6
INT0-INT5
Power
7
VIN, 5V, 3.3V, GND (multiple)
Special
3
RESET, AREF, IOREF
Each digital pin operates at 5V logic levels and can source or sink up to 20mA safely (40mA absolute maximum). The internal pull-up resistors range from 20-50kΩ when enabled.
Digital I/O Pins (D0-D53)
The 54 digital pins form the backbone of most Mega projects. Each can function as either input or output, configured through pinMode(), digitalWrite(), and digitalRead() functions.
Digital Pin Functions and Alternate Uses
Not all digital pins are created equal. Many serve dual purposes that affect how you design your circuits:
Pin
Primary Function
Alternate Function
Notes
D0
Digital I/O
Serial0 RX
Shared with USB communication
D1
Digital I/O
Serial0 TX
Shared with USB communication
D2
Digital I/O
PWM, INT0
External interrupt capable
D3
Digital I/O
PWM, INT1
External interrupt capable
D13
Digital I/O
PWM, Built-in LED
Onboard LED responds to this pin
D14
Digital I/O
Serial3 TX
Hardware UART
D15
Digital I/O
Serial3 RX
Hardware UART
D16
Digital I/O
Serial2 TX
Hardware UART
D17
Digital I/O
Serial2 RX
Hardware UART
D18
Digital I/O
Serial1 TX, INT5
UART + interrupt
D19
Digital I/O
Serial1 RX, INT4
UART + interrupt
D20
Digital I/O
SDA, INT3
I2C data + interrupt
D21
Digital I/O
SCL, INT2
I2C clock + interrupt
D44
Digital I/O
PWM
Timer5 controlled
D45
Digital I/O
PWM
Timer5 controlled
D46
Digital I/O
PWM
Timer5 controlled
D50
Digital I/O
SPI MISO
Master In Slave Out
D51
Digital I/O
SPI MOSI
Master Out Slave In
D52
Digital I/O
SPI SCK
Serial Clock
D53
Digital I/O
SPI SS
Slave Select
A critical point: pins D0 and D1 connect to the USB-to-serial converter. Using these for other purposes while uploading code or monitoring serial output will cause conflicts. Keep them free during development if possible.
PWM Pins on Arduino Mega 2560
The Mega provides 15 PWM-capable pins for analog-like output control. These pins generate 8-bit PWM signals (0-255 duty cycle values) using the analogWrite() function.
Complete PWM Pin Reference
PWM Pin
Timer
Default Frequency
Common Applications
D2
Timer3
~490 Hz
LED dimming, motor control
D3
Timer3
~490 Hz
LED dimming, motor control
D4
Timer0
~976 Hz
Tone generation
D5
Timer3
~490 Hz
Servo control
D6
Timer4
~490 Hz
LED dimming
D7
Timer4
~490 Hz
Motor speed control
D8
Timer4
~490 Hz
Motor speed control
D9
Timer2
~490 Hz
LED dimming
D10
Timer2
~490 Hz
LED dimming
D11
Timer1
~490 Hz
Servo control
D12
Timer1
~490 Hz
Servo control
D13
Timer0
~976 Hz
Built-in LED
D44
Timer5
~490 Hz
High-current applications
D45
Timer5
~490 Hz
High-current applications
D46
Timer5
~490 Hz
High-current applications
The default PWM frequency of approximately 490 Hz works for most applications. However, certain motor drivers or LED applications may require frequency adjustment through timer register manipulation.
PWM Code Example
int ledPin = 9; // PWM pin
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
// Fade LED from off to full brightness
for (int brightness = 0; brightness <= 255; brightness++) {
analogWrite(ledPin, brightness);
delay(10);
}
}
Analog Input Pins (A0-A15)
The Mega includes 16 analog input channels, each connected to a 10-bit ADC (Analog-to-Digital Converter). This resolution provides 1024 discrete voltage levels between 0V and the reference voltage (5V by default).
Analog Pin Specifications
Parameter
Value
Number of Channels
16 (A0-A15)
Resolution
10-bit (0-1023)
Default Reference
5V
Voltage per Step
~4.9mV
Input Impedance
100 MΩ
The analog pins can also function as digital I/O when needed. Reference them as digital pins 54-69 in code, or use the A0-A15 notation for clarity.
Analog Reference Options
The AREF pin allows you to change the ADC reference voltage for improved precision with lower voltage signals:
Reference Type
Function Call
Reference Voltage
DEFAULT
analogReference(DEFAULT)
5V
INTERNAL1V1
analogReference(INTERNAL1V1)
1.1V
INTERNAL2V56
analogReference(INTERNAL2V56)
2.56V
EXTERNAL
analogReference(EXTERNAL)
AREF pin voltage
When using EXTERNAL reference, connect your reference voltage to the AREF pin. Never exceed 5V on this pin or apply external voltage while using internal references.
Serial Communication Pins (UART)
One major advantage of the Arduino Mega 2560 pinout over smaller boards is the four hardware serial ports. This allows simultaneous communication with multiple devices without software serial overhead.
UART Pin Assignments
Serial Port
TX Pin
RX Pin
Primary Use
Serial0
D1
D0
USB/Computer communication
Serial1
D18
D19
GPS, Bluetooth modules
Serial2
D16
D17
Additional peripherals
Serial3
D14
D15
Additional peripherals
Serial0 shares the USB connection, so it’s typically reserved for debugging and sketch uploads. The remaining three ports (Serial1, Serial2, Serial3) are available for peripheral devices without interference.
Serial Communication Example
void setup() {
Serial.begin(9600); // USB communication
Serial1.begin(9600); // GPS module on pins 18/19
Serial2.begin(115200); // High-speed sensor
}
void loop() {
if (Serial1.available()) {
char gpsData = Serial1.read();
Serial.print(gpsData); // Forward to USB monitor
}
}
SPI Communication Pins
The SPI interface provides high-speed communication with peripherals like SD cards, displays, and sensors. The Mega dedicates four pins to SPI:
SPI Pin Configuration
Pin
Function
Description
D50
MISO
Master In Slave Out (data from peripheral)
D51
MOSI
Master Out Slave In (data to peripheral)
D52
SCK
Serial Clock (synchronization signal)
D53
SS
Slave Select (device selection)
The ICSP header also provides SPI access and maintains physical compatibility with shields designed for Arduino Uno. When using SPI, keep pin D53 as OUTPUT even if not using it as SS—leaving it as INPUT can cause the Mega to enter SPI slave mode unexpectedly.
I2C Communication Pins (TWI)
I2C (also called TWI or Two-Wire Interface) uses just two pins to communicate with multiple devices on a shared bus:
Pin
Function
Location
D20
SDA (Serial Data)
Also duplicated near AREF
D21
SCL (Serial Clock)
Also duplicated near AREF
The Mega includes built-in 10kΩ pull-up resistors on both I2C lines. For most applications, no external pull-ups are required. The default bus speed is 100kHz, adjustable to 400kHz using Wire.setClock(400000).
Important: Pins D20 and D21 also serve as external interrupt pins (INT3 and INT2). You cannot use I2C and these specific interrupts simultaneously on the same pins.
External Interrupt Pins
External interrupts allow immediate response to hardware events without constant polling. The Mega supports six external interrupt pins:
Interrupt Pin Mapping
Interrupt
Pin
Supported Triggers
INT0
D2
LOW, CHANGE, RISING, FALLING
INT1
D3
LOW, CHANGE, RISING, FALLING
INT2
D21
LOW, CHANGE, RISING, FALLING
INT3
D20
LOW, CHANGE, RISING, FALLING
INT4
D19
LOW, CHANGE, RISING, FALLING
INT5
D18
LOW, CHANGE, RISING, FALLING
Use the attachInterrupt() function to configure interrupt behavior:
Proper power distribution prevents erratic behavior and component damage. The Mega provides multiple power pins:
Power Pin Reference
Pin
Function
Maximum Current
VIN
Input voltage (7-12V recommended)
Via barrel jack/pin
5V
Regulated 5V output
800mA from external supply
3.3V
Regulated 3.3V output
50mA
GND
Ground reference
Multiple pins available
IOREF
Logic level reference (5V)
Do not draw current
Never supply voltage directly to the 5V or 3.3V pins while USB is connected—this bypasses the protection circuitry and risks damaging both the board and your computer.
Special Function Pins
RESET Pin
Pulling the RESET pin LOW for at least four clock cycles resets the microcontroller. Use this for external reset buttons or to reset the board programmatically from other circuits.
AREF Pin
The Analog Reference pin sets the upper voltage limit for ADC conversions. When using external references, apply a stable voltage here and call analogReference(EXTERNAL) in your code.
IOREF Pin
This pin outputs the board’s operating voltage (5V on the Mega). Shields use it to detect whether they’re on a 5V or 3.3V board and adjust their logic levels accordingly.
Pin Conflict Considerations
When designing circuits, watch for these common pin conflicts:
If You Use…
Avoid Using…
Reason
I2C (D20, D21)
INT2, INT3
Same physical pins
Serial1 (D18, D19)
INT4, INT5
Same physical pins
SPI
D50-D53 for general I/O
Bus conflicts
Serial0 (D0, D1)
These pins for other devices
USB communication interference
D13 for sensors
Expect LED to flicker
Built-in LED responds
Useful Arduino Mega 2560 Pinout Resources
Resource
Description
Link
Official Pinout Diagram
High-resolution PDF
docs.arduino.cc
ATmega2560 Datasheet
Complete MCU specifications
Microchip website
Arduino IDE Reference
Function documentation
arduino.cc/reference
Pin Mapping Table
MCU to Arduino pin conversion
Arduino Hacking page
Frequently Asked Questions
What are the PWM pins on Arduino Mega 2560?
The Arduino Mega 2560 has 15 PWM pins: D2 through D13 and D44 through D46. These pins generate 8-bit PWM output using the analogWrite() function, with default frequencies around 490 Hz (or 976 Hz for timer0-controlled pins D4 and D13).
Where are the I2C pins on Arduino Mega 2560?
The I2C (TWI) pins are located at D20 (SDA) and D21 (SCL). There’s also a duplicate set of I2C pins near the AREF pin on the board header. The Mega includes built-in 10kΩ pull-up resistors on these lines.
How many serial ports does Arduino Mega 2560 have?
The Arduino Mega 2560 features four hardware serial ports. Serial0 (pins D0/D1) connects to the USB interface, while Serial1 (D18/D19), Serial2 (D16/D17), and Serial3 (D14/D15) are available for external devices like GPS modules, Bluetooth, and other serial peripherals.
Can Arduino Mega 2560 analog pins be used as digital pins?
Yes, all 16 analog pins (A0-A15) can function as digital I/O. In code, reference them as pins 54-69 or use the A0-A15 notation directly. This gives you up to 70 total digital I/O pins when needed.
What is the maximum current per pin on Arduino Mega 2560?
Each digital I/O pin can safely source or sink 20mA, with an absolute maximum of 40mA. The total current through all I/O pins combined should not exceed 200mA to prevent damage to the ATmega2560 microcontroller.
Summary
The Arduino Mega 2560 pinout provides 54 digital I/O pins, 16 analog inputs, 15 PWM outputs, four hardware serial ports, plus dedicated SPI and I2C interfaces. Understanding the alternate functions and potential conflicts between these pins is essential for successful project design.
When planning your wiring, always check whether your chosen pins have conflicting alternate functions. Keep Serial0 (D0/D1) free during development, use the appropriate communication pins for your peripherals, and respect the current limits on each pin. With proper pin assignment, the Mega 2560 can handle even the most complex projects without running into resource conflicts.
Inquire: Call 0086-755-23203480, or reach out via the form below/your sales contact to discuss our design, manufacturing, and assembly capabilities.
Quote: Email your PCB files to Sales@pcbsync.com (Preferred for large files) or submit online. We will contact you promptly. Please ensure your email is correct.
Notes: For PCB fabrication, we require PCB design file in Gerber RS-274X format (most preferred), *.PCB/DDB (Protel, inform your program version) format or *.BRD (Eagle) format. For PCB assembly, we require PCB design file in above mentioned format, drilling file and BOM. Click to download BOM template To avoid file missing, please include all files into one folder and compress it into .zip or .rar format.