Judy@4pcba.com
7:30 AM - 7:30 PM
Monday to Saturday

Arduino Leonardo Pinout: Connection Points for the ATmega32u4-Based Microcontroller

Introduction to Arduino Leonardo

The Arduino Leonardo is a member of the Arduino family of microcontroller boards. It is designed around the ATmega32u4 microcontroller, which combines the functionality of a traditional Arduino board with the added benefit of built-in USB communication. This feature allows the Leonardo to appear as a USB device, such as a keyboard or mouse, to a connected computer, enabling unique interactive projects.

Key Features of Arduino Leonardo

  • ATmega32u4 microcontroller running at 16 MHz
  • 20 digital input/output pins
  • 7 analog input pins
  • 12 PWM (Pulse Width Modulation) pins
  • Built-in USB communication
  • ICSP header for programming
  • Compact form factor

Arduino Leonardo Pinout Diagram

To understand the Arduino Leonardo pinout, let’s take a look at the following diagram:

+-----+
| USB |
+-----+
   |
+-----+
|     |
| ATmega32u4 |
|     |
+-----+
   |
   |     +-----+-----+-----+-----+-----+-----+-----+-----+
   +-----|  0  |  1  |  2  |  3  |  4  |  5  |  6  |  7  |
         +-----+-----+-----+-----+-----+-----+-----+-----+
   |     |  8  |  9  | 10  | 11  | 12  | 13  |GND  |AREF |
   +-----|-----+-----+-----+-----+-----+-----+-----+-----|
         |A0/14|A1/15|A2/16|A3/17|A4/18|A5/19|     |     |
         +-----+-----+-----+-----+-----+-----+-----+-----+

Digital Pins

The Arduino Leonardo features 20 digital input/output pins, labeled from 0 to 13 and A0 to A5. These pins can be used for various purposes, such as reading digital sensors, controlling LEDs, or communicating with other devices.

Digital Pin Functions

Pin Function
0 RX (UART Receive)
1 TX (UART Transmit)
2 External Interrupt
3 PWM / External Interrupt
4 PWM
5 PWM
6 PWM
7 PWM
8 PWM
9 PWM
10 PWM / SPI Slave Select
11 PWM / SPI MOSI
12 PWM / SPI MISO
13 PWM / SPI SCK / Built-in LED

Using Digital Pins

To use a digital pin as an input or output, you need to configure it using the pinMode() function in your Arduino sketch. For example, to set pin 13 as an output:

pinMode(13, OUTPUT);

You can then use the digitalWrite() function to set the state of the pin:

digitalWrite(13, HIGH);  // Turn on the built-in LED

To read the state of a digital pin configured as an input, use the digitalRead() function:

int buttonState = digitalRead(2);  // Read the state of a button connected to pin 2

Analog Pins

The Arduino Leonardo has 6 analog input pins, labeled A0 to A5. These pins can read analog voltages between 0V and 5V, allowing you to connect various analog sensors or devices.

Analog Pin Functions

Pin Function
A0 Analog Input / Digital Pin 14
A1 Analog Input / Digital Pin 15
A2 Analog Input / Digital Pin 16
A3 Analog Input / Digital Pin 17
A4 Analog Input / Digital Pin 18 / SDA (I2C)
A5 Analog Input / Digital Pin 19 / SCL (I2C)

Using Analog Pins

To read an analog value from an analog pin, you can use the analogRead() function. It returns a value between 0 and 1023, proportional to the voltage on the pin:

int sensorValue = analogRead(A0);  // Read the value from an analog sensor connected to A0

The analog pins can also be used as digital input/output pins, referred to as digital pins 14 to 19. To use them as digital pins, simply refer to them using their digital pin numbers:

pinMode(14, OUTPUT);  // Set A0 as a digital output
digitalWrite(14, HIGH);  // Set A0 to a high state

PWM Pins

Arduino Leonardo has 7 pins that support Pulse Width Modulation (PWM) output. PWM allows you to generate analog-like signals using digital pins, which is useful for controlling the brightness of LEDs, the speed of motors, or creating audio signals.

PWM Pin Functions

Pin Function
3 PWM
5 PWM
6 PWM
9 PWM
10 PWM
11 PWM
13 PWM

Using PWM Pins

To generate a PWM signal on a PWM-capable pin, use the analogWrite() function. It takes a value between 0 and 255, representing the duty cycle of the PWM signal:

analogWrite(9, 128);  // Generate a 50% duty cycle PWM signal on pin 9

Communication Pins

Arduino Leonardo supports various communication protocols, including UART (Serial), SPI, and I2C. These protocols allow the Leonardo to communicate with other devices, such as sensors, displays, or other microcontrollers.

UART (Serial) Communication

The Leonardo has a built-in USB-to-Serial converter, allowing it to communicate with a computer or other devices using serial communication. The UART pins are:

Pin Function
0 RX (Receive)
1 TX (Transmit)

To use serial communication, you can utilize the Serial object in your Arduino sketch:

Serial.begin(9600);  // Initialize serial communication at 9600 baud
Serial.println("Hello, Arduino!");  // Send a message over serial

SPI Communication

SPI (Serial Peripheral Interface) is a synchronous communication protocol commonly used for communicating with sensors, displays, and other peripherals. The SPI pins on the Arduino Leonardo are:

Pin Function
10 SS (Slave Select)
11 MOSI (Master Out, Slave In)
12 MISO (Master In, Slave Out)
13 SCK (Serial Clock)

To use SPI communication, you can utilize the SPI library in your Arduino sketch:

#include <SPI.h>

void setup() {
  SPI.begin();  // Initialize SPI communication
}

void loop() {
  // SPI communication code here
}

I2C Communication

I2C (Inter-Integrated Circuit) is a synchronous communication protocol commonly used for communicating with sensors, displays, and other peripherals. The I2C pins on the Arduino Leonardo are:

Pin Function
A4 SDA (Serial Data)
A5 SCL (Serial Clock)

To use I2C communication, you can utilize the Wire library in your Arduino sketch:

#include <Wire.h>

void setup() {
  Wire.begin();  // Initialize I2C communication
}

void loop() {
  // I2C communication code here
}

Power Pins

The Arduino Leonardo provides several power-related pins for powering the board and connected peripherals:

Pin Function
VIN Input voltage (7-12V)
5V Regulated 5V output
3.3V Regulated 3.3V output
GND Ground
IOREF Reference voltage for digital pins
  • The VIN pin can be used to power the Leonardo board using an external power source (7-12V).
  • The 5V and 3.3V pins provide regulated power outputs for powering external components.
  • The GND pin is the common ground reference for the board and connected peripherals.
  • The IOREF pin provides the reference voltage for the digital pins, which is typically 5V.

Other Pins and Features

Reset Pin

The Reset pin on the Arduino Leonardo is used to reset the microcontroller. When this pin is connected to ground, it triggers a reset of the board.

ICSP Header

The ICSP (In-Circuit Serial Programming) header on the Leonardo allows for direct programming of the ATmega32u4 microcontroller using an external programmer. This is useful for advanced users who want to bypass the USB bootloader and program the microcontroller directly.

Built-in LED

The Arduino Leonardo has a built-in LED connected to digital pin 13. This LED can be used for debugging, status indication, or any other purpose in your projects. To control the built-in LED, you can use the digitalWrite() function on pin 13.

FAQ

  1. What is the difference between Arduino Leonardo and Arduino Uno?
    The main difference between Arduino Leonardo and Arduino Uno is the microcontroller they use. The Leonardo uses the ATmega32u4, while the Uno uses the ATmega328P. The Leonardo has built-in USB communication, allowing it to appear as a USB device to a computer, whereas the Uno requires an additional USB-to-Serial converter chip.

  2. Can I use Arduino Leonardo as a USB keyboard or mouse?
    Yes, the Arduino Leonardo can be programmed to emulate a USB keyboard or mouse. This capability allows you to create interactive projects that can send keystrokes or mouse movements to a connected computer.

  3. How do I upload sketches to Arduino Leonardo?
    To upload sketches to Arduino Leonardo, you need to select the correct board and port in the Arduino IDE. Make sure to select “Arduino Leonardo” from the “Tools > Board” menu and choose the appropriate port from the “Tools > Port” menu. Then, you can click the “Upload” button to compile and upload your sketch to the board.

  4. Can I use shields designed for Arduino Uno with Arduino Leonardo?
    Most shields designed for Arduino Uno can be used with Arduino Leonardo. However, due to the different pinout and form factor, some shields may require minor modifications or adaptations to work properly with the Leonardo.

  5. How can I power my Arduino Leonardo project?
    There are several ways to power an Arduino Leonardo project:

  6. USB: You can power the Leonardo directly from a USB port on your computer or a USB power adapter.
  7. External Power Supply: Connect a 7-12V power source to the VIN pin and GND pin of the Leonardo.
  8. Batteries: You can use batteries to power the Leonardo by connecting them to the VIN and GND pins, ensuring the voltage is within the acceptable range.

Conclusion

The Arduino Leonardo is a versatile and powerful microcontroller board that offers a wide range of connection points and features. By understanding the Arduino Leonardo pinout and the functions of each pin, you can effectively utilize this board for various projects and applications.

Whether you are a beginner or an experienced user, the Arduino Leonardo provides a user-friendly platform for learning, prototyping, and creating innovative projects. With its built-in USB communication, analog and digital pins, PWM capabilities, and communication protocols, the Leonardo opens up a world of possibilities for interactive and autonomous systems.

By exploring the Arduino Leonardo pinout and its capabilities, you can unlock the full potential of this microcontroller board and bring your ideas to life. Happy tinkering and creating with Arduino Leonardo!