MakerLab
ArduinoArduino Leonardo

Arduino Leonardo: The Versatile Microcontroller with Native USB

The Arduino Leonardo is a microcontroller board based on the ATmega32U4, notable for its integrated USB controller, making it ideal for human interface device (HID) projects.

Arduino Leonardo

The Arduino Leonardo is a significant board in the Arduino family, released in 2012. It was one of the first Arduino boards to feature the ATmega32U4 microcontroller, which integrates a full USB 2.0 controller. This built-in USB functionality means the Leonardo can act as a native USB device, such as a keyboard or mouse, without needing a separate USB-to-serial chip. This capability opens up a wide range of unique project possibilities not easily achievable with other Arduino boards.

At its heart, the Arduino Leonardo is powered by the Atmel (now Microchip) ATmega32U4, an 8-bit AVR microcontroller. This chip provides a good balance of processing power, memory, and peripherals for many embedded applications. It features 32KB of Flash memory for program storage, 2.5KB of SRAM for variables, and 1KB of EEPROM for persistent data storage. The ATmega32U4 operates at a clock speed of 16 MHz, offering sufficient performance for typical Arduino projects.

The Leonardo occupies a unique position in the Arduino ecosystem. While many Arduino boards rely on a separate USB-to-serial converter chip (like the FTDI chip on the Arduino Uno), the Leonardo's ATmega32U4 handles both the microcontroller tasks and the USB communication directly. This simplifies the board's design and reduces cost, while greatly enhancing its functionality for projects requiring USB HID emulation. It's well-suited for makers, students, and engineers who want to explore interactive electronics, custom input devices, or projects that interface directly with a computer via USB.

Historically, the Leonardo represented a step forward in making advanced USB capabilities accessible to the Arduino community. Its release provided a powerful yet easy-to-use platform for creating custom keyboards, game controllers, MIDI devices, and more. The board maintains compatibility with the vast Arduino software ecosystem, including the Arduino IDE, making it straightforward to program for both beginners and experienced developers.

Watch

Related video, embedded from YouTube.

Specifications

Microcontroller / SoCMicrochip ATmega32U4
Architecture8-bit AVR
Clock speed16 MHz
Flash / Storage32 KB (28 KB for bootloader and sketch)
RAM / SRAM2.5 KB
EEPROM1 KB
Operating voltage5V
Digital I/O pins14 (of which 7 can provide PWM output)
Analog / ADC6 (10-bit resolution)
PWM7 pins (3, 5, 6, 9, 10, 11, 13)
Connectivity1x ICSP header for in-circuit serial programming
USBNative USB (ATmega32U4), supports HID, CDC, MSC
Power input7-12V recommended via DC barrel jack or VIN pin, 5V via USB or 5V pin
Dimensions73.5 mm x 53.3 mm (2.9 in x 2.1 in)

Pinout & pin functions

PinFunction
GNDGround pin
GNDGround pin
5VRegulated 5V output
3.3VRegulated 3.3V output
AREFAnalog Reference voltage
D0 (RX)Digital I/O, UART RX
D1 (TX)Digital I/O, UART TX
D2Digital I/O
D3Digital I/O, PWM
D4Digital I/O
D5Digital I/O, PWM
D6Digital I/O, PWM
D7Digital I/O
D8Digital I/O
D9Digital I/O, PWM
D10 (SS)Digital I/O, PWM, SPI Slave Select
D11 (MOSI)Digital I/O, PWM, SPI Master Out Slave In
D12 (MISO)Digital I/O, SPI Master In Slave Out
D13 (SCK)Digital I/O, PWM, SPI Serial Clock
A0Analog Input, Digital I/O
A1Analog Input, Digital I/O
A2Analog Input, Digital I/O
A3Analog Input, Digital I/O
A4 (SDA)Analog Input, Digital I/O, I2C Data
A5 (SCL)Analog Input, Digital I/O, I2C Clock
VINPower input (7-12V recommended)
RSTReset pin

Wiring & circuit basics

Powering the Arduino Leonardo can be done via its USB connection, the DC barrel jack, or the VIN pin. When using the barrel jack or VIN pin, an external power supply providing 7-12V is recommended. The board has an onboard voltage regulator that steps this down to 5V for the microcontroller and other components. If powering via USB, ensure the USB port can supply at least 500mA, especially if connecting external devices. Avoid powering the board through both USB and the barrel jack/VIN pin simultaneously unless you understand the implications for voltage regulation.

The Arduino Leonardo operates at a logic level of 5V. This means its digital pins output 5V for HIGH signals and 0V for LOW signals. When interfacing with components that operate at different voltage levels, such as 3.3V sensors or devices, it is crucial to use level shifters or voltage dividers to prevent damage. For example, connecting a 3.3V sensor's output directly to a Leonardo input pin might work if the sensor's HIGH output is above 3V, but connecting a 5V output from the Leonardo to a 3.3V input could cause damage. Always check the voltage requirements of your external components.

A simple LED circuit demonstrates basic wiring. Connect an LED's anode (longer leg) to a digital pin, such as D13, through a current-limiting resistor (typically 220-330 ohms). Connect the LED's cathode (shorter leg) to a GND pin. This resistor is essential to prevent the LED from drawing too much current and burning out the pin or the LED itself. When the pin is set to HIGH (5V), current flows through the resistor and LED, illuminating it. When set to LOW (0V), the circuit is broken, and the LED turns off.

Programming & getting started

The primary toolchain for programming the Arduino Leonardo is the Arduino IDE. Download and install the latest version from the official Arduino website. Once installed, connect the Leonardo to your computer via USB. In the IDE, navigate to Tools > Board and select 'Arduino Leonardo'. Then, go to Tools > Port and select the COM port or /dev/ttyACM* that corresponds to your Leonardo. You can then write your sketch, compile it (Verify button), and upload it to the board (Upload button). The ATmega32U4's native USB capability means the board will appear as a serial port automatically.

For more advanced development, PlatformIO, an open-source ecosystem for IoT development, supports the Arduino Leonardo. It integrates with various IDEs like VS Code and offers features like project management, library management, and automated testing. MicroPython and CircuitPython are also options, though official support might vary and require specific firmware flashing procedures. The Leonardo's HID capabilities can also be leveraged with libraries like 'Mouse.h' and 'Keyboard.h' within the Arduino IDE for creating custom input devices.

Project ideas

Custom USB KeyboardBuild a macro pad or a fully custom keyboard. Uses digital pins for key matrix scanning and the ATmega32U4's native USB HID capabilities to send keystrokes to a computer. Teaches matrix scanning and USB HID emulation.
MIDI ControllerCreate a musical instrument controller that sends MIDI messages over USB. Utilizes digital pins for buttons/knobs and the ATmega32U4's USB serial communication. Teaches MIDI protocol and USB communication.
Mouse JigglerDevelop a device that plugs into a computer and subtly moves the mouse cursor to prevent screen locking. Uses the ATmega32U4's native USB HID emulation for mouse control. Teaches basic HID emulation.
USB Game ControllerDesign a custom game controller for PC gaming. Connects buttons and joysticks to digital pins and uses the ATmega32U4's HID capabilities to act as a game controller. Teaches input sensing and HID emulation.
Smart USB Hub with Indicator LEDsBuild a USB hub where each port has an LED indicating power status or data activity. Requires careful consideration of USB power and may involve external USB hub ICs, but the Leonardo acts as the brain. Teaches USB interfacing and power management.
Arduino-to-PC Communication BridgeUse the Leonardo to send sensor data or status updates from other microcontrollers (via serial) to a PC application. The Leonardo acts as a bridge, translating serial data to USB CDC (virtual serial port). Teaches serial communication and USB bridging.

Buying tips & gotchas

When purchasing an Arduino Leonardo, be aware of official boards versus clones. Clones are often significantly cheaper but may have minor variations in component quality or pin labeling. Ensure your USB cable is capable of data transfer, not just charging. For HID projects, remember that the Leonardo will appear as a keyboard or mouse to the host computer, so ensure your code doesn't accidentally trigger unwanted actions. Accessories like a breadboard, jumper wires, resistors, and LEDs are essential for prototyping. Consider a 5V compatible LCD or OLED display for user feedback, connected via I2C or SPI.