Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 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 = 0;
  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(100L, check);
  52.  
  53. }
  54. BLYNK_WRITE(V1) // V5 is the number of Virtual Pin
  55. {
  56. VirtualPin1 = param.asInt();
  57. if (VirtualPin1==0)
  58. {
  59. digitalWrite(relay1,HIGH);
  60. flag = 0;
  61. }
  62. if (VirtualPin1==1)
  63. {
  64. digitalWrite(relay1,LOW);
  65. flag = 0;
  66. }
  67. if (VirtualPin1==2)
  68. flag = 1;
  69. Serial.println(VirtualPin1);
  70. }
  71. void check() {
  72. Serial.println("in check");
  73. Serial.print("inainte de if");
  74. Serial.print(flag);
  75. Serial.println(" ");
  76. if ( flag == 1 ){
  77. Serial.println("in if");
  78. Serial.print(flag);
  79. motionstate=digitalRead(motionsensor);
  80. lightstate=analogRead(lightsensor);
  81. if ( lightstate > 600 && motionstate == 1 )
  82. {
  83. digitalWrite(relay1,HIGH);
  84. ok = 1;
  85. Serial.println("pornit");
  86. }
  87. if ( motionstate == 0 && ok == 1 )
  88. {
  89. digitalWrite(relay1,LOW);
  90. ok = 0;
  91. Serial.println("oprit");
  92. }}
  93. }
  94. void loop() {
  95. Blynk.run();
  96. timer.run();
  97. ArduinoOTA.handle(); // For OTA
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement