Zbotic Logo Zbotic Logo
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

  • Shop
  • About Us
  • Contact Us
  • Reseller
  • Blogs
020 69134444
1800 209 0998
[email protected]
Help Desk
Facebook Twitter Instagram Linkedin YouTube
Zbotic Logo Zbotic Logo
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

All departments
  • 3D Print Service
  • 3D Printer
  • Batteries & Chargers
  • Development Boards
  • Drone Parts
  • EBike parts
  • Sensor Modules
  • Electronic Components
  • Electronic Modules
  • IoT and Wireless
  • Mechanical Parts and Workbench Tools
  • Motors & Drivers & Pumps & Actuators
  • DIY and Robot Kits
  • Show more
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
Return to previous page
Home Arduino & Microcontrollers

Arduino Mega 2560 Pinout: Complete GPIO and Port Reference

Arduino Mega 2560 Pinout: Complete GPIO and Port Reference

March 11, 2026 /Posted byJayesh Jain / 0

The Arduino Mega 2560 is the workhorse of the Arduino family. With 54 digital I/O pins, 16 analog inputs, 4 hardware UART ports, and 15 PWM outputs, it is the board of choice for projects that have outgrown the Uno’s modest 20 pins. But that pin abundance comes with complexity — understanding which pins do what, how they map to the ATmega2560’s internal ports, and where the special functions live is essential before you start connecting hardware.

This complete reference guide covers every pin on the Arduino Mega 2560. Whether you are designing a robot controller, a CNC shield host, a multi-sensor datalogger, or a 3D printer control board, this is the reference you will come back to repeatedly.

Table of Contents

  1. Mega 2560 Overview and Key Specs
  2. Power Pins and Supply Options
  3. Digital I/O Pins 0–53
  4. PWM Output Pins
  5. Analog Input Pins A0–A15
  6. UART / Serial Pins (4 Hardware Ports)
  7. SPI Pins
  8. I2C / TWI Pins
  9. External Interrupt Pins
  10. ATmega2560 Port Mapping
  11. Common Shields and Their Pin Usage
  12. Frequently Asked Questions

Mega 2560 Overview and Key Specs

The Arduino Mega 2560 R3 is based on the Microchip (Atmel) ATmega2560 microcontroller. Here are the key specifications:

  • Microcontroller: ATmega2560
  • Clock speed: 16 MHz (external crystal)
  • Operating voltage: 5V
  • Input voltage (recommended): 7–12V via barrel jack
  • Input voltage (absolute limits): 6–20V
  • Digital I/O pins: 54 (of which 15 provide PWM output)
  • Analog input pins: 16
  • DC current per I/O pin: 40 mA maximum
  • DC current on 3.3V pin: 50 mA maximum
  • Flash memory: 256 KB (8 KB used by bootloader)
  • SRAM: 8 KB
  • EEPROM: 4 KB
  • USB-Serial chip: ATmega16U2
  • Form factor: 101.52 mm × 53.3 mm
Recommended: Arduino Mega 2560 R3 Board — the genuine Arduino Mega 2560 with ATmega2560 and ATmega16U2 for reliable USB communication, officially designed and tested to all specifications described in this reference guide.

Power Pins and Supply Options

The Mega 2560 has dedicated power pins grouped along one edge of the board:

  • VIN: Input voltage from external power source. Use this pin if you are supplying power with a regulated supply (7–12V). The on-board regulator feeds from here.
  • 5V: Regulated 5V output from the on-board regulator. Can also be used as input when powering from USB (bypasses the regulator). Maximum output current: ~800 mA (limited by the regulator).
  • 3.3V: Regulated 3.3V output generated by the ATmega16U2’s internal 3.3V regulator. Maximum 50 mA — insufficient for powering LoRa modules or displays under load. Use an external AMS1117-3.3 for higher current 3.3V loads.
  • GND: Three GND pins available on the board (power header, digital header, and ICSP header).
  • IOREF: Reference voltage for shields (5V on Mega). Allows shields to determine the operating voltage of the board.
  • RESET: Pull LOW to reset the board.

Power supply recommendation: For projects with multiple servos, relays, or display modules, power the Mega via the barrel jack with a 9V/1A or 12V/2A adapter. USB power from a PC is limited to 500 mA total (board + peripherals), which is often insufficient for motor projects.

Digital I/O Pins 0–53

All 54 digital pins can be used as INPUT, INPUT_PULLUP, or OUTPUT. Each can source or sink up to 40 mA, though the total current for all pins combined should not exceed 200 mA.

Pins 0–13 (Lower Digital Header)

These are the pins most compatible with Arduino Uno shields. Pins 0 and 1 are shared with Serial0/USB communication — avoid using them as GPIO when you need Serial debugging.

Pin Special Functions ATmega Port
0 (RX0) Serial RX (UART0), INT0 PE0
1 (TX0) Serial TX (UART0), INT1 PE1
2 PWM, INT4 PE4
3 PWM, INT5 PE5
4 PWM (Timer0B) PG5
5 PWM (Timer3A) PE3
6 PWM (Timer4A) PH3
7 PWM (Timer4B) PH4
8 PWM (Timer4C) PH5
9 PWM (Timer2B) PH6
10 PWM (Timer2A) PB4
11 PWM (Timer1A), MOSI PB5
12 PWM (Timer1B), MISO PB6
13 PWM (Timer0A), SCK, LED_BUILTIN PB7

Pins 14–21 (Serial and I2C Pins)

Pin Special Functions ATmega Port
14 (TX3) Serial3 TX PJ1
15 (RX3) Serial3 RX PJ0
16 (TX2) Serial2 TX PH1
17 (RX2) Serial2 RX PH0
18 (TX1) Serial1 TX, INT3 PD3
19 (RX1) Serial1 RX, INT2 PD2
20 (SDA) I2C SDA, INT1 PD1
21 (SCL) I2C SCL, INT0 PD0

Pins 22–53 (Extended GPIO)

These pins are unique to the Mega and have no equivalent on the Uno or Nano. They are general-purpose digital I/O with no special functions except for:

  • Pins 22–29: Port A (PA0–PA7) — 8-bit port, excellent for parallel communication or LCD data bus
  • Pins 30–37: Port C (PC7–PC0) — 8-bit port
  • Pins 38–41, 42–49, 50–53: Ports D, L, B extensions
  • Pins 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS): Secondary SPI pins (same signals as the ICSP header)
Recommended: 3D Printer Controller Board RAMPS 1.4 for Arduino Mega Shield — one of the most popular Mega shields, using nearly all 54 digital pins, all 16 analog pins, and multiple UART ports for 3D printer motion control, heating, and end-stop management. An excellent demonstration of the Mega’s full GPIO utilisation.

PWM Output Pins

The Mega 2560 has 15 PWM-capable pins (compared to 6 on the Uno). PWM on all pins operates at 490 Hz by default, except pins 4 and 13 which run at 980 Hz. Use analogWrite(pin, value) where value is 0–255.

PWM pins: 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 44, 45, 46

The 15 PWM outputs are allocated to hardware timers:

  • Timer0: Pins 4, 13 (also used by millis(), delay() — modifying affects timekeeping)
  • Timer1: Pins 11, 12
  • Timer2: Pins 9, 10
  • Timer3: Pins 2, 3, 5
  • Timer4: Pins 6, 7, 8
  • Timer5: Pins 44, 45, 46

Timer0 and Timer2 run at 8-bit resolution (0–255). Timers 1, 3, 4, and 5 are 16-bit timers capable of higher resolution PWM when configured directly via registers. Libraries like Servo and tone() use specific timers — check for conflicts when using multiple timer-dependent libraries simultaneously.

Analog Input Pins A0–A15

The Mega has 16 analog input pins (vs 6 on Uno), all with 10-bit ADC resolution (0–1023 reading, representing 0–5V). Use analogRead(A0) through analogRead(A15).

Arduino Pin ATmega ADC Channel ATmega Port
A0 ADC0 PF0
A1 ADC1 PF1
A2 ADC2 PF2
A3 ADC3 PF3
A4 ADC4 PF4
A5 ADC5 PF5
A6 ADC6 PF6
A7 ADC7 PF7
A8 ADC8 PK0
A9 ADC9 PK1
A10 ADC10 PK2
A11 ADC11 PK3
A12 ADC12 PK4
A13 ADC13 PK5
A14 ADC14 PK6
A15 ADC15 PK7

Analog pins A0–A15 can also be used as digital I/O with pinMode() and digitalWrite(), addressed as digital pins 54–69. However, A0–A7 (PF port) cannot be used as pin-change interrupt sources.

UART / Serial Pins (4 Hardware Ports)

The ATmega2560 has four independent hardware UART ports — a massive advantage over the Uno’s single UART. This allows you to simultaneously communicate with a GPS module, a GSM modem, an RS485 device, and a PC debug terminal without any software serial overhead.

Serial Port TX Pin RX Pin Arduino Object
UART0 1 0 Serial
UART1 18 19 Serial1
UART2 16 17 Serial2
UART3 14 15 Serial3

Use Serial for USB debugging (via USB cable), Serial1 for a connected peripheral like GPS, Serial2 for another peripheral, and Serial3 for a third. All four operate independently at their own baud rates and use separate hardware buffers.

Example — GPS + GSM + Debug simultaneously:

void setup() {
  Serial.begin(115200);  // USB debug output
  Serial1.begin(9600);   // GPS module on pins 18/19
  Serial2.begin(115200); // GSM module on pins 16/17
}
void loop() {
  if (Serial1.available()) {
    String gps = Serial1.readStringUntil('n');
    Serial.println("GPS: " + gps);
  }
  if (Serial2.available()) {
    String gsm = Serial2.readStringUntil('n');
    Serial.println("GSM: " + gsm);
  }
}

SPI Pins

The Mega 2560 has two sets of SPI pins — the digital header and the ICSP header:

  • ICSP Header (6-pin, top of board): MOSI (pin 1), MISO (pin 3), SCK (pin 4), RESET (pin 5), VCC (pin 2), GND (pin 6)
  • Digital pins: Pin 50 (MISO), Pin 51 (MOSI), Pin 52 (SCK), Pin 53 (SS)

Both sets connect to the same SPI bus. Most Arduino shields designed for Uno use the ICSP header for SPI, which is why shields connect properly on the Mega even though the digital pin numbers differ from Uno.

SPI chip select (CS/SS) pins are flexible — you can use any digital pin as CS for multiple SPI devices. The hardware SS (pin 53) must remain OUTPUT even if you use software-managed CS pins, otherwise the SPI master mode may be deactivated.

I2C / TWI Pins

The Mega 2560’s I2C bus is on:

  • Pin 20 (SDA) — Data line
  • Pin 21 (SCL) — Clock line

These are different from the Uno (A4/A5 for SDA/SCL). This means Uno shields that use I2C and access it via the analog pin header (not the dedicated SDA/SCL pins) may not work correctly on the Mega without modification. Shields using the dedicated SDA/SCL pins of the R3 connector standard will work correctly on both.

The I2C bus can support up to 127 devices simultaneously, each with a unique 7-bit address. Use a 4.7 kΩ pull-up resistor on each line for reliable operation with multiple devices.

External Interrupt Pins

The Mega 2560 supports 8 external hardware interrupts (INT0–INT7), far more than the Uno’s 2:

Interrupt Arduino Pin ATmega Port
INT0 21 (SCL) PD0
INT1 20 (SDA) PD1
INT2 19 (RX1) PD2
INT3 18 (TX1) PD3
INT4 2 PE4
INT5 3 PE5
INT6 (internal, not broken out) PE6
INT7 (internal, not broken out) PE7

Use attachInterrupt(digitalPinToInterrupt(pin), ISR, mode) for pins 2, 3, 18, 19, 20, 21. The modes are RISING, FALLING, CHANGE, and LOW. Note that pins 20 and 21 are shared with I2C — you cannot use them simultaneously as I2C and external interrupt inputs.

The Mega also supports pin-change interrupts (PCINT) on many other pins via the PCMSK registers, allowing software to detect any state change on selected pins using interrupts rather than polling.

ATmega2560 Port Mapping

For direct port manipulation (faster than digitalWrite, bypasses Arduino overhead), here is the full port map:

  • Port A (PA0–PA7): Arduino pins 22–29
  • Port B (PB0–PB7): Arduino pins 53, 52, 51, 50, 10, 11, 12, 13
  • Port C (PC0–PC7): Arduino pins 37, 36, 35, 34, 33, 32, 31, 30
  • Port D (PD0–PD3): Arduino pins 21, 20, 19, 18
  • Port E (PE0–PE5): Arduino pins 0, 1, –, 5, 2, 3
  • Port F (PF0–PF7): Arduino pins A0–A7
  • Port G (PG0–PG2, PG5): Arduino pins 41, 40, 39, 4
  • Port H (PH0–PH6): Arduino pins 17, 16, –, 6, 7, 8, 9
  • Port J (PJ0–PJ1): Arduino pins 15, 14
  • Port K (PK0–PK7): Arduino pins A8–A15
  • Port L (PL0–PL7): Arduino pins 49, 48, 47, 46, 45, 44, 43, 42

Example of direct port manipulation to set all Port A pins HIGH simultaneously:

DDRA = 0xFF;   // Set all Port A pins as output
PORTA = 0xFF;  // Set all Port A pins HIGH
PORTA = 0x00;  // Set all Port A pins LOW

Common Shields and Their Pin Usage

The Mega 2560’s extended headers make it the preferred board for large shields. Here is what popular shields use:

  • RAMPS 1.4 (3D Printer): All stepper pins on digital 24–54 range; endstops on digital 2, 3, 14, 15, 18, 19; thermistors on A0, A1, A2; heater control on 8, 9, 10; fan on 9.
  • Ethernet Shield W5100: SPI on pins 50–53 + pin 10 (CS).
  • SD Card Shield: SPI on 50–52, CS on pin 4 or 10 (varies).
  • TFT LCD Shield (3.2″): Data bus on pins 22–37 (Ports A and C), control on 38–42.
  • Sensor Shield v2: Breaks out all pins with VCC/GND alongside for easy sensor connection.
Recommended: 2.4″ Inch Touch Screen TFT Display Shield for Arduino UNO MEGA — a plug-in TFT touchscreen shield compatible with the Mega 2560, using the parallel data bus on the digital pins for fast display updates. Ideal for building graphical user interfaces on Mega-based projects.
Recommended: Arduino Starter Kit with 170 Pages Project Book — an excellent way to learn Arduino fundamentals through hands-on projects before working with the full Mega 2560 pinout. The project book guides you from basic GPIO through sensors, displays, and communication modules step by step.

Frequently Asked Questions

What is the difference between the Arduino Mega 2560 R2 and R3?

The R3 revision added the dedicated SDA and SCL pins near the RESET pin (also found on Uno R3), making I2C shields cross-compatible. R3 also uses the ATmega16U2 for USB-Serial (vs ATmega8U2 on R2), which is faster and more reliable. The R3 also added the IOREF pin. If your shield uses only the standard digital and analog headers, R2 and R3 are functionally identical.

Can I use all 54 digital pins simultaneously?

Yes, all 54 digital pins can be used as GPIO simultaneously. However, the total current that can flow through all pins combined is limited — the ATmega2560 specifies a maximum of 200 mA total across all output pins. If you need to drive many LEDs or loads directly from the pins, stay below 40 mA per individual pin and 200 mA total, or use transistors/MOSFETs to switch higher loads.

Why do some shields designed for Arduino Uno not work on the Mega?

Two main reasons: (1) I2C pins — Uno I2C is on A4/A5, Mega I2C is on pins 20/21. Shields that use the A4/A5 lines for I2C will not connect to the Mega’s I2C bus unless they use the dedicated R3 SDA/SCL header. (2) SPI — some shields connect SPI through the digital pins (10–13 on Uno) instead of the ICSP header. The Mega’s SPI is on pins 50–53, not 10–13. Check your shield’s schematic for these differences before purchasing.

How do I use the Mega’s analog pins as digital outputs?

Use pinMode(A0, OUTPUT) and digitalWrite(A0, HIGH) — the analog pin labels (A0–A15) work as arguments to all digital functions. You can also use the numeric equivalents: A0 = pin 54, A1 = pin 55, through A15 = pin 69. This is useful in code that calculates pin numbers programmatically.

What is the maximum current the Mega’s 5V pin can supply to connected devices?

When powered via USB (500 mA from PC USB, up to 900 mA from USB 3.0 or a phone charger), the 5V pin can supply approximately 300–400 mA after accounting for the board’s own consumption. When powered via the 9–12V barrel jack, the on-board linear regulator can supply around 800 mA at 5V (limited by thermal dissipation). For projects with servos, motors, or multiple sensors, use a separate 5V power supply connected directly to the 5V and GND pins — bypassing the regulator entirely.

Get More From Your Arduino Mega 2560

The Arduino Mega 2560’s 54 digital pins, 16 analog inputs, 4 UARTs, and abundant timer resources make it the most capable board in the standard Arduino line-up for complex projects. With this pinout reference, you have everything you need to use every pin effectively — from the basic GPIO through port manipulation, interrupts, and multi-protocol communication.

Shop for the Arduino Mega 2560 and compatible shields, sensors, and modules at Zbotic.in — Arduino & Microcontrollers, with fast delivery across India.

Tags: arduino mega 2560, Arduino Mega pinout, Arduino pins, ATmega2560, GPIO reference, Mega 2560
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
Best Raspberry Pi Cases and En...
blog best raspberry pi cases and enclosures cooling and style 595175
blog raspberry pi sd card buying guide best cards for stability 595178
Raspberry Pi SD Card Buying Gu...

Related posts

Svg%3E
Read more

Arduino Batch Programming: Flash Multiple Boards Quickly

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading
Svg%3E
Read more

Arduino Based Radar System with Ultrasonic Sensor

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading
Svg%3E
Read more

Arduino Automatic Plant Monitor: Sunlight, Moisture, Temperature

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading
Svg%3E
Read more

Arduino Lie Detector: GSR Sensor Polygraph Project

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading
Svg%3E
Read more

Arduino Metal Detector: Build a Treasure Finder

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading

Add comment Cancel reply

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

Facebook Twitter Instagram Pinterest Linkedin Youtube

Get the latest deals and more.

Download on Google Play Download on the App Store

Call us: 020 69134444 / 1800 209 0998

Monday - Saturday 09:30 AM - 06:00 PM
For Technical Supports Email: [email protected]
For Sales / Enquiries Email: [email protected]

  • My Account

    • Cart

    • Wishlist

    • Checkout

    • My Orders

    • Track Order

    • My Account

  • Information

    • FAQs

    • Blogs

    • Career

    • About Us

    • Contact Us

    • Payment Options

  • Policies

    • Privacy Policy

    • Terms & Conditions

    • GST Input Tax Credit

    • Shipping Return Policy

    • E-Waste Collection Points

    • Our Sitemap

© Zbotic.in is registered trademark of Moxie Supply Pvt Ltd – All Rights Reserved
Login
Use Phone Number
Use Email Address
Not a member yet? Register Now
Reset Password
Use Phone Number
Use Email Address
Register
Already a member? Login Now