Power on/shutdown pc with Leonardo

HI all,
my project is to power on/shutdown my pc using the TV remote control.
The power off operation is easy to perform with Leonardo, simulating the sequence of keys in order to press the shutdown button.
The problem is the power on operation: I set my pc to power on when a USB keyboard's key is pressed, but when I simulate the press of a key nothing happens
I tried also to wakeup my pc with the mouse click, but with same results. :frowning:

Any suggestion?
Thanks in advance.
Raizen

You need to make sure that in your computers bios you can turn your pc on from keyboard, thats usually off by default.

Does it work with a normal keyboard?

Yes of course it works, also with mouse and a PS2 Keyboard...

Well then, i'd suggest posting your code, because if you've isolated the PC as a problem, then it has to be your code.

Here the code:

#include <IRremote.h>

int RECV_PIN = 11;
int num_off=0;
int num_on=0;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{ 
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {

//Power OFF
    if(results.value==0xE0E0F10E)  
      num_off++;
    if(num_off>20){  //If I receive at least 20 0xE0E0F10E I shutdown my pc
      
      num_off=0;
      Keyboard.begin();
      // CTRL-ALT-DEL:
      Keyboard.press(KEY_LEFT_CTRL);
      Keyboard.press(KEY_LEFT_ALT);
      Keyboard.press(KEY_DELETE);
      delay(100);
      Keyboard.releaseAll();
      //ALT-s:
      delay(1000);
      Keyboard.press(KEY_LEFT_ALT);
      Keyboard.write('s');
      //ALT-a:
      Keyboard.write('a');
      delay(100);
      Keyboard.release(KEY_LEFT_ALT);
      Keyboard.end();
    }
    
//Power ON
    if(results.value==0xE0E0926D)
      num_on++;
    if(num_on>20){ //If I receive at least 20 0xE0E0926D I power on pc pressing a key
      num_on=0;
      Keyboard.begin();
      Keyboard.press(KEY_LEFT_CTRL);
      delay(100);
      Keyboard.release(KEY_LEFT_CTRL);
      Keyboard.end();
    }

    irrecv.resume(); // Receive the next value
  }
}

You could use the motherboard connector for the on/off switch and control it by a relay. That would be quite simple to acheive

Thanks for the advice, but I prefer a software solution...also because I can use this system on a laptop (relay solution is not achievable)....

I would change the delay from 100 to 1000. 100ms might not be slow enough.

Also, does the keyboard wake up the pc when you press those same two buttons?

I tried to change the key pressure to 1 sec, but it had no effect =(

Someone who has Leonardo can try if he can power on the PC simulating a button pressure? In this way I can understand if it's a arduino problem or it's a my pc problem....

Thanks for help :slight_smile: