How to turn on your Computer Remotely – DIY Tutorial

0
18431

Powering on your PC from anywhere in the world is something that you wanted for a long time?

Today we’re making a very interesting DIY Project. I will show you the best method to power on your PC from anywhere in the world using your smartphone, tablet, or any other device that can access a link.

For this project you need a Wemos D1 Mini module – which is very cheap, around 3$, and a Relay Shield for it, which is around 2 dollars. I would like to tell you that you don’t need a Soldering Iron as I know many of you run away from that. But, if you want me to start with a lie, don’t worry, you don’t it!

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

const char* ssid = "";                   // WRITE YOUR WIFI SSID
const char* password = "";     // WRITE YOUR WIFI PASSWORD
const char* web_password = ""; // WRITE SOMETHING SECURE AND RANDOM
const int relayPin = D1;
byte mac[6];                     // the MAC address of your Wifi shield

ESP8266WebServer server(8085);

const int led = 13;

void handleRoot() {
  digitalWrite(led, 1);
  server.send(200, "text/plain", "hello from esp8266!");
  digitalWrite(led, 0);
}

void handleNotFound(){
  digitalWrite(led, 1);
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET)?"GET":"POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i=0; i<server.args(); i++){
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);
  digitalWrite(led, 0);
}

void setup(void){
  pinMode(led, OUTPUT);
  pinMode(relayPin, OUTPUT);
  digitalWrite(led, 0);
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  WiFi.macAddress(mac);
  Serial.print("MAC: ");
  Serial.print(mac[5],HEX);
  Serial.print(":");
  Serial.print(mac[4],HEX);
  Serial.print(":");
  Serial.print(mac[3],HEX);
  Serial.print(":");
  Serial.print(mac[2],HEX);
  Serial.print(":");
  Serial.print(mac[1],HEX);
  Serial.print(":");
  Serial.println(mac[0],HEX);

  if (MDNS.begin("PowerComp")) {
    Serial.println("MDNS responder started");
  }

  server.on("/", handleRoot);

  server.on("/shortpresspowerbutton", [](){
    if(server.arg(0) == web_password) {
      digitalWrite(relayPin, HIGH); // turn on relay with voltage HIGH
      delay(200);              // pause
      digitalWrite(relayPin, LOW);  // turn off relay with voltage LOW
      delay(500);              // pause
      server.send(200, "text/plain", "Button pressed");
    } else {
      server.send(200, "text/plain", "Button not pressed");
    }
  });
  server.on("/longpresspowerbutton", [](){
      if(server.arg(0) == web_password) {
      digitalWrite(relayPin, HIGH); // turn on relay with voltage HIGH
      delay(5000);              // pause
      digitalWrite(relayPin, LOW);  // turn off relay with voltage LOW
      delay(500);              // pause
      server.send(200, "text/plain", "Button pressed");
    } else {
      server.send(200, "text/plain", "Button not pressed");
    }
  });
  server.on("/ultralongpresspowerbutton", [](){
      if(server.arg(0) == web_password) {
      digitalWrite(relayPin, HIGH); // turn on relay with voltage HIGH
      delay(9000);              // pause
      digitalWrite(relayPin, LOW);  // turn off relay with voltage LOW
      delay(500);              // pause
      server.send(200, "text/plain", "Button pressed");
    } else {
      server.send(200, "text/plain", "Button not pressed");
    }
  });

  server.onNotFound(handleNotFound);

  server.begin();
  Serial.println("HTTP server started");
}

void loop(void){
  server.handleClient();
}

Arduino IDE – Stepby step Install

LEAVE A REPLY

Please enter your comment!
Please enter your name here