Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*************************************************************
- Download latest Blynk library here:
- https://github.com/blynkkk/blynk-library/releases/latest
- Blynk is a platform with iOS and Android apps to control
- Arduino, Raspberry Pi and the likes over the Internet.
- You can easily build graphic interfaces for all your
- projects by simply dragging and dropping widgets.
- Downloads, docs, tutorials: http://www.blynk.cc
- Sketch generator: http://examples.blynk.cc
- Blynk community: http://community.blynk.cc
- Follow us: http://www.fb.com/blynkapp
- http://twitter.com/blynk_app
- Blynk library is licensed under MIT license
- This example code is in public domain.
- *************************************************************
- This example runs directly on ESP32 chip.
- Note: This requires ESP32 support package:
- https://github.com/espressif/arduino-esp32
- Please be sure to select the right ESP32 module
- in the Tools -> Board menu!
- Change WiFi ssid, pass, and Blynk auth token to run :)
- Feel free to apply it to any other example. It's simple!
- *************************************************************/
- /* Comment this out to disable prints and save space */
- #define BLYNK_PRINT Serial
- /* Fill-in your Template ID (only if using Blynk.Cloud) */
- //#define BLYNK_TEMPLATE_ID "YourTemplateID"
- #include <WiFi.h>
- #include <WiFiClient.h>
- #include <BlynkSimpleEsp32.h>
- #include <ESP32Servo.h>
- Servo servo1;
- BlynkTimer timer;
- //Pins Connections:
- #define soil_moisture_PIN 35 //
- #define LOW_indicator_PIN 3 //21 //
- #define HIGH_indicator_PIN 19 //
- #define relay_1_PIN 4 // Water Pump
- #define relay_2_PIN 21 //18 // LED Strip
- #define servo_PIN 13 //
- #define LDR_PIN 33 //
- #define redLED_PIN 25 //
- #define blueLED_PIN 26 //
- // You should get Auth Token in the Blynk App.
- // Go to the Project Settings (nut icon).
- char auth[] = "tg00tBqfJZA1BCOli4ztyyhvffJQ3-N6";
- // Your WiFi credentials.
- // Set password to "" for open networks.
- char ssid[] = "network";
- char pass[] = "123456789";
- void sendSensor()
- {
- int value1 = analogRead(soil_moisture_PIN);
- value1 = map(value1, 4095, 0, 0, 100);
- int value2 = digitalRead(LOW_indicator_PIN);
- int value3 = digitalRead(HIGH_indicator_PIN);
- int value4 = analogRead(LDR_PIN);
- Serial.print(value1);
- Serial.print(" | ");
- Serial.print(value2);
- Serial.print(" | ");
- Serial.print(value3);
- Serial.print(" | ");
- Serial.println(value4);
- int percent = 0;
- if (value2 == 0 && value3 == 1) {
- percent = 20;
- digitalWrite(redLED_PIN, 1);
- digitalWrite(blueLED_PIN, 0);
- Serial.println("#1");
- }
- else if (value3 == 0 && value2 == 0) {
- percent = 100;
- digitalWrite(redLED_PIN, 0);
- digitalWrite(blueLED_PIN, 1);
- Serial.println("#3");
- }
- else if (value3 != 0 && value2 != 0) {
- percent = 0;
- digitalWrite(relay_1_PIN, 1); // turn off water pump
- digitalWrite(redLED_PIN, 1);
- digitalWrite(blueLED_PIN, 0);
- Serial.println("#4");
- }
- if (value1 < 60 && value1 != 0 && percent != 0) {
- digitalWrite(relay_1_PIN, 0);
- Serial.println("#5");
- }
- else if (value1 > 90 || percent == 0 || value1 == 0) {
- digitalWrite(relay_1_PIN, 1);
- Serial.println("#6");
- }
- if (value4 < 700) {
- digitalWrite(relay_2_PIN, 0);
- Serial.println("#7");
- }
- else if (value4 > 700) {
- digitalWrite(relay_2_PIN, 1);
- Serial.println("#8");
- }
- Blynk.virtualWrite(V5, value1);
- Blynk.virtualWrite(V6, percent);
- }
- void setup()
- {
- // Debug console
- Serial.begin(9600);
- ESP32PWM::allocateTimer(0);
- ESP32PWM::allocateTimer(1);
- ESP32PWM::allocateTimer(2);
- ESP32PWM::allocateTimer(3);
- servo1.setPeriodHertz(50);// Standard 50hz servo
- servo1.attach(servo_PIN, 500, 2400);
- pinMode(soil_moisture_PIN, INPUT);
- pinMode(LOW_indicator_PIN, INPUT);
- pinMode(HIGH_indicator_PIN, INPUT);
- pinMode(LDR_PIN, INPUT);
- pinMode(relay_1_PIN, OUTPUT);
- pinMode(relay_2_PIN, OUTPUT);
- pinMode(redLED_PIN, OUTPUT);
- pinMode(blueLED_PIN, OUTPUT);
- //digitalWrite(relay_1_PIN, 0);
- //digitalWrite(relay_2_PIN, 0);
- //delay(1000);
- digitalWrite(relay_1_PIN, 1);
- digitalWrite(relay_2_PIN, 1);
- digitalWrite(redLED_PIN, 0);
- digitalWrite(blueLED_PIN, 0);
- Blynk.begin(auth, ssid, pass);
- timer.setInterval(2000L, sendSensor);
- }
- void loop()
- {
- Blynk.run();
- timer.run();
- }
- BLYNK_WRITE(V3)
- {
- servo1.write(param.asInt());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement