6

I'm a bit of a noob in the Arduino area but I found an Arduino nano I bought a long time ago sitting on my shelf and collecting dust, so I taught "why not make a project". I game a lot of racing games so I wanted to make a simple ignition button with it, but every time I tried to compile or verify it, it says

Keyboard not found. Does your sketch include the line #include "Keyboard.h"

Greenonline
3,1527 gold badges36 silver badges48 bronze badges
asked Jun 17, 2017 at 18:33
7
  • 1
    did you include the keyboard library from the Sketch menu? Commented Jun 17, 2017 at 19:12
  • 3
    @dandavis - that would not be possible or at least not meaningful, as there is no such library for a nano. Commented Jun 17, 2017 at 21:39
  • @ChrisStratton: good call. Commented Jun 17, 2017 at 23:27
  • Unlike and official Arduino Uno, which uses a re-programmable ATmega16U2 for an USB to UART interface, a Nano uses an non re-porgrammable FTDI chip. Commented Jun 19, 2017 at 13:44
  • A typical Nano has no hardware support for this - so you could only do it by a means such as software-approximate USB, or by adding a USB device interface chip. As the answer suggests, there are better platform choices. Commented Mar 14, 2018 at 17:01

3 Answers 3

14

Get yourself a Arduino Leonardo, Micro or Pro Micro (or Due, Zero, M0). Those can emulate a keyboard.
Start with reading the Arduino Keyboard Mouse reference.

The Arduino Nano can not use the Arduino Keyboard Mouse library.

Since many years, there is a library called "V-USB" that requires some extra hardware and makes it possible for a ATmega328p microcontroller to act as an USB device. It is not something for a beginner.

A few years ago, Arduino has changed the way the USB is used. The NicoHood HID library makes use of the new possibilities. It makes it possible for example to have extended features for a USB keyboard, like the media keys.

For a normal keyboard and mouse, the Arduino Keyboard Mouse library will do. It will be perfect for a ignition button. But you have to buy one of those boards (Leonardo, and so on).

answered Jun 17, 2017 at 20:10
1
  • 2
    or a teensy board Commented Jun 8, 2020 at 13:09
3

The solution to get a board that has built in USB support is not preferred for someone who just wants to use the boards they already have. It is possible to use a board that can communicate with your computer over serial, such as the Arduino Nano, to send data to a Python program which can then turn the input from the Arduino into keyboard presses, etc. using libraries.

For this approach, you would need to know python. The libraries to use are:

pyserial - communication with Arduino

pynput - control the computer's keyboard

threading (comes with python) - allow pyserial and pynput to work simultaneously

answered Mar 3, 2021 at 13:52
1

You can give Keyboard Input using Arduino Nano, Uno or any other boards by doing these following steps:

  1. Sending the serial data using Serial.println() in the Arduino Script. A Demo script is given below:
#include <Arduino.h>
void setup() {
 Serial.begin(9600); // Start serial communication
}
void loop() {
 int accelerator = analogRead(A0);
 int decelerator = analogRead(A1);
 int x = analogRead(A4);
 int y = analogRead(A5);
 if (accelerator > 15) {
 Serial.println("q"); // Send 'q' over serial
 delay(10);
 }
 if (decelerator > 590) {
 Serial.println("z"); // Send 'z' over serial
 delay(10);
 }
 if (x > 400) {
 Serial.println("i"); // Forward
 delay(250);
 }
 if (x < 290) {
 Serial.println(","); // Backward
 delay(250);
 }
 if (y > 400) {
 Serial.println("j"); // Left
 delay(250);
 }
 if (y < 290) {
 Serial.println("l"); // Right
 delay(250);
 }
}

Then, running the python script below:

import serial
from pynput.keyboard import Controller
keyboard = Controller()
arduino = serial.Serial('/dev/ttyUSB0', 9600) # Change this to match your Arduino's port
while True:
 data = arduino.readline().decode().strip()
 if data:
 keyboard.press(data)
 keyboard.release(data)

Here, change this '/dev/ttyUSB0' according to the port you're using the Arduino board.

answered Feb 24 at 8:56
1
  • 1
    Sounds like chatgpt! You do realise tgat chatgpt steals orher peoples work and does not give them credit. Plus its wrong way too often. Commented Feb 24 at 10:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.