Arduino Mega pinout
The Arduino Mega (ATmega2560) pinout: what each pin does, from GPIO, analog inputs and PWM to UART, I2C and SPI, with the notes that catch people out.
The board
- Microcontroller: ATmega2560, 8-bit AVR
- Clock: 16 MHz
- Flash: 256 KB (8 KB is the bootloader)
- SRAM / EEPROM: 8 KB / 4 KB
- Logic level: 5 V
- Digital pins: 54 (D0–D53), 15 with PWM
- Analog inputs: 16 (A0–A15), 10-bit: 0–1023
- Serial: 4 UARTs: Serial (D0/D1, shared with USB), Serial1 (D19/D18), Serial2 (D17/D16), Serial3 (D15/D14)
- I2C (Wire): SDA D20, SCL D21 (also on the SDA/SCL pins by AREF)
- SPI: MISO D50, MOSI D51, SCK D52, SS D53
- External interrupts: D2, D3, D18, D19, D20, D21
- On-board LED: D13 (LED_BUILTIN)
Pins
| Pin | Functions | Notes |
|---|---|---|
| 0 | D0, PE0, RX0 | Serial receive, wired to the USB serial chip. |
| 1 | D1, PE1, TX0 | Serial transmit, wired to the USB serial chip. |
| 2 | D2, PE4, ~PWM, OC3B, INT4 | analogWrite() PWM from Timer3 (OC3B), about 490 Hz. External interrupt INT4: attachInterrupt(digitalPinToInterrupt(2), handler, mode). |
| 3 | D3, PE5, ~PWM, OC3C, INT5 | analogWrite() PWM from Timer3 (OC3C), about 490 Hz. External interrupt INT5: attachInterrupt(digitalPinToInterrupt(3), handler, mode). |
| 4 | D4, PG5, ~PWM, OC0B | analogWrite() PWM from Timer0 (OC0B), about 980 Hz. |
| 5 | D5, PE3, ~PWM, OC3A | analogWrite() PWM from Timer3 (OC3A), about 490 Hz. |
| 6 | D6, PH3, ~PWM, OC4A | analogWrite() PWM from Timer4 (OC4A), about 490 Hz. |
| 7 | D7, PH4, ~PWM, OC4B | analogWrite() PWM from Timer4 (OC4B), about 490 Hz. |
| 8 | D8, PH5, ~PWM, OC4C | analogWrite() PWM from Timer4 (OC4C), about 490 Hz. |
| 9 | D9, PH6, ~PWM, OC2B | analogWrite() PWM from Timer2 (OC2B), about 490 Hz. |
| 10 | D10, PB4, ~PWM, OC2A | analogWrite() PWM from Timer2 (OC2A), about 490 Hz. |
| 11 | D11, PB5, ~PWM, OC1A | analogWrite() PWM from Timer1 (OC1A), about 490 Hz. |
| 12 | D12, PB6, ~PWM, OC1B | analogWrite() PWM from Timer1 (OC1B), about 490 Hz. |
| 13 | D13, PB7, ~PWM, OC0A, LED | analogWrite() PWM from Timer0 (OC0A), about 980 Hz. Drives the on-board LED (LED_BUILTIN). |
| 14 | D14, PJ1, TX3 | Serial3 transmit. |
| 15 | D15, PJ0, RX3 | Serial3 receive. |
| 16 | D16, PH1, TX2 | Serial2 transmit. |
| 17 | D17, PH0, RX2 | Serial2 receive. |
| 18 | D18, PD3, INT3, TX1 | External interrupt INT3: attachInterrupt(digitalPinToInterrupt(18), handler, mode). Serial1 transmit. |
| 19 | D19, PD2, INT2, RX1 | External interrupt INT2: attachInterrupt(digitalPinToInterrupt(19), handler, mode). Serial1 receive. |
| 20 | D20, PD1, INT1, SDA | External interrupt INT1: attachInterrupt(digitalPinToInterrupt(20), handler, mode). I2C SDA for the Wire library. |
| 21 | D21, PD0, INT0, SCL | External interrupt INT0: attachInterrupt(digitalPinToInterrupt(21), handler, mode). I2C SCL for the Wire library. |
| 22 | D22, PA0 | |
| 23 | D23, PA1 | |
| 24 | D24, PA2 | |
| 25 | D25, PA3 | |
| 26 | D26, PA4 | |
| 27 | D27, PA5 | |
| 28 | D28, PA6 | |
| 29 | D29, PA7 | |
| 30 | D30, PC7 | |
| 31 | D31, PC6 | |
| 32 | D32, PC5 | |
| 33 | D33, PC4 | |
| 34 | D34, PC3 | |
| 35 | D35, PC2 | |
| 36 | D36, PC1 | |
| 37 | D37, PC0 | |
| 38 | D38, PD7 | |
| 39 | D39, PG2 | |
| 40 | D40, PG1 | |
| 41 | D41, PG0 | |
| 42 | D42, PL7 | |
| 43 | D43, PL6 | |
| 44 | D44, PL5, ~PWM, OC5C | analogWrite() PWM from Timer5 (OC5C), about 490 Hz. |
| 45 | D45, PL4, ~PWM, OC5B | analogWrite() PWM from Timer5 (OC5B), about 490 Hz. |
| 46 | D46, PL3, ~PWM, OC5A | analogWrite() PWM from Timer5 (OC5A), about 490 Hz. |
| 47 | D47, PL2 | |
| 48 | D48, PL1 | |
| 49 | D49, PL0 | |
| 50 | D50, PB3, MISO | Hardware SPI MISO for the SPI library. |
| 51 | D51, PB2, MOSI | Hardware SPI MOSI for the SPI library. |
| 52 | D52, PB1, SCK | Hardware SPI SCK for the SPI library. |
| 53 | D53, PB0, SS | SPI SS: keep it an output while the board is the SPI controller, or SPI stops. |
| A0 | A0, PF0, ADC0 | Analog input: analogRead(A0) reads ADC channel 0. Also a digital pin: pinMode(A0, OUTPUT) and digitalWrite(A0, HIGH) work. |
| A1 | A1, PF1, ADC1 | Analog input: analogRead(A1) reads ADC channel 1. Also a digital pin: pinMode(A1, OUTPUT) and digitalWrite(A1, HIGH) work. |
| A2 | A2, PF2, ADC2 | Analog input: analogRead(A2) reads ADC channel 2. Also a digital pin: pinMode(A2, OUTPUT) and digitalWrite(A2, HIGH) work. |
| A3 | A3, PF3, ADC3 | Analog input: analogRead(A3) reads ADC channel 3. Also a digital pin: pinMode(A3, OUTPUT) and digitalWrite(A3, HIGH) work. |
| A4 | A4, PF4, ADC4 | Analog input: analogRead(A4) reads ADC channel 4. Also a digital pin: pinMode(A4, OUTPUT) and digitalWrite(A4, HIGH) work. |
| A5 | A5, PF5, ADC5 | Analog input: analogRead(A5) reads ADC channel 5. Also a digital pin: pinMode(A5, OUTPUT) and digitalWrite(A5, HIGH) work. |
| A6 | A6, PF6, ADC6 | Analog input: analogRead(A6) reads ADC channel 6. Also a digital pin: pinMode(A6, OUTPUT) and digitalWrite(A6, HIGH) work. |
| A7 | A7, PF7, ADC7 | Analog input: analogRead(A7) reads ADC channel 7. Also a digital pin: pinMode(A7, OUTPUT) and digitalWrite(A7, HIGH) work. |
| A8 | A8, PK0, ADC8 | Analog input: analogRead(A8) reads ADC channel 8. Also a digital pin: pinMode(A8, OUTPUT) and digitalWrite(A8, HIGH) work. |
| A9 | A9, PK1, ADC9 | Analog input: analogRead(A9) reads ADC channel 9. Also a digital pin: pinMode(A9, OUTPUT) and digitalWrite(A9, HIGH) work. |
| A10 | A10, PK2, ADC10 | Analog input: analogRead(A10) reads ADC channel 10. Also a digital pin: pinMode(A10, OUTPUT) and digitalWrite(A10, HIGH) work. |
| A11 | A11, PK3, ADC11 | Analog input: analogRead(A11) reads ADC channel 11. Also a digital pin: pinMode(A11, OUTPUT) and digitalWrite(A11, HIGH) work. |
| A12 | A12, PK4, ADC12 | Analog input: analogRead(A12) reads ADC channel 12. Also a digital pin: pinMode(A12, OUTPUT) and digitalWrite(A12, HIGH) work. |
| A13 | A13, PK5, ADC13 | Analog input: analogRead(A13) reads ADC channel 13. Also a digital pin: pinMode(A13, OUTPUT) and digitalWrite(A13, HIGH) work. |
| A14 | A14, PK6, ADC14 | Analog input: analogRead(A14) reads ADC channel 14. Also a digital pin: pinMode(A14, OUTPUT) and digitalWrite(A14, HIGH) work. |
| A15 | A15, PK7, ADC15 | Analog input: analogRead(A15) reads ADC channel 15. Also a digital pin: pinMode(A15, OUTPUT) and digitalWrite(A15, HIGH) work. |
| GND | GND | Ground (0 V). |
| GND | GND | Ground (0 V). |
| GND | GND | Ground (0 V). |
| GND | GND | Ground (0 V). |
| GND | GND | Ground (0 V). |
| 5V | 5V | 5 V supply: from USB, or from the regulator when the board is powered through VIN. |
| 5V | 5V | 5 V supply: from USB, or from the regulator when the board is powered through VIN. |
| 5V | 5V | 5 V supply: from USB, or from the regulator when the board is powered through VIN. |
| IOREF | IOREF | Tells shields the I/O voltage of the board (5 V). Not a supply to draw from. |
| 3.3V | 3V3 | 3.3 V supply from the on-board regulator. Keep the load small. |
Good to know
- Each I/O pin can source or sink about 20 mA (40 mA is the absolute maximum); keep the whole chip under 200 mA.
- analogWrite() works on the pins marked ~PWM: about 490 Hz, or 980 Hz on the Timer0 pins. Timer0 also runs millis() and delay().
- attachInterrupt() works on D2, D3, D18, D19, D20 and D21; A8–A15 and some other pins also have pin-change interrupts.
- D0 and D1 carry Serial to the computer. Leave them free while you use the Serial Monitor.
- The port tags give the register bit behind each pin: D13 is PB7, so PORTB |= (1 << PB7) drives it high without digitalWrite().
- Arduino Uno pinout
- Arduino Nano pinout
- ATtiny85 pinout
- ESP32-C3 DevKitM-1 pinout
- ESP32-S3 DevKitC-1 pinout
- ESP32-C5 DevKitC-1 pinout
- ESP32-C6 DevKitC-1 pinout
- ESP32-H2 DevKitM-1 pinout
- ESP32-P4 Function-EV pinout
- Blue Pill (STM32F103C8) pinout
- Nucleo-F030R8 pinout
- Nucleo-G071RB pinout
- Nucleo-F401RE pinout
- Nucleo-F446RE pinout
- Nucleo-F767ZI pinout
- Nucleo-H743ZI2 pinout
- Nucleo-WBA55CG pinout
- Nucleo-L552ZE-Q pinout
- Black Pill (STM32F411CE) pinout
- Raspberry Pi Pico pinout
- Raspberry Pi Pico W pinout
- Raspberry Pi Pico 2 pinout
- Raspberry Pi Pico 2 W pinout