CNAP

Arduino Mega Reference

The ATmega2560-based board — same programming model as the Uno, with far more I/O: 54 digital pins, 16 analog inputs, and 4 hardware serial ports.

Pin names

Digital pins (top + right header)

Pin IDLabelSignalNotes
0D0 / RX0USARTSerial 0 receive (shared with USB)
1D1 / TX0USARTSerial 0 transmit (shared with USB)
213D2–D13PWMAll support analogWrite(); D13 has the built-in LED
14 / 15D14/RX3, D15/TX3USARTSerial 3
16 / 17D16/RX2, D17/TX2USARTSerial 2
18 / 19D18/RX1, D19/TX1USARTSerial 1
20D20 / SDAI²CI²C data
21D21 / SCLI²CI²C clock
2243D22–D43DigitalGeneral-purpose I/O
4446D44–D46PWManalogWrite()
4749D47–D49DigitalGeneral-purpose I/O
50D50 / MISOSPISPI data in
51D51 / MOSISPISPI data out
52D52 / SCKSPISPI clock
53D53 / SSSPISPI slave select

Power & analog pins (bottom header)

Pin IDLabelSignalNotes
IOREFIOREFBoard operating voltage reference
RESETRESETPull LOW to reset the board
3.3V3.3VPower3.3 V output
5V5VPower5 V output
GNDGNDPowerGround (multiple pins)
VINVINPowerExternal power input (7–12 V)
A0A15A0–A15AnaloganalogRead(), 10-bit (0–1023)

Quick reference

CapabilityPins
Digital I/OD0–D53 (54 pins)
Analog inputA0–A15 (16 pins, 10-bit)
PWM outputD2–D13, D44–D46
SPID50 (MISO), D51 (MOSI), D52 (SCK), D53 (SS)
I²CD20 (SDA), D21 (SCL)
USART4 ports: Serial (D0/D1), Serial1 (D18/D19), Serial2 (D16/D17), Serial3 (D14/D15)
Operating voltage5 V
Clock speed16 MHz

Usage

void setup() {
  pinMode(13, OUTPUT);
  Serial.begin(9600);    // USB serial (D0/D1)
  Serial1.begin(9600);   // second hardware serial (D18/D19)
}

void loop() {
  digitalWrite(13, HIGH);
  int val = analogRead(A0);
  Serial.println(val);
  delay(500);
}

Reach for the Mega over the Uno when a project needs more I/O than the Uno's 14 digital / 6 analog pins provide, or needs more than one hardware serial port at once (e.g. talking to a GPS module on Serial1 while debugging over USB Serial).

See also

  • Arduino Uno — same core, far fewer pins
  • Arduino Nano — same core in a breadboard-friendly form factor
  • ESP32 DevKit V1 — WiFi/Bluetooth-capable alternative with a different pin layout