The Arduino Mega is like the big brother of the Uno, offering more pins, more memory, and more room for complex projects. With 54 digital I/O pins, 16 analog inputs, and multiple serial ports, it’s great for projects that need to connect to many sensors, displays, or other modules at once.
To harness the full power of the Mega, you’ll need to understand its pinout. In this guide, we’ll go through the different types of pins on the Arduino Mega and explain what each one does.
So grab your Mega, and get ready to dive into this pin-tastic adventure!
Arduino Mega Pinout
The Arduino Mega has 86 pins in total. The pinout is as follows:

Let’s take a closer look at the Arduino pins and their functions one by one.
Arduino Mega Digital I/O Pins
These are pins on the Arduino Mega that can be configured as either inputs or outputs. When set as inputs, they can read digital signals (HIGH or LOW), and when set as outputs, they can send digital signals to control external components like LEDs, motors, and relays.
The Arduino Mega has 54 digital I/O pins, labeled D0 to D53:

Please note that these pins operate at a 5V logic level, and each pin can source or sink a maximum of 20 mA of current.
To set a digital pin as an input, you use the pinMode(pin, INPUT) function, and then digitalRead(pin) function to read the input pin’s state. For setting a pin as an output, you use the pinMode(pin, OUTPUT) function, and then digitalWrite(pin, HIGH/LOW) to set it to the desired state.
Onboard LED
The Arduino Mega has an onboard LED connected to pin D13. It illuminates when the pin is set to HIGH and turns off when set to LOW. This makes it a handy indicator for debugging or signaling the status of a project.
If you use D13 for other purposes besides controlling the LED, remember that the onboard LED will also respond to changes in the pin’s state. This could be confusing if you’re unaware of the connection.
Internal Pull-up Resistors
Each digital pin has an internal pull-up resistor that can be enabled in INPUT mode using pinMode(pinNumber, INPUT_PULLUP). This resistor weakly pulls the pin to HIGH when nothing is connected to it, preventing it from floating between HIGH and LOW states due to electrical noise.
The value of the pull-up resistor is guaranteed to be between 20-50 kΩ.
Arduino Mega Interrupt Pins
Interrupt pins are special digital input pins that can trigger a specific block of code (known as an interrupt service routine or ISR) when an external event occurs, such as a change in voltage level (HIGH to LOW or vice versa). This allows the Arduino to respond immediately to events without constantly checking the pin’s state in the main loop of your code.
The Arduino Mega has a total of 6 external interrupt pins:
- Pin 2 (Interrupt 0)
- Pin 3 (Interrupt 1)
- Pin 21 (Interrupt 2)
- Pin 20 (Interrupt 3)
- Pin 19 (Interrupt 4)
- Pin 18 (Interrupt 5)

The attachInterrupt(interrupt, ISR, mode) function is used to configure the pins as external interrupts, where interrupt is the interrupt number (e.g. 0 for pin 2, 1 for pin 3), ISR is the interrupt service routine (a function to be called when the interrupt occurs) and mode defines the trigger condition (LOW, RISING, FALLING, or CHANGE).
Please note that pins 20 & 21 are not available to use for interrupts while they are used for I2C communication; they also have external pull-ups that cannot be disabled.
Arduino Mega PWM Pins
PWM pins on the Arduino Mega are digital pins that can simulate analog output. They achieve this by rapidly switching the pin between HIGH and LOW states, creating a square wave signal. The ratio of the “ON” time to the total period of the signal is called the duty cycle. By varying the duty cycle, you can control the average voltage delivered to a connected component, allowing you to dim LEDs, control motor speeds, and even generate simple audio tones.
The Arduino Mega provides 15 PWM-capable digital pins: D2 to D13, and D44 to D46.

By default, the PWM output is an 8-bit signal, meaning it can take any value from 0 to 255. This translates to 256 discrete levels of duty cycle.
The Arduino’s programming language makes PWM easy to use. First, the pinMode(pin, OUTPUT) function is used to set the desired PWM pin as an output. The analogWrite(pin, value) function is then used to set the PWM value on a pin. Here, pin is the PWM-capable pin number, and value is an integer between 0 and 255. For example,
analogWrite(pin, 0): Sets the duty cycle to 0% (always off).analogWrite(pin, 127): Sets the duty cycle to approximately 50%.analogWrite(pin, 255): Sets the duty cycle to 100% (always on).
Arduino Mega ADC Pins
Analog input pins on the Arduino Mega are designed to read continuous analog signals. These signals often come from sensors that measure physical quantities like temperature, light intensity, or pressure. The Arduino Mega converts these analog signals into digital values using an Analog-to-Digital Converter (ADC), allowing you to process and analyze the data within your Arduino code.
The Arduino Mega has 16 analog input pins, labeled A0 to A15.

The ADC on the Arduino Mega has a resolution of 10 bits. This means it can detect 1024 (2^10) discrete analog levels. In other words, it will convert input voltages ranging from 0 to 5V (operating voltage) into integer values ranging from 0 to 1023. This translates to a resolution of 5 volts / 1024 units, or approximately 0.0049 volts (4.9 mV) per step.
This level of precision is generally sufficient for most of our projects, but for more precise measurements, an external ADC with a higher resolution should be used.
To read an analog value from a pin, you use the analogRead(pin) function. This function returns an integer value between 0 and 1023, representing the measured voltage on the pin. For example, if the pin is measuring a voltage of 2.5V (half of the maximum 5V), the analogRead() function will return approximately 512.
Keep in mind that the analog pins on the Mega can also be used as digital I/O pins. If you need more digital pins and aren’t using all the analog ones, you can configure them as digital outputs using pinMode().
Changing Reference Voltage
By default, the ADC measures voltages from 0V to 5V, but this range can be adjusted using the AREF pin and the analogReference(type) function. Possible values for the type are:
DEFAULT: Uses the default analog reference of 5V.INTERNAL: Uses an internal reference voltage of 1.1V.EXTERNAL: Uses an external reference voltage applied to the AREF pin.
Arduino Mega ICSP Header Pins
The Arduino Mega features two ICSP headers. One is located next to the main microcontroller chip, and the other is situated near the USB connector.

The ICSP header has two primary use cases:
- Programming the Arduino Mega: You can use an external programmer (like an AVR ISP programmer or another Arduino board acting as an ISP) to upload code to the Arduino Mega directly through the ICSP header. This is particularly useful if the bootloader is corrupted or if you want to burn a bootloader onto a new microcontroller.
- Communicating with SPI Devices: The header provides access to the SPI (Serial Peripheral Interface) pins: MISO (Master In Slave Out), MOSI (Master Out Slave In), and SCK (Serial Clock). These pins can be used to connect and communicate with SPI devices, such as SD card modules or external sensors. It’s important to note that the Slave Select (SS) pin, necessary for controlling multiple SPI devices, is not included on the header and must be controlled manually.
Arduino Mega I2C Pins
The Arduino Mega has two pins dedicated to I2C communication:
- D20 (SDA)
- D21 (SCL)
There is also a duplicate set of I2C pins located near the AREF pin.

The default I2C bus speed on the Arduino Mega is 100kHz. You can increase it to 400kHz (or even higher in some cases) using Wire.setClock(), but be mindful of limitations of the connected devices.
Please note that the Arduino Mega already has built-in 10k pull-up resistors on the SDA and SCL pins.
Arduino Mega SPI Pins
The Arduino Mega has a dedicated set of pins for SPI communication:

Pin 51, labeled MOSI (Master Out Slave In), is used by the master device (Arduino) to send data to the slave device. Conversely, pin 50, labeled MISO (Master In Slave Out), is used by the slave device to send data back to the Arduino. Pin 52, marked SCK (Serial Clock), carries the clock signal that synchronizes the data transfer between the master and slave. Lastly, pin 53, typically assigned as SS (Slave Select), is used to select the specific slave device you want to communicate with if you have multiple SPI devices connected.
In addition to the standard SPI pins, the Arduino Mega also has an ICSP header that provides access to the same SPI signals. You can use either the standard pins or the ICSP header for SPI communication.
Arduino Mega UART Pins
The Arduino Mega 2560 actually has four sets of UART pins: UART0, UART1, UART2, and UART3.
UART0 uses pin 1 (TX0) and pin 0 (RX0), UART1 uses pin 18 (TX1) and pin 19 (RX1), UART2 uses pin 16 (TX2) and pin 17 (RX2), and finally, UART3 communicates through pin 14 (TX3) and pin 15 (RX3).

UART0 is primarily used for uploading sketches and serial communication with the computer via the USB connection, which means it is shared with the USB-to-serial converter on the board. The remaining hardware UARTs (UART1, UART2, and UART3) allow the Arduino Mega to communicate with multiple serial devices simultaneously. Each UART operates independently, enabling concurrent data transmission and reception.
If you need more UART channels, the Arduino Mega supports a library called SoftwareSerial, which allows you to create additional software-based UART connections on other digital pins. However, SoftwareSerial has limitations in terms of speed and reliability compared to hardware UART.
Arduino Mega Power Pins
The Arduino Mega has several power pins. These pins are essential for powering the board itself and for supplying power to connected components and sensors.

VIN: This pin allows you to supply power to the Arduino board using an external power source like a wall adapter or a battery pack. This is useful for standalone projects where the board is not connected to a computer via USB. The input voltage range for VIN is typically 7-12 volts. The input voltage supplied to this pin is regulated down to a stable 5V by the onboard voltage regulator, which then powers the microcontroller and other components on the board. The Vin pin is internally connected to the positive terminal of the DC power jack. This means that when you supply voltage through the DC power jack, it is accessible through the Vin pin.
5V: This pin provides a regulated 5V output from the onboard voltage regulator. You can use this pin to power various components and sensors that require a stable 5V supply. The 5V pin can provide a maximum of 500mA of current if you’re powering your Arduino Mega through a USB cable. The onboard voltage regulator is technically rated for 800mA, but due to power dissipation issues, you shouldn’t go over 400 to 500mA. Should your project demand more power than the 5V pin can safely supply, you’ll need to consider an external power source.
3.3V: This pin provides a regulated 3.3V output, which is useful for components that operate at lower voltages. Be cautious not to draw excessive current from this pin, as it has a limited current capacity of approximately 50mA. It’s worth noting that the 3.3V regulator is connected to the output of the 5V regulator. Drawing current from the 3.3V regulator will dissipate heat in both the 3.3V regulator and the 5V regulator. This means that if you connect a 3.3V device to the 3.3V pin, then it also limits the maximum current you can use for the 5V modules connected to the 5V pin.
GND: This pin represents the common ground reference for all electrical connections on the Arduino. It’s essential to connect the ground pins of your external components to this pin to complete the electrical circuit.
Arduino Mega Special Function Pins

D13: This pin has an onboard LED connected to it. It illuminates when the pin is set to HIGH and turns off when set to LOW. This makes it a handy indicator for debugging or signaling the status of a project. If you use D13 for other purposes besides controlling the LED, remember that the onboard LED will also respond to changes in the pin’s state. This could be confusing if you’re unaware of the connection.
IOREF: stands for Input/Output Reference Voltage. This pin provides a voltage reference that indicates the operating voltage of the Arduino board. In the case of the Arduino Mega, the IOREF pin outputs a voltage of 5V. This pin is primarily designed for use with expansion boards called shields. When a shield is properly designed, it can read the voltage on the IOREF pin to determine the Arduino’s operating voltage. This information allows the shield to adjust its own voltage levels or enable voltage translators as needed, ensuring compatibility and avoiding potential damage due to voltage mismatches. Please keep in mind that the IOREF pin is not intended to be used as a power source for external components. Doing so could potentially damage the Arduino board.
RESET: pin is used to reset the microcontroller on the Arduino Mega, essentially restarting the program running on it. The RESET pin is active LOW, meaning that when it is pulled LOW (connected to ground), the microcontroller resets. Typically, there’s an internal pull-up resistor that keeps the RESET pin HIGH by default. You can reset the Arduino programmatically by connecting the RESET pin to a digital output pin and toggling it LOW using digitalWrite(RESET_PIN, LOW) and then back HIGH. Or you can connect an external switch or device to this pin. When the switch is closed or the device sends a LOW signal, the Arduino will reset.
