Home // Electronics // Arduino Control PC Powerstate

Arduino Control PC Powerstate

I found myself in a situation where I needed to be able to ping a computer and based on the response power cycle the machine. The Arduino pings the target system and determines if the machine is responsive. If the machine is not responsive it will simply power cycle the machine and wait 3 minutes to check again.  

I used a Arduino along with an Arduino Ethernet shield. Here is the code that was loaded onto the Arduino. This is link to the source code below PcPowerUp. The white wire is connected PC power switch 5V side. The orange wire is connected to the ground. This is great for those mining rigs that are just slightly unstable. Couple this with CGWatcher and your mining troubles should subside! *****************************************************************************************************************
  Ping Example
 This example sends an ICMP pings every 500 milliseconds, sends the human-readable
 result over the serial port. 

 * Ethernet shield attached to pins 10, 11, 12, 13
 created 30 Sep 2010
 by Blake Foster
 //Modified by William Fecke
 //25 Jan 2014
 added a logic statement to trip power on pc if ping failed.

#include <SPI.h>         
#include <Ethernet.h>
#include <ICMPPing.h>

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // max address for ethernet shield
byte ip[] = {192,168,4,177}; // ip address for ethernet shield
IPAddress pingAddr(192,168,4,114); // ip address to ping
int failogic = 0;
int alternatePress = 0;
int powerPin = 4;
int powerPinStatus = 5;

SOCKET pingSocket = 0;

char buffer [256];
ICMPPing ping(pingSocket, (uint16_t)random(0, 255));

void setup() 
  // start Ethernet
  Ethernet.begin(mac, ip);

void loop()
  ICMPEchoReply echoReply = ping(pingAddr, 4);
  if (echoReply.status == SUCCESS)
            "Reply[%d] from: %d.%d.%d.%d: bytes=%d time=%ldms TTL=%d",
            millis() - echoReply.data.time,
            failogic = 0; // resets the logic count if machine starts to respond to the pings
            alternatePress = 0;
    failogic++; //this will increment the counter for every failed ping
    sprintf(buffer, "Echo request failed; %d", echoReply.status); 
  if (failogic > 5) // 5 failed pings will trip the if statement and cause the arduino to hit the power button
     digitalWrite(powerPin,LOW); //The positive side of the power button is connected to PIN 4 on my Arduino so moving it to the LOW state simulates pushing the power button
     digitalWrite(powerPinStatus,HIGH); //LED turns on while button is pressed
     if(alternatePress == 0)
     delay(5500); //This delay kills the PC power all together
     alternatePress = 1;
      delay(500); //This delay quickly presses the button;
     digitalWrite(powerPin,HIGH); //This is the release of the power button
     digitalWrite(powerPinStatus,LOW);//LED turns off when button is released
Posted in Electronics, Fun Hacking, Programming

Leave a Reply