Another newb issue :)

I'm trying to use a nano to create a keystroke when PIR sensor is tripped to turn my monitor on. I've searched and looked and read and have been at it 3 days but cannot seem to get it figured out. Here is the sketch I'm trying to use but I keep getting errors so I can't upload it.

Any help would be great appreciated!! I apologize in advance if I don't post this correctly formatted.

#include <Keyboard.h> 
 
int sensorPin = 10;
void setup()
{
  pinMode(sensorPin, INPUT);
  Serial.begin(9600);
}
void sendWakeUp(void);
void loop()
{
  if (digitalRead(sensorPin) == 1)
  {
    sendWakeUp();
    while (digitalRead(sensorPin) == 1)
    {
      delay(1000);
    }
  }
  delay(1000);
}
void sendWakeUp(void)
{
  USBDevice.wakeupHost();
  Keyboard.press(KEY_LEFT_CTRL);
  delay(1);
  Keyboard.release(KEY_LEFT_CTRL);
}

These are the errors I'm getting. Trying to fix them but have had no luck.

Arduino: 1.8.13 (Windows 10), Board: "Arduino Nano, ATmega328P"

In file included from C:\Users\cowbo\Downloads\F7MIIU0IL4FPFYR\F7MIIU0IL4FPFYR.ino:1:0:

C:\Program Files (x86)\Arduino\libraries\Keyboard\src/Keyboard.h:29:2: warning: #warning "Using legacy HID core (non pluggable)" [-Wcpp]

 #warning "Using legacy HID core (non pluggable)"

  ^~~~~~~

C:\Users\cowbo\Downloads\F7MIIU0IL4FPFYR\F7MIIU0IL4FPFYR.ino: In function 'void sendWakeUp()':

F7MIIU0IL4FPFYR:24:3: error: 'USBDevice' was not declared in this scope

   USBDevice.wakeupHost();

   ^~~~~~~~~

F7MIIU0IL4FPFYR:25:3: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?

   Keyboard.press(KEY_LEFT_CTRL);

   ^~~~~~~~

F7MIIU0IL4FPFYR:25:18: error: 'KEY_LEFT_CTRL' was not declared in this scope

   Keyboard.press(KEY_LEFT_CTRL);

                  ^~~~~~~~~~~~~

exit status 1

'USBDevice' was not declared in this scope

The classic Nano is not compatible with the Keyboard library. That library requires the use of an Arduino board with native USB capabilities such as the Micro, Leonardo, MKR boards, or Nano 33 IoT.

Thank you so much!! Great info. Now I can get what I really need and that'll be that!!

It is a micro clone:

Micro Clone

I now know they won't work :slight_smile: That's okay I'll keep them for other projects. They all work fine so something will come along, it always does! LOL

The link you provided is not a Micro clone; it clearly states Nano :smiley:

1 Like

You want the pro micro which has an atmega32u4 microcontroller. The atmega32u4 is the important part in your case, because it has the integrated USB controller needed for the keyboard library.

sterretje:
The link you provided is not a Micro clone; it clearly states Nano :smiley:

They were probably reading the "Micro-Controller Board" part. :slight_smile:

cowboysdude:
I now know they won't work :slight_smile: That's okay I'll keep them for other projects. They all work fine so something will come along, it always does! LOL

You got that right! I never regret having spare Arduino boards on hand, especially when it comes to the awesome Nano (or its derivatives in this case).

Enjoy! Per

1 Like