Go Down

Topic: Power on/off computer using Arduino Yun (Read 8458 times) previous topic - next topic

thatkookooguy

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!

Pauly

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

thatkookooguy

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.

thatkookooguy

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

Pauly

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.

ShapeShifter

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.

Quote
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.)

sonnyyu

#6
Aug 07, 2015, 12:48 am Last Edit: Aug 07, 2015, 01:02 am by sonnyyu
At Arduino Yun/compatible:

Install software:
Code: [Select]
opkg update
opkg install etherwake


Power on computer:

Code: [Select]
etherwake -i eth1 00:1d:09:2e:36:93

Wake-on-LAN by Arduino Yun/compatible

Power off computer:

Code: [Select]
shutdown.exe /s /t 00  #Windows Vista, 7, and 8 users

Code: [Select]
shutdown -h now #linux



ShapeShifter

Wake-on-LAN by Arduino Yun/compatible
From that referenced page:

Quote
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?

sonnyyu

#8
Aug 07, 2015, 01:27 am Last Edit: Aug 07, 2015, 01:31 am by sonnyyu
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




jessemonroy650

#9
Aug 07, 2015, 02:36 am Last Edit: Aug 08, 2015, 01:03 am by jessemonroy650
@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

sonnyyu


thatkookooguy

Quote
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.

Quote
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.

Quote
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.

Quote
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.

thatkookooguy

Just for reference:
Quote
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

sonnyyu

#13
Aug 07, 2015, 01:57 pm Last Edit: Aug 07, 2015, 01:59 pm by sonnyyu
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?




thatkookooguy

Quote
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.

Go Up