Automatic Shutdown of Windows 7 PC After Powercut

Hello,

I have recently built and installed a UPS for my PC that seamlessly switches to inverter power once a power-cut occurs. The problem is that once the batteries run out, my computer dies as usual.

Firstly I need the Arduino to recognize when grid power is off, from then on it should safely shutdown my PC. I am thinking of using a "Genuino Uno" and a simple 240V AC to 5V DC converter that will act as a signal to the Arduino that grid power is still on. I will power the Arduino from a separate power source.

My question is if the Arduino alone is able to monitor a loss of 5V DC power or do I need some sort of sensor component? Otherwise I've seen a "Non-invasive AC current sensor" (https://store.arduino.cc/product/E000020) that is able to monitor current, and therefor I would safely be able to clamp it around my PC's live wire, right?

Finally, Is it possible to shutdown a Windows 7 PC automatically once loss of power is achieved? If so, How?

Thank you, Since I am new to the Arduino and this forum, all help is appreciated! :)

~Alexander

What you are describing is a basic function of a UPS. It comes with companion software for the PC and shuts the PC down gracefully when the UPS is unable to continue to power the PC. Even if you build something yourself, you are still faced with the problem of shutting the PC down in such a way that there is no corruption/loss of data. Here is an example: http://www.howtogeek.com/183102/how-to-gracefully-shutdown-your-pc-with-a-ups-unit-and-why-you-should/

Given that you’ve built the UPS yourself I guess there’s no accompanying software? That’s what you need to build next then.

The Arduino can run off a very small rechargeable li-ion battery 3.7v - a UNO will require a step up booster to 5v (costs all of about $2) but a Pro Micro style (eg Leonardo) will require a small voltage dropper (step-down).

The latter is eminently suitable because you can leverage the fact that it connect to your Windows PC as a keyboard (HID - Human Interface Device) - all automatically.

I do this for my video recordings and am currently using a Leonardo clone to experiment with - it sends the required keystrokes back to my PC and ‘does stuff’ - which could include shutting down my PC. Basically the Leonardo emulates both a keyboard and mouse (whatever you require).

It would simply monitor the voltage going into the voltage step-up/step down and take the appropriate action after the require delay if there was a power outage.

alexanderstroborg: Hello,

I have recently built and installed a UPS for my PC that seamlessly switches to inverter power once a power-cut occurs. The problem is that once the batteries run out, my computer dies as usual.

Firstly I need the Arduino to recognize when grid power is off, from then on it should safely shutdown my PC. I am thinking of using a "Genuino Uno" and a simple 240V AC to 5V DC converter that will act as a signal to the Arduino that grid power is still on. I will power the Arduino from a separate power source.

My question is if the Arduino alone is able to monitor a loss of 5V DC power or do I need some sort of sensor component? Otherwise I've seen a "Non-invasive AC current sensor" (https://store.arduino.cc/product/E000020) that is able to monitor current, and therefor I would safely be able to clamp it around my PC's live wire, right?

Finally, Is it possible to shutdown a Windows 7 PC automatically once loss of power is achieved? If so, How?

Thank you, Since I am new to the Arduino and this forum, all help is appreciated! :)

Hey! I actually built the very first USB UPS on the market! It was very many years ago, so hopefully my info isn't dated.

Windows does have native power management that you can interface to if you follow the Power Device Spec (which I helped write) -> http://www.usb.org/developers/docs/devclass_docs/pdcv10.pdf. This means you can't use the Uno or any Arduinos that use a USB Serial Converter. I'm not sure how much effort it would take to make a direct USB Arduino like the Leonardo operate as a power device.

BTW - to enable the native power management in Windows 7, plug in your UPS and then go to "Hardware and Sound"->"Power Options"->"Edit Plan Settings"->"Change advanced power settings"->"Battery"->"Critical battery action"->"Shut Down". When I was doing this for a living in the 90s, Apple and Windows native power management both supported UPS shutdown with some sort of file saving. Linux had something that one of our employees did in his spare time, but I didn't work with it. I remember Windows not saving data for much more than Microsoft products, which might not even be relevant today since Office seems to always have a copy of my lost work even if the PC crashes.

Following the Power Device Spec is a little easier said than done, as it is large and only a few of the usages are used by the OS's native power management. You might be able to guess from the names in the Advanced Power Options which need to be supported. Otherwise you could check which usages another UPS used that works with Windows and implement the same HID Report Descriptor they did.

As far as detecting the power failure, you ask if you "need some sort of sensor component" but then you say that you already have a UPS that "seamlessly switches to inverter power once a power-cut occurs." How are you sensing the power failure now?

I appreciate the hasty feedback! :)

I might have been a little unclear, I own a desktop PC that feeds of an inverter that only uses battery power once grid power is turned off (power-cut). Additionally it is completely homemade so there is no compatible software, just pure, battery powered AC current from an inverter. The inverter is able to switch to battery power seamlessly and only feeds 4 wall plugs, for monitor, printer, computer etc. So my plan is to take advantage of a wall socket that is still on the grid, so if a power-cut occurs the 240V AC to 5V DC converter will stop supplying voltage (keep in mind this does not refer to the power supply of the Arduino), my aim is for the Arduino to notice this cutoff in power and execute a shutdown.

In theory it would be a voltmeter measuring the 5V supply.

Turning it into a keyboard like Leonardo said was a great idea, but can anyone give me some guidance to how to create a simple voltmeter and from then on be able to execute a keyboard press that is recognized by the computer. A good first step would be to monitor if voltage is present or not on my computer, from then on maybe have it type a ASCII letter once a loss of power occurs. Like once I unplug the AC to DC converter from the socket, something will be typed into my computer.

Thanks again,

~Alexander

alexanderstroborg:
I might have been a little unclear, I own a desktop PC that feeds of an inverter that only uses battery power once grid power is turned off (power-cut). Additionally it is completely homemade so there is no compatible software, just pure, battery powered AC current from an inverter. The inverter is able to switch to battery power seamlessly and only feeds 4 wall plugs, for monitor, printer, computer etc. So my plan is to take advantage of a wall socket that is still on the grid, so if a power-cut occurs the 240V AC to 5V DC converter will stop supplying voltage (keep in mind this does not refer to the power supply of the Arduino), my aim is for the Arduino to notice this cutoff in power and execute a shutdown.

In theory it would be a voltmeter measuring the 5V supply.

Hmm, ok. I would be interested in seeing a block diagram of your homemade inverter that only uses battery power once grid power is turned off (aka a UPS). If you can trust that your inverter will take care of powering the load through the blackout, then yes: you could use a 240VAC to 5V DC converter to detect the power outage.

You should put enough resistance on the converter so that your 5V is stable and that it doesn’t hold up too long after the AC is cut. You could then just read the 5V as a digital input with the Arduino.

The idea of mimicking a keyboard is cute. I’m not sure if you could find a string of keyboard characters that would reliably shut down the PC, however. Even if you Alt-F4 over and over again some programs will first open a dialog about saving your work, and others might open a second dialog about a filename. If you have a command prompt window open, it won’t close at all. It’d be fun to try to make, however.

Thank you, DigitalRead is the exact function I was looking for. ~Alex