- Arduino Tutorial
- Arduino Function Libraries
- Arduino Advanced
- Arduino Projects
- Arduino Sensors
- Motor Control
- Arduino And Sound
- Arduino Useful Resources
First to include built-in USB. The inbuilt USB 2.0 communication is what makes it different from other Arduino boards. With this, the Leonardo is able to directly communicate with your PC via just USB, allowing for it to behave like a mouse or a keyboard. Uploading: You need to be in the arduino IDE ready to upload the code, hold the reset button on the Leonardo, as soon as you press it press CTRL + U to upload the new code, as soon as it says uploading in the bottom of the IDE release the reset button on the Leonardo and hope that you got the timing right. If you got the timing right it will upload and display the Done uploading message, if you got it wrong you. The Leonardo board is equivalent to a standard HID (Human Interface Device Class) USB keyboard. Project level: Easy Difficult. Prerequisites: A computer with Arduino IDE version 1.6 or higher installed. An Arduino board with HID USB keyboard support is required. Some hardware components and tools. (Described in next chapters).
- 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.
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
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
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
Arduino Leonardo Keyboard 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.
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.
Result
Arduino Leonardo Button Box
By using any text editor, it will display the text sent via Arduino.