Contact Sales & After-Sales Service

Contact & Quotation

  • 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.
Drag & Drop Files, Choose Files to Upload You can upload up to 3 files.

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 CategoryQuantityPin Numbers/Labels
Digital I/O54D0-D53
PWM Output15D2-D13, D44-D46
Analog Input16A0-A15
Serial (UART)4 portsRX0/TX0, RX1/TX1, RX2/TX2, RX3/TX3
I2C (TWI)1 portSDA (D20), SCL (D21)
SPI1 portMISO (D50), MOSI (D51), SCK (D52), SS (D53)
External Interrupts6INT0-INT5
Power7VIN, 5V, 3.3V, GND (multiple)
Special3RESET, 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:

PinPrimary FunctionAlternate FunctionNotes
D0Digital I/OSerial0 RXShared with USB communication
D1Digital I/OSerial0 TXShared with USB communication
D2Digital I/OPWM, INT0External interrupt capable
D3Digital I/OPWM, INT1External interrupt capable
D13Digital I/OPWM, Built-in LEDOnboard LED responds to this pin
D14Digital I/OSerial3 TXHardware UART
D15Digital I/OSerial3 RXHardware UART
D16Digital I/OSerial2 TXHardware UART
D17Digital I/OSerial2 RXHardware UART
D18Digital I/OSerial1 TX, INT5UART + interrupt
D19Digital I/OSerial1 RX, INT4UART + interrupt
D20Digital I/OSDA, INT3I2C data + interrupt
D21Digital I/OSCL, INT2I2C clock + interrupt
D44Digital I/OPWMTimer5 controlled
D45Digital I/OPWMTimer5 controlled
D46Digital I/OPWMTimer5 controlled
D50Digital I/OSPI MISOMaster In Slave Out
D51Digital I/OSPI MOSIMaster Out Slave In
D52Digital I/OSPI SCKSerial Clock
D53Digital I/OSPI SSSlave 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 PinTimerDefault FrequencyCommon Applications
D2Timer3~490 HzLED dimming, motor control
D3Timer3~490 HzLED dimming, motor control
D4Timer0~976 HzTone generation
D5Timer3~490 HzServo control
D6Timer4~490 HzLED dimming
D7Timer4~490 HzMotor speed control
D8Timer4~490 HzMotor speed control
D9Timer2~490 HzLED dimming
D10Timer2~490 HzLED dimming
D11Timer1~490 HzServo control
D12Timer1~490 HzServo control
D13Timer0~976 HzBuilt-in LED
D44Timer5~490 HzHigh-current applications
D45Timer5~490 HzHigh-current applications
D46Timer5~490 HzHigh-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

ParameterValue
Number of Channels16 (A0-A15)
Resolution10-bit (0-1023)
Default Reference5V
Voltage per Step~4.9mV
Input Impedance100 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 TypeFunction CallReference Voltage
DEFAULTanalogReference(DEFAULT)5V
INTERNAL1V1analogReference(INTERNAL1V1)1.1V
INTERNAL2V56analogReference(INTERNAL2V56)2.56V
EXTERNALanalogReference(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 PortTX PinRX PinPrimary Use
Serial0D1D0USB/Computer communication
Serial1D18D19GPS, Bluetooth modules
Serial2D16D17Additional peripherals
Serial3D14D15Additional 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

PinFunctionDescription
D50MISOMaster In Slave Out (data from peripheral)
D51MOSIMaster Out Slave In (data to peripheral)
D52SCKSerial Clock (synchronization signal)
D53SSSlave 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:

PinFunctionLocation
D20SDA (Serial Data)Also duplicated near AREF
D21SCL (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

InterruptPinSupported Triggers
INT0D2LOW, CHANGE, RISING, FALLING
INT1D3LOW, CHANGE, RISING, FALLING
INT2D21LOW, CHANGE, RISING, FALLING
INT3D20LOW, CHANGE, RISING, FALLING
INT4D19LOW, CHANGE, RISING, FALLING
INT5D18LOW, CHANGE, RISING, FALLING

Use the attachInterrupt() function to configure interrupt behavior:

void setup() {

  pinMode(2, INPUT_PULLUP);

  attachInterrupt(digitalPinToInterrupt(2), buttonPressed, FALLING);

}

void buttonPressed() {

  // Interrupt service routine – keep it short

}

Power Pins on Arduino Mega 2560

Proper power distribution prevents erratic behavior and component damage. The Mega provides multiple power pins:

Power Pin Reference

PinFunctionMaximum Current
VINInput voltage (7-12V recommended)Via barrel jack/pin
5VRegulated 5V output800mA from external supply
3.3VRegulated 3.3V output50mA
GNDGround referenceMultiple pins available
IOREFLogic 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, INT3Same physical pins
Serial1 (D18, D19)INT4, INT5Same physical pins
SPID50-D53 for general I/OBus conflicts
Serial0 (D0, D1)These pins for other devicesUSB communication interference
D13 for sensorsExpect LED to flickerBuilt-in LED responds

Useful Arduino Mega 2560 Pinout Resources

ResourceDescriptionLink
Official Pinout DiagramHigh-resolution PDFdocs.arduino.cc
ATmega2560 DatasheetComplete MCU specificationsMicrochip website
Arduino IDE ReferenceFunction documentationarduino.cc/reference
Pin Mapping TableMCU to Arduino pin conversionArduino 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.

Leave a Reply

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

Contact Sales & After-Sales Service

Contact & Quotation

  • 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.

Drag & Drop Files, Choose Files to Upload You can upload up to 3 files.

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.