USB motion sensor (PIR) to activate monitor

I have an always on net-book for weather forecast (yeah, when paragliding, you need it)
It basically displays a full screen custom web-page with time and date.

Its always on, not really good for the back-light and energy consumption.

So I got the idea of plugging a PIR sensor to wake up the screen when someone approach it.

Take an Arduino Micro Pro (8€ for the Chinese version), a PIR sensor from eBay (2€), a Hammond case (1€) and an USB A male from scrap (0€).

Let’s give a try, with a basic wiring, and this sketch to emulate keyboard thanks to it’s USB HID, the Arduino Micro Pro is a must.

Updated 05-01-2017:

  • code with USB wakeuphost and capslock instead of ctrl
  • green TX led always on
  • orange RX led only on motion
#include <Keyboard.h>

int sensorPin = 10;
int RXLED = 17;  // The RX LED has a defined Arduino pin
static bool sensor_previous_state = false;

void setup()
  pinMode(sensorPin, INPUT);  // PIR sensor pin as input
  pinMode(RXLED, OUTPUT);     //  RX LED as an output
  digitalWrite(RXLED, HIGH);  //  RX LED off
  TXLED0;                     // switch on TX green to show init/powered up (only available by macro)
  sensor_previous_state = digitalRead(sensorPin); // get sensor initial state (can be already true)

void loop()
  bool sensor_current_state = digitalRead(sensorPin);
  if ( sensor_previous_state == false   // looping until we detect a rising edge
       && sensor_current_state == true) {// when sensor state is trigged, it takes about 20 sec to recover
    digitalWrite(RXLED, LOW);   // set the LED on
    USBDevice.wakeupHost(); KEY_CAPS_LOCK );
    Keyboard.release( KEY_CAPS_LOCK );
    TXLED0;                     // great hackery in this: we have to force down the TXLED
    delay(1000);                  // wait a bit for the led
  } else {
    digitalWrite(RXLED, HIGH);    // set the LED off
  sensor_previous_state = sensor_current_state;
2017 update: lightguide for green and orange LEDs:
Update with LED (lightguide from scrap)
And voila!
Quite nice, discrete and works very well, for about 10€/$.

25 thoughts on “USB motion sensor (PIR) to activate monitor

  1. This is really great! What are the wiring schematics though? I want to build this so I want to be sure to get this right. Thanks.

  2. As ive only played with the rpi and uno r3 I had no idea the pro was hid! lol.
    Have you worked out the solution as to stop it pressing ctrl constantly?

  3. This is great stuff. I have used your guide to create my own usb motion sensor. This is to wake my kitchen touchscreen. I have also updated the USBCore.h and script slightly to also support walking the pc when it’s asleep.

    More details on my blog

  4. Hi,
    I notice in your Schematic drawing no additional resistor but there is in the image above it.
    Is the additional Resistor a requirement?

  5. The resistor is optional, but it’s always nice to put one (from 10ohm to 1k), to adapt impedances and limit current.

  6. I’m planning something similar to this, using 4 separate sensors for 4 different keystrokes, but I’m a complete novice. would a single pro micro suffice for all 4 sensors?

  7. Hi. Just want to ask if you can create a micro sensor that beeps or blinks a led llight when someone is approaching or coming near on the sensor about 1 to 2 meters? Please email me if you can create this one. Very Interested.

    Thank you.

  8. Sure, it’s quite easy to make, as a proof of concept, no problem.
    But if you need something, low power, reliable, and you are not an EE, then go to Amazon buy a end product

  9. Hello,
    Do you know any commercial product that does exactly this (emulate keyboard input on motion detection)? I need many of these so doing them is not really an option. Thanks!

  10. Nope, I’m not aware of similar “USB PIR sensor” as commercial product. Otherwise I would have bought one instead of spending 2hours hacking it.

    You can request a design on and find a company such seedstudio to manufacture it.

    If you find one, don’t hesitate to post it here.

  11. Since I happened to have issues with keyboard states, I changed to use mouse movements. If i had no-zero (e.g. 10) mouse movements, they were easy to see in Windows for debugging. I found that mouse movements of zero still trigger Windows. I also toggle the Pro Micro TX LED when motion is detected. Code:

    #include Mouse.h

    int sensorPin = 10;

    void setup()
    pinMode(sensorPin, INPUT);

    void loop()
    if (digitalRead(sensorPin) == 1)
    TXLED1; // Turn on TX LED to indicate movement
    Mouse.move(0, -0);
    TXLED0; // Turn off TX LED

  12. Pingback: Portable soldering fumes extractor fan DIY (battery operated and rechargeable) | DotMana

  13. Sure, but as I previously said, as it’s hand made, it’s rather expensive, are you willing to buy anyway?

  14. hello, Total newbie question here, where do you put the code that you have written above? Do you program the board or does it run on your computer?


  15. For a key to wake you could try using F13, there exist key codes all the way up to F24 but they do nothing so they should be perfect for this.

Leave a Reply

Your email address will not be published. Required fields are marked *