Seafox_C
Published © GPL3+

Turn on your PC with Alexa and the ESP8266 like IRONMAN

Are you also tired of pressing the button on your PC case? Are you also highly motivated for doing less? This the project for you!

BeginnerFull instructions provided1 hour3,044
Turn on your PC with Alexa and the ESP8266 like IRONMAN

Things used in this project

Hardware components

NodeMCU ESP8266 with CH340G
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Breadboard (generic)
Breadboard (generic)
×1
Short jumper wires
×1
Singel channel 5V relay
×1
Wago clamps 3 hole
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic ESP8266 PC boot

Code

ESP8266 code Boot PC with ESP8266

Arduino
You first have to add the library to your Arduino IDE and add the board to your Arduino IDE. After that you change the name on how you like to call your computer and change the network name and password.
/*
   This is a basic example on how to use Espalexa and its device declaration methods.
   This code is edited for controlling a PC power Button and so control your PC by SeafoxC

   YouTube Channel : https://www.youtube.com/c/seafoxc
 
*/

#ifdef ARDUINO_ARCH_ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#include <Espalexa.h>


#define R1 2 // PIN D4 on a Node MCU V3


boolean connectWifi();

//callback functions
void firstLightChanged(uint8_t brightness);


// Change this!!

// WiFi Credentials
const char* ssid = "Your network name";
const char* password = "Your network password";

// device names
String Device_1_Name = "Jarvis"; // This the name you can use in the Alexa App. Make sure you it is easy to pronounce it :).


boolean wifiConnected = false;

Espalexa espalexa;

void setup()
{
  Serial.begin(115200);

  pinMode(R1, OUTPUT);


  // Initialise wifi connection
  wifiConnected = connectWifi();

  if (wifiConnected)
  {

    // Define your devices here.
    espalexa.addDevice(Device_1_Name, firstLightChanged); //simplest definition, default state off

    espalexa.begin();
    digitalWrite(R1, HIGH);

  }

  else
  {
    while (1)
    {
      Serial.println("Cannot connect to WiFi. Please check data and reset the ESP.");
      delay(2500);
    }
  }

}

void loop()
{
  espalexa.loop();
  delay(1);
}

//our callback functions
void firstLightChanged(uint8_t brightness)
{
  //Control the device
  if (brightness)
  {
    if (brightness == 255)
    {
      digitalWrite(R1, LOW);
      delay(2000);
      digitalWrite(R1, HIGH);
      Serial.println("Device1 ON");
    }

  }
  else
  {
    digitalWrite(R1, LOW);
    delay(2000);
    digitalWrite(R1, HIGH);
    Serial.println("Device1 OFF");
  }
}




// connect to wifi – returns true if successful or false if not
boolean connectWifi()
{
  boolean state = true;
  int i = 0;

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.println("");
  Serial.println("Connecting to WiFi");

  // Wait for connection
  Serial.print("Connecting...");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    if (i > 20) {
      state = false; break;
    }
    i++;
  }
  Serial.println("");
  if (state) {
    Serial.print("Connected to ");
    Serial.println(ssid);
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());
  }
  else {
    Serial.println("Connection failed.");
  }
  return state;
}

Credits

Seafox_C

Seafox_C

10 projects • 47 followers
I'm 29 years old and live in Belgium. I love the Arduino community and like to learn and make projects.

Comments