Advertisement
WpJuel

Arduino Pc Turn off and on

Mar 30th, 2019
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //links with Blynk Libaries for NodeMCU
  2. #define BLYNK_PRINT Serial
  3. #include <ESP8266WiFi.h>
  4. #include <BlynkSimpleEsp8266.h>
  5.  
  6. //Authentication
  7. char auth[] = "TOKEN";                              //Your blynk token
  8. char ssid[] = "SSID";                               //Your wifi SSID
  9. char pass[] = "PASS";                               //Your wifi password
  10.  
  11. //On startup
  12. void setup()
  13. {
  14.   Serial.begin(9600);                               //starting the Debug com (Open it by clicking on Tools -> Serial Monitor)
  15.   Blynk.begin(auth, ssid, pass);                    //Authentication with Blynk
  16.   pinMode (D1, OUTPUT);                             //Enables Pin D1
  17.   digitalWrite(D1, !digitalRead(D1));               //Sets state of Pin D1 to the opposite on start *Remove if Relay is on, on start*
  18.   }
  19.  
  20.  
  21. //Turn on script
  22. BLYNK_WRITE(V1) {                                   //Start of Script
  23.    if (param.asInt()==1){                           //Checks if Virtual port V1 is active, and if it is, it will run the script
  24.     digitalWrite(D1, LOW);                          //Sets the state of port D1 to LOW
  25.     delay(300);                                     //Delay for 3 miliseconds
  26.     digitalWrite(D1, HIGH);                         //Sets the state of port D1 to HIGH
  27.     Blynk.virtualWrite(V1, LOW);                    //Sets Virtual port V1 to be disabled
  28.     }                                               //end of "if true" script
  29. }                                                   //End of script
  30.  
  31. //Force turn off script
  32. BLYNK_WRITE(V2) {                                   //Start of Script
  33.    if (param.asInt()==1){                           //Checks if Virtual port V2 is active, and if it is, it will run the script
  34.     digitalWrite(D1, LOW);                          //Sets the state of port D1 to LOW
  35.     delay(6000);                                     //Delay for 3 miliseconds
  36.     digitalWrite(D1, HIGH);                         //Sets the state of port D1 to HIGH
  37.     Blynk.virtualWrite(V2, LOW);                    //Sets Virtual port V2 to be disabled
  38.     }                                               //end of "if true" script
  39. }                                                   //End of script
  40.  
  41. //When running
  42. void loop()
  43. {
  44.   Blynk.run();                                      //Start blynk connection
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement