Arduino Controlled Pc Power Switch

66,805

53

17

Introduction: Arduino Controlled Pc Power Switch

this project is the first step in an advanced pc power switch.
this first installment will show you how to power your arduino from your computers power supply even when your computer is off.
and take control of the computers power switch using your arduino.
After this there are many different things you can do to activate your pc 


Supplies you will need:
an arduino, any will do!
and jumper wires (two f-f and one f-m)

Tools:
phillips head screw driver (to open your computer case)




Step 1: Powering the Arduino

now obviously we cant get power from the usb port when the pc is off!

you will be tapping into the +5v standby pin on your computers power supply.
the easiest way to do this is simply to take the male end of your female to male jumper wire (or any wire) and stick it down the back of the connector and secure it there.
this is a constant 5v source when the pc is off and on.
then you just run that wire to the 5v pin on your arduino. dont use vin unless you have a 3.3v board (like my pro mini).
the ground can come from anywhere be it the 24 pin atx connector, a hard drive connector, or like what i did an unused usb header.

Step 2: The Other Connection.

there will be two wires from your power switch to your motherboard.
unplug them both and connect your jumper wire to the ground on your arduino being powered by your computer.
touch the other end to one of the two pins. if the pc starts to shut down or power on (depending on which state its in) then thats the pin you need if not connect it to the other pin and connect it to adruino digital 13

Step 3: The Code

the code i used to test this was very simple it was just a modified version of the arduino physical pixel sample. 

to test your setup:
load the code 
plug the arduino in to a separate computer
open arduino on the second computer
open the serial monitor at 9600baud
 type an "O" and hit enter.
if your computer is on it should now act as if you have hit the power button and begin to shut down.

/*
  Physical Pixel

The circuit:
* LED connected from digital pin 13 to ground

created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe and Scott Fitzgerald

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/PhysicalPixel
*/

const int ledPin = 13; // the pin that the LED is attached to
int incomingByte;      // a variable to read incoming serial data into

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
    // if it's a capital O (ASCII 72), turn on the computer:
    if (incomingByte == 'O') {
      digialWrite(ledPin, LOW);
      delay(500);
      digitalWrite(ledPin, HIGH);
    }
  }
}

thats the very basic modified code use pin 13 to power on and off your pc

Step 4: IT WORKED...now What?

now is where creativity comes in. some ideas to make this cool are

rfid card to start your computer
bluetooth! fire up your computer from across the room.
PIR have your arduino sense when your around and turn you computer on
IR use your tv remote to fire up your pc.

or add other code and more uses!
 a fancy light show
 built in fan controller
 hard drive power switch

the possibilities are endless!

Epilog Challenge V

Participated in the
Epilog Challenge V

Arduino Contest

Participated in the
Arduino Contest

Be the First to Share

    Recommendations

    • Make it Glow Contest

      Make it Glow Contest
    • First Time Author Contest

      First Time Author Contest
    • PCB Challenge

      PCB Challenge

    17 Discussions

    0
    JeremyH4
    JeremyH4

    Question 7 months ago on Step 4

    Is it a good idea to use Pin 13 on the Arduino? The way I see it, if
    the onboard LED is lit for any reason, you will be sending a "shutdown
    pulse" to the PC. Wouldn't that mean that every time you try to
    communicate with the Arduino (for example when you program it using the
    USB), this will just shut your PC down? It confused me initially when I
    did this! My workaround was to use a different pin on the Arduino (D12)
    and change the references in the sketch from 13 to 12...

    0
    rakly3
    rakly3

    10 months ago

    This is the first time I am using Arduino. There are a bunch of errors in the code which took me a while to figure out. there was a typo in digiTalWrite., incomingByte wasn't declared, The HIGH/LOW sequence was in the wrong order.
    Luckily I pick up on Syntax quite easy even though I'm not a programmer :)
    I will post the corrected code here:

    void setup() {
    // initialize serial communication:
    Serial.begin(9600);
    // initialize the LED pin as an output:
    pinMode(LED_BUILTIN, OUTPUT);
    }
    void loop() {
    // see if there's incoming serial data:
    if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    int incomingByte = Serial.read();
    // if it's a capital O (ASCII 72), turn on the computer:
    if (incomingByte == 'O') {
    digitalWrite(LED_BUILTIN, HIGH);
    delay(5000);
    digitalWrite(LED_BUILTIN, LOW);
    }
    }
    }

    0
    JeremyH4
    JeremyH4

    Reply 8 months ago

    Hi rakly3, a PC On/Off switch works by shorting the sensing pin to ground. This pin is normally pulled HIGH (5volts) internally. Therefore, I would suggest that the original code would be correct, where the pin is pulled LOW first and then set back to HIGH after half a second (500 ms). This would simulate you pressing the power button for half a second and then releasing it... Basically, the code you have posted above says "if you receive the trigger-code "O", do nothing for 5 seconds (not sure of your reason for changing this delay), then press and keep holding the button forever"... Note that holding the power button for more than 4 seconds will result in a forced power off, rather than letting your operating system deal with it and close down cleanly, so you're probably risking losing data and getting "Windows did not close down properly" sort of messages when you start it again.
    I'm pretty sure that's not what you want to be doing :) ... In fact, I suspect you might be stressing components by doing that, because your computer is trying to send that pin to +5v, but your arduino is going to be constantly pulling it to ground, so they're fighting each other. No sure which one would win, but you might find nasty things happen sooner or later, and I suspect you could damage your arduino eventually ...
    If anyone could confirm this, I would be grateful :)

    Hi, this project is great! I have a question though, do you know if it would be possible to do with a laptop computer?

    0
    Misadventures in 3D Printing
    Misadventures in 3D Printing

    Reply 1 year ago

    Most likely not. The power button on your laptop is solderd in place. Or is part of thr board itself.

    0
    ChasseC
    ChasseC

    1 year ago

    I get what you are doing here basically using the arduino as an inline switch, how difficult would it be to turn on and off a power supply which has no computer in another case and keep it running until the power supply in the first case was gracefully shutdown?

    0
    larsh32
    larsh32

    Tip 1 year ago

    For anyone who can't get this to work. You have to connect the negative pin of the mother board to the ground pin of your arduino and the positive pin on the motherboard to pin 13 of the arduino. i hope this clears up some questions people are having

    0
    Hey Dave
    Hey Dave

    2 years ago

    there will be two wires from your power switch to your motherboard.
    unplug them both and connect your jumper wire to the ground on your arduino being powered by your computer.
    touch the other end to one of the two pins. if the pc starts to shut down or power on (depending on which state its in) then thats the pin you need if not connect it to the other pin and connect it to adruino digital 13

    can you explain this more

    0
    jaysonbadz
    jaysonbadz

    2 years ago

    Hi, Can you send me the circuit diagram? Thanks!

    0
    dogla
    dogla

    4 years ago

    Hi, Do you HAVE to unplug the two plugs to connect the Arduino to act as power button? Can't you just tap into one of the power button cables so you could still use the physical power button to turn it on and off. I want to integrate the Arduino to receive an ON or OFF instruction via email to remotely turn on my pc when I'm at work, so I can start a Teamviewer session on it.

    0
    CodeNoob
    CodeNoob

    Reply 3 years ago

    You should be able to! The only thing I'd worry about is a scenario where the Arduino is outputting +5V and the physical button is pressed. I think this would short the Arduino's output pin to ground =(

    You could probably get the same functionality by having the physical button be an input to the Arduino and handling both the email and button presses in the Arduino's code.

    Let us all know how it goes!

    0
    jfrasser
    jfrasser

    4 years ago

    Hello from Venezuela. Sir, can you send me the circuit diagram ? thank you!

    0
    YapangJ1
    YapangJ1

    4 years ago

    Relay will needing for that right inorder to control the AC

    0
    k.biagini
    k.biagini

    Reply 4 years ago

    I'm not switching on and off the high current AC just using the arduino in place of the power switch on the pc case. It's all 5v

    0
    YapangJ1
    YapangJ1

    Reply 4 years ago

    Can you send me the circuit diagram of the adruino to connect with CPU..?

    I don´t get this completely. you say: "there will be two wires from your power switch to your motherboard.

    unplug them both (note from me: unplug them from where? from the power switch or the motherboard?? I guess it should be the power switch since the arduino will replace the power switch?) and connect your jumper wire to the ground on your arduino being powered by your computer. touch the other end to one of the two pins. (those two pins on the motherboard right? if I don´t get the correct pin at the first time will I fry my arduino board or something? aand the last question, once I get the pin that will turn on/off my computer, I connect the other end of the wire to the pin 13? or I keep it at GND and connect the other pin to the pin 13?).

    thank you!!!