Make £2000 a month risk free!

USB motion sensor to wake Kitchen touchscreen using a Arduino and PIR

Now that I have the touch screen fitted in the Kitchen, I needed a convenient way to wake the tablet. I was hoping that just swiping the screen would wake it up, but unfortunately not.

kitchen3_2.jpg

After a little bit of internet searching, I came across a blog entry on dotmana.com. The site goes through the steps to create a motion detector to wake the screen, using a Arduino and PIR sensor. This was almost perfect, except it would not work when the tablet was sleeping.  

I picked up the bits I needed from Ebay and Amazon, listed below:

A little more searching, I came across this post on Arduino forum.  The post goes into detail on how to update the USBCore.h to enable the HID Keyboard driver, this then supports the 'Allow this device to wake computer' option in Device Manager.  

Once this was done it was just a case of updating the code that monitors the PIR sensor, then send the keyboard command to wake the screen/pc.  Code is from dotmana.com. I just made a change to include the USBDevice.wakeupHost(), so that it will also wake the pc when sleeping. It was nice to play with a little c++.

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);
}

Construction steps below.

kitchen3_1.jpg

Parts all soldered, wired and configured, ready to be assembled

kitchen3_2.jpg

All assembled

kitchen3_3.jpg

Finished unit ready to be installed

kitchen3_4.jpg 

Project complete, now whenever you get close to the tablet it wakes the screen, regardless of whether it's sleeping or not.

#kitchen #homeautomation #coding #arduino

Comments

How do you connect it to your Tablet? The Tablet has a mini USB port but you are showing a standard USB plug




The tablet I'm using runs windows and has 2 USB ports. If you have an android tablet, you could try using an OTG adapter.




Thanks, The OTG worked I just had it plugged in backwards. Now I just need to figure out how to power the table and motion sensor at the same time.

Do you know how many amps the Leonardo can take? E.g. Table power is 5v 2 amps. Would this be too much?




Hmm, not sure. Amazon sells OTG adapters with additional USB lead for power. Could that be worth a try?




I bought all the same components you listed and I noticed that the newest version of IDE appears to have the usbcore.h changes needed for usbwakeup, however i am still doing something wrong because the motion sensor doesnt seem to be actively triggering. i checked my soldering points just to make sure. Is there a way to test it in windows? i opened the virtual keyboard after plugging in the pro micro and the ctrl key does not show as being pressed and my tablet seems to wakeup randomly not by motion.




Sorry not replied sooner, did you get it working?

I would have thought the virtual keyboard would show it its being pressed. Just to be sure, have you tried updating the code to send KEY_TAB instead. Then leave notepad in the foreground and see if it writes the tabs?




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

#include

int sensorPin = 10;

void setup()
{
pinMode(sensorPin, INPUT);
Serial.begin(9600);
}

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




the include statement should have been #include \




@kiwin
Nice idea with the mouse movements, I think I'll do the same. Thanks for sharing your code :)




Hi there

This is my first project so a total coding novice.

I've set up using the hardware described and the original code but am getting a USBDevice was not declared in this scope error

Any ideas?

Thanks




Back to blog