Best way to detect when PC is being powered on/off by Arduino?

Hey gang-

I was asked to help make an Arduino based project that controls some servos for a PC case mod (for opening/closing some fan grills...and some other things)

I have all the Arduino/servo stuff handled pretty good...

but I have a question about one of the requested features.

closing the fan grills when the computer is turned off.

I asked how would that happen when there is no power?

Response was, that there is a standby +5v power source that is 'always on'..

and/or the USB (3.0) ports on the motherboard....

if this is true/correct.. then this is how the Arduino will be powered, and will always have power even when the machine is powered down... great.

However.. I still need a way to 'detect' when the PC is being powered on and off.. so I can start the servo behavior.

I believe most/all PC PSU's run at 12v?..

which is off course way to high to connect directly to the Arduino in any fashion.

I am looking for suggestions on how to detect when the PC is being powered on and being powered off..

when either of those behaviors is detected, I then wait for my programmed delay and then open/close the servos to the designated angle and speed.

I'm not into PC case mod stuff much.. anyone have any ideas to walk through?

thanks!

Every PC indeed has a standby 5v. And on most modern motherboard it’s connected to the USB ports (or at least some and/or selectable). So indeed, power isn’t the problem.

And a PC has multiple power rail. 12v but also 5v and 3,3v. So just connect a 5v rail to an input pin and you are done. And if you are really good, connect it to an interrupt pin and bring the Arduino to sleep after it closes the grills after power down.

The multiple rails you mention.. the +5v & +3.3v arent 'on' all the time are they? Like the +5v standby line that is always on I was told (even after shutdown?)

I have never put an Arduino 'to sleep' (stand by mode) before...

but it wont be fun if there isnt something new to learn/add right? :)

thanks for the reply.

I think you can directly connect an arduino input to the green wire (pin 14) of the big ATX connector. If you read a LOW mean the PSU is on.

Is the 'green wire' (pin 14) the same on all PSU's?

is this a +5v or +3.3v line?

LOW is on?

I need to see if I have an older one in my basement or something.. not sure if they have changed much over the years?

Thanks...

xl97: Is the 'green wire' (pin 14) the same on all PSU's?

is this a +5v or +3.3v line?

LOW is on?

I need to see if I have an older one in my basement or something.. not sure if they have changed much over the years?

Thanks...

I have another idea, you could just use a hall effect sensor around the PC power cable and connect the sensor to Arduino.

It's the "PS_ON" pin:

You can indeed use the PS_ON wire but why would you do that? That means splicing the big ATX the access the wire. The 5v rail is available on every molex connector (the one used to power DVD-drives etc).

xl97: The multiple rails you mention.. the +5v & +3.3v arent 'on' all the time are they? Like the +5v standby line that is always on I was told (even after shutdown?)

Think about it, would that make sens? To have a standby 5V rail but don't power off the other lines? No ;) So yes, all the other lines or off when the PC is off. Actually, it's the way a PC turns itself off by turning all the power off. The 5V standby is the only line that still has power after power down and is used for the motherboard to detect someone pressing the power button (otherwise, how can it now when to turn on...) and on most PC's to power (some) USB ports (to charge mobiles etc). 5V standby is only turned off if you turn off the big switch on the back of the PSU (and everything is off).

So the most non non destructive way is to give the Arduino power by plugging it into a always on USB port of the motherboard and use a molex plug to detect when the PC is turned on.

xl97: but it wont be fun if there isnt something new to learn/add right? :)

Indeed, it's not that hard ;)

The ATX specification provides for 5V standby power, and IIRC it has to be capable of 2.5 amps. It will be a purple wire, and there is only one coming out of the supply. Any 5V line (red wire) can be checked to see if the supply is running.

If you want to sense when the PC is starting up, or even have the Arduino control startup/shutdown you could use the header at the bottom of the motherboard, where the front panel switches/ports connect. It will have labels like "PWR ON", "RESET", "HDD LED" etc. Pulling the "PWR ON" pin low momentarily will cause the PC to boot up, that's what the front panel power button does, or if it's running pulling the pin low again will send a shutdown signal to the OS. You can do the same with the "RESET" pin or even monitor the "HDD LED" pin to sense HD activity. You can't tell if the power supply (PC) is on from those pins since they are fed by the standby power line and always have 5V if the supply has mains power.

So you could route the power switch wires to the Arduino and have it start/shutdown the PC. When someone presses the power on button on the PC's front panel the Arduino could open louvers, ring a bell, or take some other action first and then pull the "PWR ON" pin low to actually start the PC. Likewise it could shut down the PC first, and then close the louvers after the PC is "off".

You really need to define just what state the pc is in when "powered on" and "powered off". Seems to be confusion between the main power supply being being shut down and the pc just in a sleep/hibernation state.

I dont want anything done (or am interested in) in sleep mode of the PC. (at least you brought it up!) lol

I dont wanna crack my own PC open and start muking about with the PSU.. and I dont have an extra PSU to fiddle with either... so I relied on some info about there be a constant +5v line when the computer is shut down.

(septillion above also mirrors this, and gives a good idea to use a molex connector to detect when the PC is on or off)..

that being said you bring up a neat idea for an additional feature...to be able to control the servos when sleep or hibernation mode as well.. is there a difference? or a specific wire to use then?


some questions for clarity:

  • There is always a constant +5v ("standby") source .....correct?

  • what line is this on the PSU pinout chart above? (The purple +5VSB line?)

  • connecting to the motherboard USB is done through the header pins then? (and this stays constantly on?

I dont recall having my computer OFF and being able to use a USB port to power anything for example?)

  • The rest of the +12v, +5v and +3.3v rails turn off/go dead.. when the machine is powered down

  • do they stay 'on' when the machine is sleep mode?

  • Powering ON/OFF vs Sleep Mode ON/OFF

  • how can I tell or what wires in the above pinout diagram are to/can be used for checking when the PC is powered on or off? (Any of the remaining +5v/+3.3v rails....correct? doesnt matter?) And what is the difference between using one of these +5/+3.3v rails to check when the machine is off or on, vs the PC_ON (green) wire?

  • how then, can I tell or what wires should be used when the PC is in sleep mode?

Thanks for the guidance!

Can you edit you're post and remove all the blank lines at the end?

xl97: (septillion above also mirrors this, and gives a good idea to use a molex connector to detect when the PC is on or off)..

Yep, it's a non destructive way.

xl97: when sleep or hibernation mode as well.. is there a difference? or a specific wire to use then?

In sleep the system is brought into a state of low lower but not powered down. So the PSU (and all power rails) stay powered on (fans keep on spinning as well). In Hibernate the system state is written onto the hard drive and the system is powered down (PSU powers down except 5V stand by) so it just looks like a power down.

xl97: * There is always a constant +5v ("standby") source .....correct?

Yes

xl97: - what line is this on the PSU pinout chart above? (The purple +5VSB line?)

Yes

xl97: - connecting to the motherboard USB is done through the header pins then? (and this stays constantly on?

I dont recall having my computer OFF and being able to use a USB port to power anything for example?)

You can indeed use the header. You have to loop in the manual for which one stays powered on. And on some (like mine) I can set it in the BIOS for some USB-ports. But on modern motherboards there's almost curtain a USB-port that can be configured this way.

xl97: * The rest of the +12v, +5v and +3.3v rails turn off/go dead.. when the machine is powered down - do they stay 'on' when the machine is sleep mode?

Shut down or hibernate => go off. Sleep or stand by => stay powered on

xl97: - how can I tell or what wires in the above pinout diagram are to/can be used for checking when the PC is powered on or off? (Any of the remaining +5v/+3.3v rails....correct? doesnt matter?) And what is the difference between using one of these +5/+3.3v rails to check when the machine is off or on, vs the PC_ON (green) wire?

All power rail wires can be used but if the Arduino runs on 5V is would make sens to use the 5V rail. The PC_ON line is the line that's pulled LOW by the motherboard to tell the PSU to turn on. You can use it but you would have to modify the ATX connector.

xl97: - how then, can I tell or what wires should be used when the PC is in sleep mode?

Sleep is a bit hard because everything stays powered on. But on most (don't know if it's all, don't use sleep...) the power LED is flashing slow instead of being on. If you want you can check this but it's a bit harder. (If the power LED is blue it's possible because you have 3V but with a green LED you can't because 2V is to low for the Arduino. You can connect the POWER_LED line only to the Arduino and let the Arduno power the LED via a resistor though.) But I don't think that necessary because all the fans are powered on in sleep.

Hi, Do you have a program running on the PC that is in comms with the Arduino.

What I am thinking is you have a program in say Processing language that boots when the PC is ON, it sends a command to the Arduino every say 5 seconds, that lets the Arduino know that the PC is ON. If the Arduino does not get any command, then it assumes the PC is OFF and proceeds to do its shutdown procedure.

I'd say it will work with any PC and you don't have to hack into its hardware. The PC program would be very small.

Tom..... :)

septillion:
In sleep the system is brought into a state of low lower but not powered down. So the PSU (and all power rails) stay powered on (fans keep on spinning as well). In Hibernate the system state is written onto the hard drive and the system is powered down (PSU powers down except 5V stand by) so it just looks like a power down.

Sorry, wrong.

In sleep mode, the main power supply is shut off - and all fans are off.

The 5V standby supply powers the LAN card, USB ports and keyboard to enable waking, and powers RAM refresh. These functions account for slightly more power than in shut-down - though all bar the RAM refresh may also be enabled in shut-down anyway for full start from keyboard or LAN. (Alarm time wakeup OTOH costs nothing.)

You arguably could detect this mode by monitoring flashing of the power LED - though I have one late-model computer here which does not do this in sleep mode (it is just - off).

My PC has a "sleep mode" light that turns on when it is asleep. All the lights turn off(network, HD active, battery level, and plugged in) when it hibernates or shuts down.

All great info guys!!

THANKS!

I’m pretty solid on:

  • the powering of the Arduino
  • detecting when the PC has been turned on or off

And now, from what I gather,… (which was just a new idea since it was brought up)… the sleep/hibernation mode is really a motherboard/case dependent type of deal…

(which makes it a bit harder to create a one size fits all type of device in the end)

but was still an idea that was brought up that I felt was valid enough to explore/ask about.

Thanks again every one! (now if only my USB Host keyboard thread got this type of attention!) :slight_smile:

USB Host Shield 2.0 Library question(s)

Paul_B, you are right for Windows & and up). It's been ages since I used Sleep (I don't find it very usefull...) but I'm pretty sure in XP and below power wasn't turned off. (Because the current Sleep is a hybrid sleep mode and XP it wasn't.) But it can also be a motherboard dependency and modern motherboard can just do it with the 5Vsb, not sure.

And yeay, the sleep and hibernate all depends on the motherboard... But as I said, I don't use sleep of hibernate. Used hibernate but find a fresh restarts works better every day.

Sleep - is sleep - has nothing to do with the OS; it is a control on the motherboard which switches off all the main power but feeds "standby" power to the RAM refresh. It has been present since Windoze 2000. WIn7 has a "hybrid sleep" option which performs the hibernation save to hiberfil.sys as a backup in case power is lost in sleep mode.

Laptops have different power controllers, but perform the same functions. Hibernation is a problem as it takes so long to shut down.

septillion: But as I said, I don't use sleep or hibernate. Used hibernate but find a fresh restarts works better every day.

I use sleep all the time, but my consulting room PC has developed some sort of "zombie" problem. If I put it to sleep, the ACPI goes mad shortly after and winds the fans up to full blast (worried my secretary no end, thought it was preparing for take-off!) and would not revive; had to be killed.

Even stranger, when I turn it off - as I have to since it will not sleep - it waits about three seconds and turns itself back on! I have to hold the power button to finally kill it.

Windoze, unlike Linux for the most part, has faulty garbage collection and needs to be periodically closed fully. Successive versions have improved, but never quite got it right. :roll_eyes:

xl97:
All great info guys!!

THANKS!

I’m pretty solid on:

  • the powering of the Arduino
  • detecting when the PC has been turned on or off

And now, from what I gather,… (which was just a new idea since it was brought up)… the sleep/hibernation mode is really a motherboard/case dependent type of deal…

(which makes it a bit harder to create a one size fits all type of device in the end)

but was still an idea that was brought up that I felt was valid enough to explore/ask about.

Thanks again every one! (now if only my USB Host keyboard thread got this type of attention!) :slight_smile:

USB Host Shield 2.0 Library question(s)

Hy xl97 can you gave your code sample?

im doing similar project for my pc.

Thanks…

Wow!

Nearly five yeas ago.

The PC that was giving me the trouble has long gone! I can’t even recall which one it was!

Windoze 10 is however, a menace! Fails to initialise the network interface about half the time when waking from (hybrid) sleep. Windoze 7 used to just - work!

Windoze 10 also crashes on updates on machines with WiFi! Had to remove the WiFi cards to install it to start with.