Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. #define BLYNK_PRINT Serial // This prints to Serial Monitor
  2. //#define BLYNK_DEBUG // Optional, this enables more detailed prints
  3.  
  4. //// Pick one Blynk Device Library group or other
  5. ////----------
  6. // #include <WiFi.h> // for ESP32
  7. // #include <WiFiClient.h> // for ESP32
  8. // #include <BlynkSimpleEsp32.h> // for ESP32
  9. ////----------
  10. #include <ESP8266WiFi.h> // for ESP8266
  11. #include <BlynkSimpleEsp8266.h> // for ESP8266
  12. ////----------
  13.  
  14. //// Pick one OTA Library or other
  15. ////----------
  16. // #include <ESPmDNS.h> // For OTA w/ ESP32
  17. ////----------
  18. #include <ESP8266mDNS.h> // For OTA w/ ESP8266
  19. ////----------
  20.  
  21. #include <WiFiUdp.h> // For OTA
  22. #include <ArduinoOTA.h> // For OTA
  23. BlynkTimer timer;
  24. char auth[] = "_wAZYbzsPQQGREWJXZf1lPX1fpvgDCt5";
  25. char ssid[] = "testnetwork";
  26. char pass[] = "test1234";
  27. int relay1=D0;
  28. int lightsensor=A0;
  29. int motionsensor=D2;
  30. int lightstate=0;
  31. int motionstate=0;
  32. int ok;
  33. int flag = 2;
  34. int VirtualPin1=2;
  35. char server[] = "192.168.1.228"; // IP for your Local Server
  36. int port = 8080;
  37.  
  38.  
  39. void setup() {
  40. Serial.begin(9600); // BLYNK_PRINT data
  41.  
  42. WiFi.begin(ssid, pass);
  43. Blynk.config(auth, server, port);
  44. Blynk.connect();
  45.  
  46. ArduinoOTA.setHostname("ESP_Dormitor_1"); // For OTA - Use your own device identifying name
  47. ArduinoOTA.begin(); // For OTA
  48. pinMode (relay1, OUTPUT);
  49. pinMode (motionsensor, INPUT);
  50. digitalWrite(relay1,LOW);
  51. timer.setInterval(1000L, check);
  52.  
  53. }
  54. BLYNK_WRITE(V1) // V5 is the number of Virtual Pin
  55. {
  56. VirtualPin1 = param.asInt();
  57. check();
  58. }
  59. void check() {
  60. if (VirtualPin1 == 0)
  61. {
  62. digitalWrite(relay1,HIGH);
  63. }
  64. if (VirtualPin1 == 1)
  65. {
  66. digitalWrite(relay1,LOW);
  67. }
  68. if ( VirtualPin1 == 2 )
  69. {
  70. motionstate=digitalRead(motionsensor);
  71. lightstate=analogRead(lightsensor);
  72. if ( lightstate > 600 && motionstate == 1 )
  73. {
  74. digitalWrite(relay1,HIGH);
  75. ok = 1;
  76. }
  77. if ( motionstate == 0 && ok == 1 )
  78. {
  79. digitalWrite(relay1,LOW);
  80. ok = 0;
  81. }}
  82. }
  83.  
  84. void loop() {
  85. Blynk.run();
  86. timer.run();
  87. ArduinoOTA.handle(); // For OTA
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement