02Lesson
Robotics Lab: Arduino Mega 2560 R3 Lesson and Pinout
Select a board in Robotics Lab to see its specifications, pin functions and component guide.
Board overview
Robotics Lab board guide · Arduino · 2010
The big brother of the Arduino Uno: the same simple language and the same shields, but more than three times the pins and eight times the memory. Reach for a Mega when a robot needs lots of motors, sensors and displays at once — a walking robot, a robotic arm or a 3D printer.
- Clock
- 16 MHz
- Flash
- 256 KB
- RAM
- 8 KB
- GPIO pins
- 54
- Logic level
- 5 V
- Price
- ≈ $45
Specs
Compare the electrical specs with other Robotics Lab boards. See the hardware references.
- Microcontroller
- ATmega2560 (8-bit AVR)
- Clock speed
- 16 MHz
- Flash memory
- 256 KB (8 KB used by the bootloader)
- RAM / EEPROM
- 8 KB / 4 KB
- Digital pins
- 54, of which 15 with PWM
- Analog inputs
- 16 (10-bit ADC)
- Serial interfaces
- 4 hardware UARTs, I²C, SPI
- Logic voltage
- 5 V
- Current per pin
- 20 mA (absolute maximum 40 mA)
- Power
- USB 5 V or 7–12 V via barrel jack / Vin
- USB
- USB-B connector, ATmega16U2 bridge
- Size and weight
- 101.6 × 53.3 mm, 37 g
What’s on the board
16 parts match the numbered labels in Robotics Lab. Click one and the camera flies to it.
Strengths and pitfalls
Use these trade-offs when choosing a board in Robotics Lab.
Strengths
- 70 pins: 54 digital and 16 analog — enough for a big robot
- Four hardware UARTs: GPS, Bluetooth and debugging at the same time, no SoftwareSerial needed
- Compatible with Arduino Uno shields and sketches
- 5 V logic works directly with most classroom sensors and modules
Watch out
- A pin supplies no more than 20 mA: power motors and servos from a separate supply through a driver, with the grounds connected together.
- 3.3 V modules (ESP8266, nRF24L01, many sensors) must not be wired straight to the 5 V pins — use a level shifter.
- SPI and I²C are not where they are on the Uno: SPI is on pins 50–53, I²C on 20 and 21. Old shields that expect pins 11–13 and A4/A5 may not work.
- Feed 7–12 V into the barrel jack. Above that the regulator runs hot; below that the board gets less than 5 V.
Pins
Learn which pins to use on the Robotics Lab workbench.
Power
5V and 3.3V are outputs for sensors (no more than 50 mA from 3.3V). GND is the common "minus". Vin carries whatever voltage arrives at the barrel jack. The double-row header has two more 5 V contacts at the top and two GND contacts at the bottom.
Digital pins and PWM
Pins 0–53 work as inputs or outputs with 0 V and 5 V levels. PWM (analogWrite) is available on pins 2–13 and 44–46. External interrupts are on 2, 3, 18, 19, 20 and 21.
Analog inputs
A0–A15 measure 0–5 V with 10-bit resolution (0–1023). They can also be used as ordinary digital pins 54–69.
Serial ports
Serial (pins 0, 1) is tied to USB — keep those pins free if you use the Serial Monitor. Serial1 is on 19 (RX) and 18 (TX), Serial2 on 17 and 16, Serial3 on 15 and 14.
I²C and SPI
I²C: 20 (SDA) and 21 (SCL), duplicated next to AREF. SPI: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS) and on the ICSP header — not on 10–13 as on the Uno.
Hover over a pin in the Robotics Lab viewer to see its name and function.
- Power
- Ground
- Digital
- Analog
- Buses: UART, I²C, SPI
- Control: RESET, EN, BOOT
- Not connected
First code
Try the Robotics Lab starter example on your physical board.
// The Mega has four hardware serial ports: Serial (USB), Serial1, Serial2, Serial3.// We blink the built-in LED "L" and forward everything a module sends// on Serial1 (for example a Bluetooth HC-05 or a GPS) to the Serial Monitor.// Module wiring: its TX -> pin 19 (RX1), its RX -> pin 18 (TX1), GND -> GND.const int LED = 13; // built-in LED "L"unsigned long lastBlink = 0; // time of the last blinkbool ledOn = false;void setup() { pinMode(LED, OUTPUT); Serial.begin(9600); // link to the computer over USB Serial1.begin(9600); // link to the module on pins 18 and 19 Serial.println("Mega is ready!");}void loop() { // Blink without delay() so no incoming data is missed if (millis() - lastBlink >= 500) { lastBlink = millis(); ledOn = !ledOn; digitalWrite(LED, ledOn); } // Module -> computer if (Serial1.available()) Serial.write(Serial1.read()); // Computer -> module if (Serial.available()) Serial1.write(Serial.read());}
Where it shines
Use the Robotics Lab workbench to plan the wiring for a project.
- Hexapod robot: 18 servos through a driver, sensors on the remaining pins
- Robotic arm with joysticks, limit switches and a display
- The brain of a 3D printer or CNC machine (a RAMPS board plugs on top as a shield)
- A large weather station or smart greenhouse with dozens of sensors
- LED matrices and panels that need lots of pins
Board background
See how this hardware fits into the Robotics Lab board collection.
Thousands of home-built RepRap 3D printers ran on an Arduino Mega with a RAMPS shield — this board helped make desktop 3D printing mainstream.
The ATmega2560 has one hundred leads and 86 of them can be inputs/outputs, but only 70 are brought out to the headers.
Analog inputs A0–A15 double as digital pins 54–69: digitalWrite(A0, HIGH) works.
Practice with this board
Try the same board in these Robotics Lab activities.
- Inspect the Robotics Lab 3D model to locate a component or connector.
- Try the Robotics Lab component quiz to check what you remember.
- Open the Robotics Lab workbench to simulate your wiring.
Sources
Manufacturer and hardware project documentation.
- Arduino Mega 2560 Rev3 hardware documentation
ATmega2560 board specifications, pinout and schematics.