Skip to main content

wokwi-arduino-mega Reference

Arduino Mega 2560. Powered by the ATmega2560 chip, which has 256K bytes of Flash program memory, 8k bytes of SRAM and 4K bytes of EEPROM. The board features 54 digital pins, 16 analog input pins, and 4 serial ports. It runs at 16MHz.

Pin names#

Pins 0 to 53 are digital GPIO pins. Pins A0 to A15 double as analog input pins, in addition to being digital GPIO pins.

There are five ground pins: GND.1 (next to pin 13), GND.2/GND.3 (next to the Vin pin), and GND.4/GND.5 (at the bottom of the dual-row female header connector)

Pins VIN / 5V are connected to the positive power supply. There are also two additional power supply pins, 5V.1/5V.2, at the top of the dual-row female header connector.

Pins 3.3V / IOREF / AREF / RESET are not available in the simulation.

Digital pins 2 … 13, 44, 45, and 46 have hardware PWM support (total of 15 PWM channels).

Some of the digital pins also have additional functions:

PinFunctionSignalExternal interrupt
0SerialRX
1SerialTX
2INT4
3INT5
19Serial1RXINT2
18Serial1TXINT3
17Serial2RX
16Serial2TX
15Serial3RX
14Serial3TX
20I2CSDA (Data)INT1
21I2CSCL (Clock)INT0
50SPIMISO
51SPIMOSI
52SPISCK (Clock)
53SPISS (Chip select)

On board LEDs#

The board includes four LEDs:

LEDFunction
LConnected to digital pin 13
RXSerial RX Activity
TXSerial TX Activity
ONPower LED. Always on while the simulation is running

In general, only the "L" LED can be controlled by the user's code. You can use the LED_BUILTIN constant to reference it from your code:

pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);

See Blink for a complete code example.

Simulation features#

The Arduino Mega 2560 is simulated using the AVR8js Library. The table below summarizes the status of features:

PeripheralStatusNotes
Processor✔️
GPIO✔️Including External/Pin Change Interrupts
8-bit timers✔️Timer0, Timer2
16-bit timers✔️Timer1, Timer3, Timer4, Timer5 *
Output Compare Modulator
Watchdog Timer
USART✔️USART0, USART1, USART1, USART3
SPI🟡Master mode only
I2C🟡Master mode only
EEPROM✔️
Clock Prescale✔️
ADC✔️Used by analogRead()
Analog Comparator
GDB Debugging✔️See the GDB Debugging Guide

Legend: ✔️ Simulated 🟡 Simulated, but see notes ❌ Not implemented

* Compare Match C and Input Capture are not implemented in the 16-bit timers.

If you need any of the missing features, please open an issue on the AVR8js repo or reach out on Discord.

Serial Monitor#

You can use the Serial Monitor to receive information from your Arduino code, such as debug print. You can also use it to send information to your code, such as textual commands.

For more information and code samples, check out the Serial Monitor guide. It also explains how to connect the serial monitor to a different pin (e.g. to Serial2 instead of Serial), and how to configure the line ending characters.

Libraries#

The simulator supports many popular Arduino libraries. For a complete list, see the Libraries guides.

Simulator examples#