Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define BLYNK_PRINT Serial // This prints to Serial Monitor
- //#define BLYNK_DEBUG // Optional, this enables more detailed prints
- //// Pick one Blynk Device Library group or other
- ////----------
- // #include <WiFi.h> // for ESP32
- // #include <WiFiClient.h> // for ESP32
- // #include <BlynkSimpleEsp32.h> // for ESP32
- ////----------
- #include <ESP8266WiFi.h> // for ESP8266
- #include <BlynkSimpleEsp8266.h> // for ESP8266
- ////----------
- //// Pick one OTA Library or other
- ////----------
- // #include <ESPmDNS.h> // For OTA w/ ESP32
- ////----------
- #include <ESP8266mDNS.h> // For OTA w/ ESP8266
- ////----------
- #include <WiFiUdp.h> // For OTA
- #include <ArduinoOTA.h> // For OTA
- BlynkTimer timer;
- char auth[] = "_wAZYbzsPQQGREWJXZf1lPX1fpvgDCt5";
- char ssid[] = "testnetwork";
- char pass[] = "test1234";
- int relay1=D0;
- int lightsensor=A0;
- int motionsensor=D2;
- int lightstate=0;
- int motionstate=0;
- int ok;
- int flag = 0;
- int VirtualPin1=2;
- char server[] = "192.168.1.228"; // IP for your Local Server
- int port = 8080;
- void setup() {
- Serial.begin(9600); // BLYNK_PRINT data
- WiFi.begin(ssid, pass);
- Blynk.config(auth, server, port);
- Blynk.connect();
- ArduinoOTA.setHostname("ESP_Dormitor_1"); // For OTA - Use your own device identifying name
- ArduinoOTA.begin(); // For OTA
- pinMode (relay1, OUTPUT);
- pinMode (motionsensor, INPUT);
- digitalWrite(relay1,LOW);
- timer.setInterval(100L, check);
- }
- BLYNK_WRITE(V1) // V5 is the number of Virtual Pin
- {
- VirtualPin1 = param.asInt();
- if (VirtualPin1==0)
- {
- digitalWrite(relay1,HIGH);
- flag = 0;
- }
- if (VirtualPin1==1)
- {
- digitalWrite(relay1,LOW);
- flag = 0;
- }
- if (VirtualPin1==2)
- flag = 1;
- Serial.println(VirtualPin1);
- }
- void check() {
- Serial.println("in check");
- Serial.print("inainte de if");
- Serial.print(flag);
- Serial.println(" ");
- if ( flag == 1 ){
- Serial.println("in if");
- Serial.print(flag);
- motionstate=digitalRead(motionsensor);
- lightstate=analogRead(lightsensor);
- if ( lightstate > 600 && motionstate == 1 )
- {
- digitalWrite(relay1,HIGH);
- ok = 1;
- Serial.println("pornit");
- }
- if ( motionstate == 0 && ok == 1 )
- {
- digitalWrite(relay1,LOW);
- ok = 0;
- Serial.println("oprit");
- }}
- }
- void loop() {
- Blynk.run();
- timer.run();
- ArduinoOTA.handle(); // For OTA
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement