Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 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 VirtualPin1;
  34. char server[] = "192.168.1.228"; // IP for your Local Server
  35. int port = 8080;
  36.  
  37.  
  38. void setup() {
  39. Serial.begin(9600); // BLYNK_PRINT data
  40.  
  41. WiFi.begin(ssid, pass);
  42. Blynk.config(auth, server, port);
  43. Blynk.connect();
  44.  
  45. ArduinoOTA.setHostname("ESP_Dormitor_1"); // For OTA - Use your own device identifying name
  46. ArduinoOTA.begin(); // For OTA
  47. pinMode (relay1, OUTPUT);
  48. pinMode (motionsensor, INPUT);
  49. digitalWrite(relay1,LOW);
  50. timer.setInterval(100L, check);
  51.  
  52. }
  53. BLYNK_WRITE(V1) // V5 is the number of Virtual Pin
  54. {
  55. VirtualPin1 = param.asInt();
  56. if (VirtualPin1==0)
  57. digitalWrite(relay1,HIGH);
  58. if (VirtualPin1==1)
  59. digitalWrite(relay1,LOW);
  60. }
  61. void check() {
  62. if ( VirtualPin1 == 2 ){
  63. motionstate=digitalRead(motionsensor);
  64. lightstate=analogRead(lightsensor);
  65. if ( lightstate > 600 && motionstate == 1 )
  66. {
  67. digitalWrite(relay1,HIGH);
  68. ok = 1;
  69. }
  70. if ( motionstate == 0 && ok == 1 )
  71. {
  72. digitalWrite(relay1,LOW);
  73. ok = 0;
  74. }}
  75. }
  76. void loop() {
  77. Blynk.run();
  78. timer.run();
  79. ArduinoOTA.handle(); // For OTA
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement