Even though you weren’t talking to me but I have the same problem
I’m so upset
I need to fix it today or tomorrow
It’s been a while since I’ve been trying to fix this problem
I hope you can help me
#define BLYNK_TEMPLATE_ID "***"
#define BLYNK_DEVICE_NAME "***"
#define BLYNK_AUTH_TOKEN "***"
#define BLYNK_PRINT Serial
#define ESP8266_BAUD 9600
#define RE 8
#define DE 7
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
#include <SoftwareSerial.h>
char auth[] = "***";
char ssid[] = "***";
char pass[] = "***";
const int trigPin = 12;
const int echoPin = 13;
const int RELAY_PIN = A5;
long cm;
long duration;
int sensorPin = A0;
int soilMoistureValue = 0;
int percentage = 0;
const byte ph[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A};
byte values[11];
SoftwareSerial mod(2,3); // R0,D1
SoftwareSerial EspSerial(10, 11); // RX, TX
ESP8266 wifi(&EspSerial);
BlynkTimer timer;
BLYNK_WRITE(V0)
{
if(param.asInt()==1){
digitalWrite(RELAY_PIN, HIGH);
}
else{
digitalWrite(RELAY_PIN, LOW);
}
}
BLYNK_CONNECTED()
{
Blynk.syncVirtual(V0);
}
void Soilph()
{
byte val;
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
if (mod.write(ph, sizeof(ph)) == 8)
{
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
for (byte i = 0; i < 11; i++)
{
values[i] = mod.read();
}
Serial.println();
}
float soil_ph = float(values[4]) / 10;
Serial.print("Soil Ph: ");
Serial.println(soil_ph, 1);
Blynk.virtualWrite(V2, soil_ph);
Blynk.virtualWrite(V1, "7 is Neutral Soil ,6.5-0 is Acidic Soil ,7.5-14 is Alkaine Soil");
}
void Wlevel()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(4);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin,HIGH);
cm = duration / 29 / 2;
if (cm >= 10)
{
Blynk.logEvent("tank");
Serial.println("Tank is empty so pump is off");
digitalWrite(A5,LOW);
}
Blynk.virtualWrite(V3, cm);
Serial.print ("Water Level: ");
Serial.print(cm);
}
void SoilMoisture()
{
soilMoistureValue = analogRead(sensorPin);
percentage = map(soilMoistureValue, 490, 1023, 100, 0);
if(percentage <= 60 )
{
Blynk.logEvent("on");
digitalWrite(RELAY_PIN,HIGH);
}
else if (percentage >= 61 && percentage <= 79 )
{
Serial.println("pump Unoutomatic");
}
else if (percentage >= 80 < 490 )
{
Blynk.logEvent("off");
Serial.println("pump off");
digitalWrite(A5,LOW);
}
else {
Serial.println("pump Unoutomatic");
}
}
void Clockdispla()
{
// You can call hour(), minute(), ... at any time
// Please see Time library examples for details
String currentTime = String(hour()) + ":" + minute() + ":" + second();
String currentDate = String(day()) + "/" + month() + "/" + year();
Serial.print ("Current time: ");
Serial.print(currentTime);
Serial.print(" ");
Serial.print(currentDate);
Serial.println();
Blynk.virtualWrite(V4, currentTime);
Blynk.virtualWrite(V5, currentDate);
Blynk.logEvent("remind");
}
void setup() {
Serial.begin(9600);
mod.begin(4800);
EspSerial.begin(ESP8266_BAUD);
Blynk.begin(auth, wifi, ssid, pass);
Blynk.sendInternal("rtc", "sync");
pinMode(RE, OUTPUT);
pinMode(DE, OUTPUT);
pinMode(RELAY_PIN, OUTPUT);
// Waterlevel
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
timer.setInterval(20000L, Soilph);
timer.setInterval(1000L, Wlevel);
timer.setInterval(10000L, Clockdispla);
timer.setInterval(1000L, SoilMoisture);
}
void loop()
{
Blynk.run();
timer.run();
}