gracefully shutdown a windows computer with arduino

Hi All,

As a lover of old arcade games and pinball, I have started building my own virtual pinball machine (if you want to know more you can check my blog). And for this project I have a question:

I want to use an arduino to switch on and off a PC that is inside the pinball machine. I plan to hookup a flipperbutton to an arduino and have it trigger an interrupt which switches the pc on. That I can work out.

However, if the machine is left alone for several minutes I want it to power down automatically, so when the flipperbutton is touched, I plan to set a timer for , say, 5 minutes. When the timer counts down to zero, it should shutdown windows and via a smartstrip the rest of the electonics in the cabinet is powered off also.

I wonder if this graceful shutdown is possible by using an Arduino? What would be a good and safe way to do this? Hookup the pc-power switch to the arduino? Or have it act as a keyboard and "press" the right keys or give it some sort of special command via usb? I do not want to just cut the power to it, as it will cause windows to be messed up on the next startup.

I have thought about these concepts, but am not sure where to start, nor do I want to break the PC.

Is this feasible or is this not something to do with an Arduino?

What OS is the PC running? If it's windows, I'd think that having the PC shut itself down would be a much better idea.

it is indeed running windows, PaulS. But, I am not sure what you mean having the PC shutting itself down? Like instead of going to a screensaver, shutting down?

Like instead of going to a screensaver, shutting down?

Yes. Windows has lots of options for what to do when the idle time limit has been exceeded, including shutting itself down. It properly ends all applications, services, etc. so the shutdown is achieved in a way that restarts don't cause the OS to have a conniption fit restarting Windows.

You could have the Arduino monitor the PC status, and shut the other stuff down when it detects that the PC has shut down.

Ah thanks for that idea. Simpler is better and I simply had not thought about this direction :slight_smile: I think I will give this a try! However monitoring the PC's status still brings up similar questions: what is the safest/most reliable way to do that? Detect something over USB? Hookup a part of the PC to an input pin on the arduino (or would that fry the arduino or pc?)

Hookup a part of the PC to an input pin on the arduino (or would that fry the arduino or pc?)

If the PC has a power light, I presume that that goes out when it shuts down. An LDR positioned so that it saw the PC light only (inside a small, black tube, closed at the LDR end; open at the LED end) would let the Arduino determine when the PC shut down, with no physical connection required.

You haven't explained how the Arduino and the PC work together in this solution, but I guess you're using the Arduino to interface with controller hardware and an application on the PC to manage the game logic and drive the display and so on.

Having the PC shut itself down after an idle period is very easy with any modern version of Windows. I suggest that rather than doing a full shutdown you use the standard policy to quiesce the hard drives and then send the PC to sleep. This means you can wake the PC from the keyboard (i.e. using an Arduino emulating a keyboard) rather than splicing into power buttons, and means it will wake up much quicker (usually fractions of a second) and with your applications all running and initialised. And this means you can just plug your Arduino-based controller into any PC for testing without needing any hardware hackery.

I'm not sure whether or why the Arduino would care whether the PC was awake, but if it does need to know then I would have thought that a simple handshake over the serial port would tell you. There's one part of this solution which I'm not clear about - when the Arduino is emulating a keyboard HID, can it also support the normal serial port comms with the host PC? Presumably anyone who's used the HID emulation would know, but I haven't.

All PC power supplies (for the last 10 years at least) have two leads that go to the momentary power switch. If you close that circuit momentarily Windows will do whatever is policy to do when that button is pushed. So set the off button to put the PC to sleep. It should even sleep if there are programs that would ordinarily balk at being shut down (due to unsaved data, etc.). No software needed on the PC for this route. Just a reed relay or something to momentary close that line when you want the computer to sleep or wake.

Power_options.png

ah thanks people, it seems there are quite a few options. I think I will have to experiment a bit to see what works best.

@Peter: The arduino does not work together with the PC really. It is only used to switch it on. The PC will run pinball emulation software with 2 screens (one for playfield, one for backglass) and a Dot Matrix Display. Together with several buttons hooked up to a keyboard encoder (and some additional electronics) to act as inputs.

So the Arduino is only really used to detect a button press and switch the whole thing on. If you want to know more about these builds, you can check my progress or better yet, the "HyperPin Cabinet Forum". Its really fun :slight_smile:

aetjansen:
the Arduino is only really used to detect a button press and switch the whole thing on

I assume you see now that you could correct the button directly to the PC, if you wanted, and cut out the Arduino altogether.

yes I do, but the button is used as a flipper button when the pc and software are running, so I will have to make sure that the button press does not lead to any shutdown action in windows, not when pressed briefly, or when being held for several seconds, but I guess that can all be configured in windows xp itself.

Windows XP provides an interface for a uninterpretable power supply shut down via a com port.

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/pwrmn_ups_configure_ups.mspx?mfr=true

You could configure windows to look on the arduino com port, and emulate the APC smart protocol

http://www.networkupstools.org/ups-protocols/apcsmart.html