This project will show how can you use an USB enabled Arduino as a USB Keyboard.
I will not explain how it works from the silicon. That will be a book one it self.
Like Arduino micro, Arduino Leonardo etc.
You can make an entire keyboard if you want.
2. 4 Push Buttons
3. Some wires
1. Setup the circuit as shown in the diagram above with the breadboard wires.
3. Click the Upload button to send this code to your Arduino.
4. Wait for to upload to finished then reconnect the Arduino by unplugging the USB cable and re-plugging.
5. Now open "Notepad" app in your PC/MAC.
6. Push one of those button, you will see the character in the app.
Here you can see when i press tthe buttons it sends the character to the PC.
This one will send 'A', 'B', 'C', 'D' character to PC/Mac.
This one will send Up, Down, Left, Right command to PC/Mac. You can try this in a game or website.
2. You can also use other spacial keys from this list here.
3. You can make a custom Keyboard to suit your needs. Like Video editing or Photoshop shorcuts in a keyboard.
2. Select the proper board from the "Tools">> "Boards" . Or you will get error when you tried to build the code.
3. It will register/handles one button at a time. Because the code dose not supports multi pal registering key. Means if you press all of those buttons at a time it will not send all of those one time.
4. Make sure there is no loose connection and Use a good USB cable.
Thanks.
I will not explain how it works from the silicon. That will be a book one it self.
So What is "USB enabled Arduino" ?
Not all Arduino can act as a USB Keyboard. Usually those board has Atmel-Mega32U4 MicroControlar can act as one. Those chip have HID support.Like Arduino micro, Arduino Leonardo etc.
You can make an entire keyboard if you want.
What you need?
1. Arduino Micro/ Leonardo.2. 4 Push Buttons
3. Some wires
Schematics
Wire up your parts according to the diagram And connect the Arduino to your PC/Mac.Code
This is a simple code that will send some English character to a computer.1. Setup the circuit as shown in the diagram above with the breadboard wires.
2. Now Plug the Arduino to your PC/Mac with USB cable.
3. Click the Upload button to send this code to your Arduino.
4. Wait for to upload to finished then reconnect the Arduino by unplugging the USB cable and re-plugging.
5. Now open "Notepad" app in your PC/MAC.
6. Push one of those button, you will see the character in the app.
Here you can see when i press tthe buttons it sends the character to the PC.
This one will send 'A', 'B', 'C', 'D' character to PC/Mac.
#include <Keyboard.h> // This is a "built-in" library so no need to install from outside void setup() { pinMode(2,INPUT_PULLUP); // sets pin 3 to input pinMode(3,INPUT_PULLUP); // sets pin 4 to input pinMode(5,INPUT_PULLUP); // sets pin 3 to input pinMode(6,INPUT_PULLUP); // sets pin 4 to input } void loop() { Keyboard.begin(); //First begin keyboard if (digitalRead(2) == 0 ) // if buton 2 is pushed { Keyboard.write('A'); // send single character "A" delay(200); // delay to don't get 5 A's } if (digitalRead(3) == 0 ) // if buton 3 is pushed { Keyboard.write('B'); // send single character "B" delay(200); // delay to don't get 5 B's } if (digitalRead(5) == 0 ) // if buton 5 is pushed { Keyboard.write('C'); // send single character "C" delay(200); // delay to don't get 5 C's } if (digitalRead(6) == 0 ) // if buton 6 is pushed { Keyboard.write('D'); // send single character "D" delay(200); // delay to don't get 5 D's } Keyboard.end(); // stops keybord }
This one will send Up, Down, Left, Right command to PC/Mac. You can try this in a game or website.
#include <Keyboard.h> // This is a "built-in" library so no need to install from outside void setup() { pinMode(2,INPUT_PULLUP); // sets pin 3 to input pinMode(3,INPUT_PULLUP); // sets pin 4 to input pinMode(5,INPUT_PULLUP); // sets pin 3 to input pinMode(6,INPUT_PULLUP); // sets pin 4 to input } void loop() { Keyboard.begin(); //First begin keyboard if (digitalRead(2) == 0 ) // if buton 2 is pushed { Keyboard.write(KEY_UP_ARROW); delay(200); } if (digitalRead(3) == 0 ) // if buton 3 is pushed { Keyboard.write(KEY_DOWN_ARROW); delay(200); } if (digitalRead(5) == 0 ) // if buton 5 is pushed { Keyboard.write(KEY_LEFT_ARROW); delay(200); } if (digitalRead(6) == 0 ) // if buton 6 is pushed { Keyboard.write(KEY_RIGHT_ARROW); delay(200); } Keyboard.end(); // stops keybord }
Conclusion
1. You can send any character you want in this list from 1st to 128th. Other can't because the keyboard library dose not supports others.2. You can also use other spacial keys from this list here.
3. You can make a custom Keyboard to suit your needs. Like Video editing or Photoshop shorcuts in a keyboard.
N.T.
1. Download the library first from "Tools">> "Manage Libraries..">> "Keyboard Buit-In by Arduino ">> Click the install.2. Select the proper board from the "Tools">> "Boards" . Or you will get error when you tried to build the code.
3. It will register/handles one button at a time. Because the code dose not supports multi pal registering key. Means if you press all of those buttons at a time it will not send all of those one time.
4. Make sure there is no loose connection and Use a good USB cable.
Thanks.