Arduino Leonardo Keyboard



  • Arduino Tutorial
  • Arduino Function Libraries
  • Arduino Advanced
  • Arduino Projects
  • Arduino Sensors
  • Motor Control
  • Arduino And Sound
ArduinoArduino leonardo keyboard exampleArduino Leonardo Keyboard

The Leonardo can be toggled in software so the USB port can appear as a keyboard to the PC/Mac. Note - this uses a different USB connector than the UNO. My desk is a mess of cables now that I need three types of USB adapters to go to my UNO, Leonardo and Teensy 2.0.

  1. HiLetgo BadUsb Beetle Bad USB Microcontroller ATMEGA32U4 Development Board Virtual Keyboard for Arduino Leonardo R3 DC 5V 16MHz Visit the HiLetgo Store. 4.0 out of 5 stars 36 ratings. Amazon's Choice highlights highly rated, well-priced products available to ship immediately.
  2. The Arduino Leonardo keyboard API only allows ASCII input and then converts it to the actual key codes sent to the computer via USB. This is a huge problem because it fails for non-QWERTY systems (e.g. In Germany, France) and even for non-Windows systems (e.g. When it comes to special characters on a Mac). Take this code as a small example.
  3. Open the Arduino IDE software on your computer. Coding in the Arduino language will control your circuit. Open a new sketch File by clicking New. Arduino Code /. Keyboard Message test For the Arduino Leonardo and Micro, Sends a text string when a button is pressed.
  • Arduino Useful Resources
  • Selected Reading

In this example, when the button is pressed, a text string is sent to the computer as keyboard input. The string reports the number of times the button is pressed. Once you have the Leonardo programmed and wired up, open your favorite text editor to see the results.

Keyboard

Warning − When you use the Keyboard.print() command, the Arduino takes over your computer's keyboard. To ensure you do not lose control of your computer while running a sketch with this function, set up a reliable control system before you call Keyboard.print(). This sketch includes a pushbutton to toggle the keyboard, so that it only runs after the button is pressed.

Components Required

Arduino Keyboard Example

You will need the following components −

  • 1 × Breadboard
  • 1 × Arduino Leonardo, Micro, or Due board
  • 1 × momentary pushbutton
  • 1 × 10k ohm resistor

Procedure

Follow the circuit diagram and hook up the components on the breadboard as shown in the image given below.

Sketch

Keyboard

Arduino Leonardo Keyboard Enter

Open the Arduino IDE software on your computer. Coding in the Arduino language will control your circuit. Open a new sketch File by clicking New.

Arduino Leonardo Layout

Arduino Code

Code to Note

Attach one terminal of the pushbutton to pin 4 on Arduino. Attach the other pin to 5V. Use the resistor as a pull-down, providing a reference to the ground, by attaching it from pin 4 to the ground.

Arduino Leonardo Keyboard

Once you have programmed your board, unplug the USB cable, open a text editor and put the text cursor in the typing area. Connect the board to your computer through USB again and press the button to write in the document.

Use Arduino As Keyboard

Result

Arduino Leonardo Keyboard Enter

By using any text editor, it will display the text sent via Arduino.