Advertisement
safwan092

project-3652-not-final

Oct 31st, 2021
1,216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.31 KB | None | 0 0
  1. /*************************************************************
  2.   Download latest Blynk library here:
  3.     https://github.com/blynkkk/blynk-library/releases/latest
  4.  
  5.   Blynk is a platform with iOS and Android apps to control
  6.   Arduino, Raspberry Pi and the likes over the Internet.
  7.   You can easily build graphic interfaces for all your
  8.   projects by simply dragging and dropping widgets.
  9.  
  10.     Downloads, docs, tutorials: http://www.blynk.cc
  11.     Sketch generator:           http://examples.blynk.cc
  12.     Blynk community:            http://community.blynk.cc
  13.     Follow us:                  http://www.fb.com/blynkapp
  14.                                 http://twitter.com/blynk_app
  15.  
  16.   Blynk library is licensed under MIT license
  17.   This example code is in public domain.
  18.  
  19.  *************************************************************
  20.   This example runs directly on ESP32 chip.
  21.  
  22.   Note: This requires ESP32 support package:
  23.     https://github.com/espressif/arduino-esp32
  24.  
  25.   Please be sure to select the right ESP32 module
  26.   in the Tools -> Board menu!
  27.  
  28.   Change WiFi ssid, pass, and Blynk auth token to run :)
  29.   Feel free to apply it to any other example. It's simple!
  30.  *************************************************************/
  31.  
  32. /* Comment this out to disable prints and save space */
  33. #define BLYNK_PRINT Serial
  34.  
  35. /* Fill-in your Template ID (only if using Blynk.Cloud) */
  36. //#define BLYNK_TEMPLATE_ID   "YourTemplateID"
  37.  
  38. #include <WiFi.h>
  39. #include <WiFiClient.h>
  40. #include <BlynkSimpleEsp32.h>
  41. #include <ESP32Servo.h>
  42.  
  43. Servo servo1;
  44.  
  45. BlynkTimer timer;
  46.  
  47. //Pins Connections:
  48. #define soil_moisture_PIN 35
  49. #define LOW_indicator_PIN 21
  50. #define HIGH_indicator_PIN 19
  51. #define relay_1_PIN 4
  52. #define relay_2_PIN 18
  53. #define servo_PIN 13
  54.  
  55. // You should get Auth Token in the Blynk App.
  56. // Go to the Project Settings (nut icon).
  57. char auth[] = "tg00tBqfJZA1BCOli4ztyyhvffJQ3-N6";
  58.  
  59. // Your WiFi credentials.
  60. // Set password to "" for open networks.
  61. char ssid[] = "network";
  62. char pass[] = "123456789";
  63.  
  64. void sendSensor()
  65. {
  66.   int value = analogRead(soil_moisture_PIN);
  67.   value = map(value, 4095, 0, 0, 100);
  68.   int value2 = digitalRead(LOW_indicator_PIN);
  69.   int value3 = digitalRead(HIGH_indicator_PIN);
  70.   int percent = 0;
  71.   if (value2 == 0) {
  72.     percent = 20;
  73.   }
  74.   if (value3 == 0) {
  75.     percent = 100;
  76.   }
  77.   else if (value3 != 0 && value2 != 0) {
  78.     percent = 0;
  79.     digitalWrite(relay_1_PIN, 1);
  80.   }
  81.   if (value < 60 && value != 0) {
  82.     digitalWrite(relay_1_PIN, 0);
  83.   }
  84.   else if (value > 90) {
  85.     digitalWrite(relay_1_PIN, 1);
  86.   }
  87.  
  88.   Blynk.virtualWrite(V5, value);
  89.   Blynk.virtualWrite(V6, percent);
  90. }
  91.  
  92. void setup()
  93. {
  94.   // Debug console
  95.   Serial.begin(9600);
  96.   ESP32PWM::allocateTimer(0);
  97.   ESP32PWM::allocateTimer(1);
  98.   ESP32PWM::allocateTimer(2);
  99.   ESP32PWM::allocateTimer(3);
  100.   servo1.setPeriodHertz(50);// Standard 50hz servo
  101.   servo1.attach(servo_PIN, 500, 2400);
  102.   pinMode(soil_moisture_PIN, INPUT);
  103.   pinMode(LOW_indicator_PIN, INPUT);
  104.   pinMode(HIGH_indicator_PIN, INPUT);
  105.   pinMode(relay_1_PIN, OUTPUT);
  106.   pinMode(relay_2_PIN, OUTPUT);
  107.   digitalWrite(relay_1_PIN, 1);
  108.   digitalWrite(relay_2_PIN, 1);
  109.   Blynk.begin(auth, ssid, pass);
  110.   timer.setInterval(1000L, sendSensor);
  111. }
  112.  
  113. void loop()
  114. {
  115.   Blynk.run();
  116.   timer.run();
  117. }
  118.  
  119. BLYNK_WRITE(V3)
  120. {
  121.   servo1.write(param.asInt());
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement