Arduino Leonardo

The Arduino that can pretend to be a keyboard or mouse. The Arduino Leonardo uses the ATmega32U4 with native USB built in, so it needs no separate USB chip and can appear to your PC as a real USB device. This guide covers the full board anatomy, a complete pinout with every pin explained, its native-USB HID trick, the buses, a Leonardo vs Uno comparison, and code and mini-projects.

Complete Learning Path — Arduino Leonardo

From board anatomy and the ATmega32U4, to a full pinout with every pin detailed, power, digital & analog I/O, native USB (HID), the buses, uploading, Leonardo vs Uno, code and mini-projects

What is the Arduino Leonardo?

The Arduino Leonardo looks like an Uno, but its brain is the ATmega32U4 — a chip with USB built right in. That single change means the board needs no separate USB-serial chip, and it can pretend to be a USB keyboard or mouse.

Everything else is Uno-familiar: 5 V logic, the same shield shape and the same Arduino IDE. Just a few pins move around (more on that below).

Labelled Arduino Leonardo board anatomy: native-USB ATmega32U4, micro-USB port, DC jack, regulator, headers and LEDs
A map of the Leonardo: the ATmega32U4 does both the computing and the USB — there is no separate USB chip.
ATmega32U4
8-bit AVR + USB
Native USB
Keyboard / mouse
20 + 12
Digital + analog pins
5 V
Logic level

The Brain: ATmega32U4

The ATmega32U4 is the same family as the Uno's chip, but with one big addition: a built-in USB controller. It runs at 16 MHz and carries a little more RAM.

Block diagram of the ATmega32U4: AVR CPU, 32 KB flash, 2.5 KB SRAM, 1 KB EEPROM, 20 I/O lines, 12-channel ADC, timers and native USB
Inside the ATmega32U4: CPU + 32 KB flash / 2.5 KB SRAM / 1 KB EEPROM + GPIO, 12-channel ADC, timers, and a native USB controller.
  • Flash (32 KB) — stores your program; ~4 KB is the (larger, USB) bootloader.
  • SRAM (2.5 KB) — working memory for variables.
  • EEPROM (1 KB) — non-volatile store that survives power-off.
  • Native USB — the stand-out feature: the chip is its own USB device (keyboard, mouse, or serial).

Full Arduino Leonardo Pinout

Here is the complete pinout. The header shape matches the Uno, but note the differences: I2C is on D2/D3, SPI is on the ICSP header, and six analog inputs (A6–A11) live on digital pins.

Detailed Arduino Leonardo pinout: every pin with its Arduino number, port register and alternate functions (ADC, PWM, I2C, UART), with SPI on ICSP
The full Leonardo pinout — digital on the right, power & analog on the left. SCL = D3, SDA = D2; A6–A11 share digital pins.

Prefer a simpler view? This colour-coded map groups the header pins by function:

Simplified Arduino Leonardo pinout showing digital, PWM, analog and power pins colour-coded, with I2C on D2/D3
Quick overview — note D2 = SDA, D3 = SCL and the extra analog pins on the digital header.

Every Pin Explained

Let's go through each group of pins. Where the Leonardo differs from the Uno, it's flagged — those differences trip up a lot of beginners.

Digital pins (0–13)

14 header pins that read or write HIGH (5 V) or LOW (0 V) with pinMode(), digitalWrite() and digitalRead(). Each handles ~20 mA (40 mA max). The A0–A5 pins can also be used as digital, giving 20 in total.

D2 (SDA) & D3 (SCL)

The I2C bus — on the Leonardo it's here, not on A4/A5.

D0 (RX) & D1 (TX)

Serial1 hardware UART — separate from the USB Serial.

PWM (~) — 7 pins

Pins 3, 5, 6, 9, 10, 11, 13 — analogWrite(0–255).

Interrupts

Pins 0, 1, 2, 3, 7 support attachInterrupt().

Pin 13

Wired to the on-board “L” LED — a first test with no extra parts.

Analog input pins (12 total)

The Leonardo has 12 analog inputs, each a 10-bit ADC reading 0–5 V as 0–1023:

  • A0–A5 on the analog header.
  • A6–A11 share digital pins 4, 6, 8, 9, 10, 12 — read them with analogRead(A6) … analogRead(A11).

The buses (and where they moved)

BusLeonardo pinsOn the Uno…
Serial (USB)Serial — virtual USB portsame object as pins 0/1
UARTSerial1 on D0 (RX) / D1 (TX)this is Serial
I2CD2 (SDA) / D3 (SCL)A4 / A5
SPIICSP header only11–13 + ICSP

Power pins

VIN (7–12 V in), 5V (regulated out), 3.3V (~50 mA), GND, IOREF, RESET and AREF — the same as the Uno.

The classic Leonardo trap

If a library or tutorial says “I2C on A4/A5” or “SPI on 11–13”, that's Uno wiring. On the Leonardo, wire I2C to 2/3 and take SPI from the ICSP header. And use Serial1 (not Serial) for a module on pins 0/1.

Native USB — Keyboard & Mouse (HID)

This is why the Leonardo exists. Because the 32U4 speaks USB itself, the board can present to a PC as a real USB keyboard or mouse — something the Uno and Nano can't do.

Arduino Leonardo native USB HID: the board connects over USB and the PC sees a real keyboard or mouse, with Keyboard.print and Mouse.move
The PC sees a genuine HID device. Type with Keyboard.print(), move the cursor with Mouse.move().
// type a line when a button on pin 2 is pressed
#include <Keyboard.h>
void setup() {
  pinMode(2, INPUT_PULLUP);
  Keyboard.begin();
}
void loop() {
  if (digitalRead(2) == LOW) {      // pressed
    Keyboard.println("Hello from Leonardo!");
    delay(1000);                    // avoid repeats
  }
}
Gate your HID code

A sketch that types or moves the mouse non-stop makes the PC very hard to use. Always trigger HID actions from a button or condition (as above), never on every loop(). If you get stuck, double-tap RESET to re-flash.

Powering the Leonardo

Power it from micro-USB (5 V), a 7–12 V DC jack, or the VIN pin. An on-board regulator makes the clean 5 V the chip needs.

Arduino Leonardo power paths: micro-USB 5 V or a 7-12 V DC jack through the regulator to the 5 V and 3.3 V rails
Micro-USB or the DC jack → regulator → clean 5 V (and 3.3 V from a second regulator).

Digital I/O

Output a HIGH/LOW to drive an LED or relay, or read a HIGH/LOW input from a button or sensor.

Arduino digital I/O: an output pin driving an LED through a resistor, and an input pin reading a button with a pull-down resistor
Output drives an LED (via a 220 Ω resistor); input reads a button with a 10k pull-down so the pin never floats.
// digital output + input
void setup() {
  pinMode(13, OUTPUT);      // LED pin
  pinMode(7, INPUT);        // button pin
}
void loop() {
  digitalWrite(13, digitalRead(7));   // LED follows the button
}

PWM Output (~)

PWM fakes an analog voltage by switching a pin on and off fast. The Leonardo has 7 PWM pins: 3, 5, 6, 9, 10, 11, 13.

Arduino PWM: three duty cycles (25%, 50%, 75%) and their average voltages, set with analogWrite
Higher duty → higher average voltage. Use analogWrite(pin, 0–255) on any of the 7 ~ pins.
// fade an LED on a PWM pin (~9)
void setup() { pinMode(9, OUTPUT); }
void loop() {
  for (int v = 0; v <= 255; v++) { analogWrite(9, v); delay(5); }
  for (int v = 255; v >= 0; v--) { analogWrite(9, v); delay(5); }
}

Analog Input (ADC)

The Leonardo has 12 analog inputs — six more than the Uno. Each 10-bit reading turns 0–5 V into 0–1023.

Arduino analog input: a potentiometer feeding A0, and the 10-bit ADC mapping 0-5 V to 0-1023
A potentiometer on A0 → the ADC reads 0–1023. Convert to volts with v * 5.0 / 1023.0. A6–A11 live on digital pins.
// read an "extra" analog input (A6 is on digital pin 4)
void setup() { Serial.begin(9600); }
void loop() {
  int raw = analogRead(A6);          // 0..1023
  float volts = raw * 5.0 / 1023.0;
  Serial.println(volts);
  delay(200);
}

Serial, SPI & I2C

The Leonardo has the usual three buses — but on different pins from the Uno, so it's worth a close look.

Arduino Leonardo communication buses: Serial1 on D0/D1, SPI on the ICSP header, and I2C on D2/D3
Serial1 on D0/D1 (separate from USB Serial), SPI on the ICSP header, I2C on D2/D3.

How Code Gets onto the Leonardo

The 32U4 handles USB itself, so there's no separate USB chip in the upload path. Write a sketch, connect micro-USB, pick Arduino Leonardo, and upload.

Arduino Leonardo upload flow: write in the IDE, compile, send over the 32U4's native USB, and the bootloader writes it to flash
Write → compile → native USB (32U4) → the bootloader writes it to flash → run.
If an upload fails: double-tap RESET

Because the sketch shares the USB port, a bad sketch can hide the board. Double-tap the RESET button to force the bootloader for a few seconds, then upload and pick the temporary bootloader port.

Leonardo vs Uno

Same shape, same 5 V code — but the 32U4 changes what the board can do and where a few pins live.

Comparison table of the Arduino Leonardo and Uno: microcontroller, native USB, HID, serial, pins, analog inputs and bus pins
Native USB and HID, more analog pins, and moved buses set the Leonardo apart from the Uno.

Choose the Leonardo for USB keyboard/mouse projects and more analog inputs; the Uno for the most tutorials, easiest uploads and the widest shield support.

Code Examples

The everyday building blocks — plus one that only the Leonardo can run.

1. Blink the on-board LED

void setup() { pinMode(LED_BUILTIN, OUTPUT); }
void loop() {
  digitalWrite(LED_BUILTIN, HIGH); delay(1000);
  digitalWrite(LED_BUILTIN, LOW);  delay(1000);
}

2. Print to the Serial Monitor (wait for USB)

void setup() {
  Serial.begin(9600);
  while (!Serial) { ; }          // wait for the USB port (Leonardo)
  Serial.println("Ready!");
}
void loop() { Serial.println(millis()); delay(1000); }

3. Talk to a module on Serial1

void setup() {
  Serial.begin(9600);       // USB to PC
  Serial1.begin(9600);      // module on pins 0/1
}
void loop() {
  if (Serial1.available()) Serial.write(Serial1.read());
}

Beginner Mini-Projects

Start with the classics, then try the HID trick that makes the Leonardo special.

Arduino Blink project: an LED and 220 ohm resistor on pin 13 with the blink sketch
Project 1 wiring — the classic Blink. Pin 13 already has an on-board LED, so this works even with no parts.

Project 1 — Blink an LED

Parts: 1 LED, 1 × 220 Ω resistor. LED anode → resistor → pin 13; cathode → GND.
void setup() { pinMode(13, OUTPUT); }
void loop() {
  digitalWrite(13, HIGH); delay(500);
  digitalWrite(13, LOW);  delay(500);
}

Project 2 — Button-triggered keyboard shortcut

Parts: 1 push-button between pin 2 and GND. Pressing it types text on your PC — the Leonardo's HID trick.
#include <Keyboard.h>
void setup() { pinMode(2, INPUT_PULLUP); Keyboard.begin(); }
void loop() {
  if (digitalRead(2) == LOW) {
    Keyboard.print("power4all.in");
    delay(800);              // debounce / avoid repeats
  }
}

Project 3 — Mouse jiggler (button-gated)

Parts: 1 push-button between pin 3 and GND. Nudges the mouse while held — only the Leonardo can do this.
#include <Mouse.h>
void setup() { pinMode(3, INPUT_PULLUP); Mouse.begin(); }
void loop() {
  if (digitalRead(3) == LOW) { Mouse.move(3, 0); delay(200); Mouse.move(-3, 0); delay(200); }
}

Project 4 — I2C sensor on D2/D3

Parts: any I2C module (e.g. an OLED or BMP280). Wire SDA → D2, SCL → D3 (not A4/A5!), then use the Wire library.
#include <Wire.h>
void setup() {
  Serial.begin(9600);
  Wire.begin();                // SDA=2, SCL=3 on the Leonardo
}
void loop() {
  Wire.beginTransmission(0x3C);   // example device address
  byte err = Wire.endTransmission();
  Serial.println(err == 0 ? "found" : "not found");
  delay(1000);
}

Specifications

The Arduino Leonardo at a glance.

Arduino Leonardo specifications table: ATmega32U4, 16 MHz, 5 V, 32 KB flash, 20 digital pins, 12 analog inputs, native USB
Key numbers for the Leonardo — MCU, clock, memory, pins, native USB and buses.

Key Terms — Glossary

TermMeaning
ATmega32U4The Leonardo's 8-bit AVR chip, with a built-in USB controller.
Native USBUSB handled by the MCU itself — no separate USB-serial chip.
HIDHuman Interface Device — a keyboard or mouse the PC recognises.
Serial vs Serial1Serial = USB to PC; Serial1 = hardware UART on 0/1.
PWM (~)Pulse-width modulation; 7 pins on the Leonardo (3,5,6,9,10,11,13).
ADCAnalog-to-digital converter; 12 inputs, 10-bit (0–1023).
I2C2-wire bus on D2 (SDA) / D3 (SCL) — not A4/A5.
SPIOn the ICSP header (MISO/MOSI/SCK) — not pins 11–13.
BootloaderUSB bootloader; double-tap RESET to force it if uploads fail.

Frequently Asked Questions

Quick answers to the questions people ask most about the Arduino Leonardo.

What is the Arduino Leonardo?

A board built around the ATmega32U4, which has native USB. It can act as a USB keyboard or mouse, and has 20 digital pins (7 PWM), 12 analog inputs, 32 KB flash and 5 V logic in the Uno's shield-compatible shape.

Leonardo vs Uno — what's different?

Native USB (so it can be a keyboard/mouse and needs no USB chip), 20 digital + 12 analog pins, I2C on D2/D3 (not A4/A5), SPI on the ICSP header only, and Serial (USB) separate from Serial1 (pins 0/1).

Can it really be a keyboard or mouse?

Yes — use the built-in Keyboard and Mouse libraries (Keyboard.print(), Mouse.move()). Always trigger HID actions from a button, or the PC becomes hard to control.

Where are I2C and SPI?

I2C is on pins 2 (SDA) and 3 (SCL). SPI is only on the ICSP header (MISO, MOSI, SCK) — not pins 11–13. Serial1 (UART) is on pins 0/1.

How many analog inputs does it have?

12: A0–A5 on the analog header, plus A6–A11 on digital pins 4, 6, 8, 9, 10 and 12. Read them with analogRead(A6) and so on.

What's the difference between Serial and Serial1?

Serial is the USB connection to the PC (the Serial Monitor). Serial1 is the hardware UART on pins 0/1. On the Uno these are the same; on the Leonardo they're separate objects.

Why won't my Leonardo upload?

A misbehaving sketch can hide the USB port. Double-tap the RESET button to force the bootloader for a few seconds, then start the upload and select the temporary bootloader port.

Do Uno shields fit the Leonardo?

Physically yes — same shape and headers. Just check shields that assume I2C on A4/A5 or SPI on 11–13, since the Leonardo puts those on 2/3 and the ICSP header.

Conclusion & Key Takeaways

The Arduino Leonardo is the Uno's USB-native cousin — same easy code, plus the power to be a keyboard or mouse.

ATmega32U4

Native USB built in.

Keyboard / mouse

HID libraries.

20 + 12 pins

Digital + analog.

I2C on 2/3

SPI on ICSP.

Serial + Serial1

USB and UART.

Uno-shaped

Shields fit.

Continue Learning