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 21
- #define HIGH_indicator_PIN 19
- #define relay_1_PIN 4
- #define relay_2_PIN 18
- #define servo_PIN 13
- // 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 value = analogRead(soil_moisture_PIN);
- value = map(value, 4095, 0, 0, 100);
- int value2 = digitalRead(LOW_indicator_PIN);
- int value3 = digitalRead(HIGH_indicator_PIN);
- int percent = 0;
- if (value2 == 0) {
- percent = 20;
- }
- if (value3 == 0) {
- percent = 100;
- }
- else if (value3 != 0 && value2 != 0) {
- percent = 0;
- digitalWrite(relay_1_PIN, 1);
- }
- if (value < 60 && value != 0) {
- digitalWrite(relay_1_PIN, 0);
- }
- else if (value > 90) {
- digitalWrite(relay_1_PIN, 1);
- }
- Blynk.virtualWrite(V5, value);
- 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(relay_1_PIN, OUTPUT);
- pinMode(relay_2_PIN, OUTPUT);
- digitalWrite(relay_1_PIN, 1);
- digitalWrite(relay_2_PIN, 1);
- Blynk.begin(auth, ssid, pass);
- timer.setInterval(1000L, sendSensor);
- }
- void loop()
- {
- Blynk.run();
- timer.run();
- }
- BLYNK_WRITE(V3)
- {
- servo1.write(param.asInt());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement