Power on/off computer using Arduino Yun

Hi All!

I'm trying to connect my Arduino Yun to my PC as a remote power switch.

The idea is that I will be able to connect to my website on the Arduino and power on the computer if it's off or turn it off if it's on.

I'm a web developer, so I think I can handle the programming part of this, but since I have a pretty narrow knowledge on electronics, I'm afraid to damage my PC :-)

I saw this video: https://www.youtube.com/watch?v=UNUiLi_JEH0 And read this answer: http://www.tomshardware.com/forum/278683-28-power-button-work which made me think that the power button on the PC doesn't actually require a relay. If I understand correctly, just closing the circuit gives a signal to the motherboard to turn the computer on or off.

Is there a way to simulate this using the Arduino only? Do I need a relay for this type of setup?

Thanks!

An easy way to do that is plug your computer into a powerswitch tail and leave it on. Then the Arduino turns the tail on and off.

http://www.powerswitchtail.com/Pages/default.aspx

The main problem is that I live in an area with a lot of power shortages.

So every few days my server will shut off (and won't turn back on unless I manually switch it on).

This is a workaround so I'll be able to switch the server back on when abroad or away from home.

If I understand correctly, a powerswitch tail will cut the power to the computer or connect the computer back to power, right?

I prefer that the OS will handle power off in order to let programs save things before switching the computer off.

and if the computer is off, connecting it back to power won't make it power on unless there's an option to make the computer switch on as soon as it connects to a power source.

But again, this is not preferable since it means that on a switch off I'll lose the most recent data of my server.

I want this to resemble a click on the power button as closely as possible

Ok. Sounds like the powertail isn't right for you. Looks more like you want to hack your computer. I probably can't be too much help in that regard, but if someone else jumps in they might want to know what kind of PC you have.

thatkookooguy:
which made me think that the power button on the PC doesn’t actually require a relay. If I understand correctly, just closing the circuit gives a signal to the motherboard to turn the computer on or off.

You shouldn’t need a relay to control the power to the computer, most modern computers already have such a relay built into their power supplies. The power button is usually just a simple momentary contact push button:

  • Give a brief push when the computer is off, and it turns on the internal relay and the computer powers up.
  • Give a brief push when the computer is on, and the operating system detects that, shuts down the computer in an orderly fashion, and then turns off the internal relay to power it down. (This is usually configurable to either shut it down, go to sleep or hibernate, or always prompt you for what you want. You will likely want to set it to always shut down gracefully.)
  • Give a long push when the computer is on, and it turns off the internal relay to power it down. This is not graceful, but can be used when the operating system has crashed or has hung.

Is there a way to simulate this using the Arduino only? Do I need a relay for this type of setup?

You don’t need a relay to do this, it can be done with a transistor. But using a relay is a lot simpler and safer as you don’t have to worry about voltages, polarity, and common grounds. The coil of the relay is controlled by the Arduino (and you will probably need a transistor to drive the relay coil.) Then the normally open contacts of the relay are wired in parallel with the contacts of the power switch. You are essentially doing the same thing as in the video, but you are using the contacts of the relay instead of the pushbutton switch.

Your sketch and website will probably want to be able to generate a short pulse to turn it on or off, or a long pulse to be able to shut down a crashed computer if necessary.

You could also take a USB cable with one end plugged into the computer, and the other end snipped of: connect the +5V wire (usually red) through a 1K resistor to one of the Yun’s digital inputs, and connect the ground wire (usually black) to the Yun’s ground. Leave the data lines disconnected and insulated from each other. This will give you an idea if the server is powered up, and will help you decide if the server is off, or just not being responsive. (You could also hook up the +5V and ground lines from the USB cable to an optoisolater to completely isolate the Yun from the computer.)

At Arduino Yun/compatible:

Install software:

opkg update
opkg install etherwake

Power on computer:

etherwake -i eth1 00:1d:09:2e:36:93

Wake-on-LAN by Arduino Yun/compatible

Power off computer:

shutdown.exe /s /t 00  #Windows Vista, 7, and 8 users
shutdown -h now #linux

sonnyyu: Wake-on-LAN by Arduino Yun/compatible

From that referenced page:

Also, you must allow the system to boot into the OS (windows in my case) and then perform a proper shut down.

if you you just hold the power button down and kill the system or pull the power plug wol would not work

The OP is experiencing power failures, and wants to be able to remotely restart the computer when that happens. Since a power failure is not a graceful shutdown and is equivalent to pulling the power plug, it sounds like WOL may not help him?

ShapeShifter: From that referenced page:

The OP is experiencing power failures, and wants to be able to remotely restart the computer when that happens. Since a power failure is not a graceful shutdown and is equivalent to pulling the power plug, it sounds like WOL may not help him?

At System BIOS set up AC Power Recovery:On, Now box will be auto restart once power back. Some time this setting is well hidden. I sometime found it under security section of BIOS.

The Wol setting is at NIC BIOS.

AC Power Recovery:

  • On
  • Off
  • Last

@thatkookooguy, you can also use an X-10 power switch. http://www.x10.com/x10-home-automation.html

There is more than one maker.

Jesse

Wake-on-LAN by luci-app-wol

|500x394

Also, you must allow the system to boot into the OS (windows in my case) and then perform a proper shut down.

if you you just hold the power button down and kill the system or pull the power plug wol would not work

When I tried to read on the WOL option, it stated that WOL works only if the computer is hibernating or sleeping. I do want to be able to do a full shutdown and startup.

At System BIOS set up AC Power Recovery:On, Now box will be auto restart once power back. Some time this setting is well hidden. I sometime found it under security section of BIOS.

The Wol setting is at NIC BIOS.

AC Power Recovery:

On Off Last

That's great to know! But since this will only fix my problem when the power is cut off, I still prefer a power switch for the other scenarios I mentioned.

You don't need a relay to do this, it can be done with a transistor. But using a relay is a lot simpler and safer as you don't have to worry about voltages, polarity, and common grounds. The coil of the relay is controlled by the Arduino (and you will probably need a transistor to drive the relay coil.) Then the normally open contacts of the relay are wired in parallel with the contacts of the power switch. You are essentially doing the same thing as in the video, but you are using the contacts of the relay instead of the pushbutton switch.

This is great! it's exactly what I was looking for :-)

I'll learn more about this and try to implement this.

You could also take a USB cable with one end plugged into the computer, and the other end snipped of

Also a great idea! I originally thought of creating a startup script to tell me if the computer is on or off but this suggestion is much more straight forward and it makes sense the arduino will do both things (check if computer is on/off and do the actual turn on/turn off.

I think I'll go with ShapeShifter's suggestion since it answers all of my requirements :-)

But thanks everybody who chipped in.

I'll post my progress here in case anyone else will need something similar.

Just for reference:

When a PC is configured to wake on LAN, it MUST continue to have standby power, and network connectivity all the time. If there is a power failure, or a network outage (restarting a switch or router is enough, it acts like disconnecting the network cable from the PC's NIC), then the PC will not respond to magic packets until after being booted into Windows and gracefully shutdown again (as you mentioned you are doing).

This is a well-documented limitation in Wake on LAN. I'm not sure if this is by design, or just something that couldn't be avoided for some reason- but I can repeat the problem on my PCs too.

http://superuser.com/questions/556303/how-reliable-is-wake-on-lan-if-configured-correctly

thatkookooguy: When I tried to read on the WOL option, it stated that WOL works only if the computer is hibernating or sleeping. I do want to be able to do a full shutdown and startup. ...

The huge difference between read and do! It does work fine with full shutdown and startup. Software solution does not cost anything but few minutes. Why not try?

The huge difference between read and do! It does work fine with full shutdown and startup

It doesn't cover all of my needs, so why try it?

It doesn't work if the computer was shutdown incorrectly. which often happens as I stated since there are a lot of power outage.

It will also won't allow me to do anything if the computer froze but didn't shutdown.

I do have my media center which have a WOL feature which I use sometimes and I can say from experience it doesn't always allow me to power it up from afar.

I just didn't try this on my server PC, because of that experience. And I tried to read about WOL to check if something changed since my media center is 2 years old and my server is 3 months old.

But the reason to write here in the forum is to get expert's advise. If you have other information then what I read on powering up using WOL after a bad shutdown you're more than welcome to write it down here and I'll try it.

Plan B:

Base on ShapeShifter’s idea

Wire PS-ON and PS-Ground from PC and connect them to above circuit. (two wires between PC and Arduino)

ATX Power Supply Design Guide

thatkookooguy:
It doesn’t cover all of my needs, so why try it?

It doesn’t work if the computer was shutdown incorrectly. which often happens as I stated since there are a lot of power outage.

It will also won’t allow me to do anything if the computer froze but didn’t shutdown.

I do have my media center which have a WOL feature which I use sometimes and I can say from experience it doesn’t always allow me to power it up from afar.

I just didn’t try this on my server PC, because of that experience. And I tried to read about WOL to check if something changed since my media center is 2 years old and my server is 3 months old.

You keep add new requests, we are not future tellers.

I didn't understand the post with the pictures since there are no explanations on it. Can you elaborate?

and you're right. I tried to explain everything in the original post but after a few comments I understood I didn't so I refined my request. Don't see something wrong with that. But thanks for the criticism. I'll try to be more thorough on my next post.

sonnyyu:

Wired PS-ON and PS-Ground

OK, looks like that’s the way to do it without a relay. Good to know. If you tap into the switch connector as shown in the video you posted, you need to make sure which pin is ground and which is the PS-ON signal, as the polarity is important with this circuit.

If you’re tapping into the power connector as shown, instead of just the switch connector, you could also use any of the +5V signals (red wires) as the power on sense to the Yun instead of the USB cable. You could also use the +5VSB (purple wire) to see if the wall power is available by connecting that to another YUN input. +5VSB is the standby power that is always on when the unit is plugged in, even if the machine is turned off. +5V has power only when the machine is turned on. When using any power source like that as a sense input, it’s a good idea to use a 1K (or a bit larger) series resistor to limit the current draw if something goes wrong (like setting the input pin to be a low output.)

Your post about not understanding the pictures came in just as I was about to hit “Post” for the above data.

The first picture is the ATX power supply connector plugged into the computer’s motherboard.

The next picture shows two commonly used pinouts for that connector, the colors of the wires, and the meaning of the signals. These signals will be interesting to you:

  • Ground - Black - connect to the Yun ground
  • PS-ON - Green - this is the power switch signal, ground it to simulate pushing the switch
  • +5V - Red - this will have 5 volts when the computer is on, can be used to sense that it’s on
  • +5VSB - Purple - this will have 5 volts anytime the computer has wall power, even if the computer isn’t on. Can be used to sense if the AC power is present
    Just don’t hook up to any of the +12V, -12V or -5V lines!

The last picture shows a circuit where the Yun could control the computer’s power switch. ATX Ground goes to one of the black wires, PS-ON goes to the purple wire. When the Yun output (D12 in this diagram) is HIGH, the transistor will be on, and the PS-ON signal will be grounded, simulating pressing the button. When the output is LOW, the PS-ON signal will not be grounded, releasing the push of the button.