Ping Multi without any connection

You haven’t added flag variables to the logEvent commands to prevent multiple event logging and you haven’t removed the legacy RTC code.

If you’d bothered to re-read the posts in this topic and compare the advice you’ve been given to the changes you’ve made then you would have realised this - but clearly you haven’t taken that piece of advice onboard either.

Maybe that’s your problem. More time spent looking at the advice given in this topic would be a better approach.

Pete.

Can you take a look at this please ?
I’ve never used this RTC and flag variables before so I’m not sure if this is true or not

#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "***"
#define BLYNK_DEVICE_NAME "***"
#define BLYNK_AUTH_TOKEN "***"

#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;

bool alert_sent1 = false;
bool alert_sent2 = false;
bool alert_sent3 = false; 

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); 
  Blynk.sendInternal("rtc", "sync"); 
  }

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 && alert_sent1 == false )
  {
   

     Blynk.logEvent("tank");
     alert_sent1 = true;
     Serial.println("Tank is empty so pump is off");

    digitalWrite(A5,LOW);
  }
    else if(cm <= 10 && alert_sent1 == true) 
  {
  alert_sent1 = false;
  }
 
  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 && alert_sent2 == false )  
{
 
     Blynk.logEvent("on");
     alert_sent2 = true;
    digitalWrite(RELAY_PIN,HIGH);
}
else if(percentage >= 61 && percentage <= 79 && alert_sent2 == true) 
  {
  alert_sent2 = false;
  }

 else if (percentage >= 80  && percentage && alert_sent3 == false )
{

     Blynk.logEvent("off");
     alert_sent3 = true;
    Serial.println("pump off");
    digitalWrite(A5,LOW);
}
    else if(percentage >= 61 && percentage <= 79 && alert_sent3 == true) 
  {
  alert_sent3 = false;
  }
}       
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);
}
 


void setup() {
   Serial.begin(9600);
   mod.begin(4800);
  EspSerial.begin(ESP8266_BAUD);
 
  Blynk.begin(auth, wifi, ssid, pass);

     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();        
}

It’s unlikely that this will work. Why have you chosen to do it this way rather than placing the RTC command here…

as the example in the official documentation suggests?

And why do you have this…

Despite me saying…

Pete.

1 Like

Well I corrected it
What about the flag variables please
This is the latest version of the code
I hope you work
I’m so desperate
And thank you too

#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "***"
#define BLYNK_DEVICE_NAME "***"
#define BLYNK_AUTH_TOKEN "***"
#define ESP8266_BAUD 9600
#define RE 8
#define DE 7
 
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <TimeLib.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;

bool alert_sent1 = false;
bool alert_sent2 = false;
bool alert_sent3 = false; 

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); 
  Blynk.sendInternal("rtc", "sync"); 
  }

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 && alert_sent1 == false )
  {
   

     Blynk.logEvent("tank");
     alert_sent1 = true;
     Serial.println("Tank is empty so pump is off");

    digitalWrite(A5,LOW);
  }
    else if(cm <= 10 && alert_sent1 == true) 
  {
  alert_sent1 = false;
  }
 
  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 && alert_sent2 == false )  
{
      Blynk.logEvent("on");
     alert_sent2 = true;
    digitalWrite(RELAY_PIN,HIGH);
}
else if(percentage >= 61 && percentage <= 79 && alert_sent2 == true) 
  {
  alert_sent2 = false;
  }

 else if (percentage >= 80  && percentage <= 490 && alert_sent3 == false )
{

     Blynk.logEvent("off");
     alert_sent3 = true;
    Serial.println("pump off");
    digitalWrite(A5,LOW);
}
    else if(percentage >= 61 && percentage <= 79 && alert_sent3 == true) 
  {
  alert_sent3 = false;
  }
  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);
}
 


void setup() {
   Serial.begin(9600);
  EspSerial.begin(ESP8266_BAUD);
 
  Blynk.begin(auth, wifi, ssid, pass);
  mod.begin(4800);
  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();        
}

It’s difficult to follow the code, because of the way that your if statements aren’t indented properly, but it looks okay.

Does it work?

If not, then you need to focus on what you’re seeing in your serial monitor, and how you are powering your board and the peripherals.

Pete.

No it doesn’t work
The strange thing is that the code was working but when I added the void Soilph() and void Clockdispla() parts it stopped working
What are the potential problems?
I will try all the solutions just hope it works well in any way

this is my serial monitor

And what do you mean by powering my board and the peripherals ?

Please copy the output from your serial monitor as text, and paste it between triple backticks, rather than posting screenshots.

Have you tried adding-in your problematic functions one at a time, then commenting out pieces of the problem function until you identify the issue?

How are you powering your devices? Is your power supply up to the task?

Pete.

16:05:27.786 -> [0] 
16:05:27.786 ->     ___  __          __
16:05:27.832 ->    / _ )/ /_ _____  / /__
16:05:27.880 ->   / _  / / // / _ \/  '_/
16:05:27.880 ->  /____/_/\_, /_//_/_/\_\
16:05:27.928 ->         /___/ v1.0.1 on Arduino Uno
16:05:27.974 -> 
16:05:28.401 -> [587] Connecting to Ahmad
16:05:31.494 -> [3666] 0018000902
16:05:40.635 -> [12809] 192.*******
16:05:40.635 -> [12809] Connected to WiFi
16:05:41.490 -> [13648] Ready (ping: 44ms).
16:05:53.722 -> [25862] Ready (ping: 45ms).
16:06:10.415 -> [42530] Ready (ping: 45ms).
16:06:21.397 -> [53483] Ready (ping: 44ms).

It works fine when I delete the void Soilph () parts.

the arduino connected to my laptop
As for the relay, it is connected to a 12V battery, as the water pump needs 12V

So, you seem to have reverted to not fully answering my questions.

Also, you have much more than an Arduino in the equation, yet you seem reluctant to discuss your wiring schematic in detail. That’s fine by me, you can sort out any potential power issues yourself.

Pete.

not like that
I didn’t understand you meant to share the wiring details
also i didn’t understand this part.

my English is not very good

Please take a look this is how the parts are connected

water pump with Relay :
GND >> GND
Vcc>> 3.3v
S >> A5

soil moisture sensor:
GND >> GND
Vcc>> 3.3v
D0>> A0

Ultrasonic sensor:
GND >> GND
Vcc>> 3.3v
Trig >> pin 12
echo>> pin 13

Soil pH sensor:
Vcc>> 3.3 v
GND >> GND
R0 >> pin 2
D1 >> pin 3
RE >> pin 8
DE >> pin 7

ESP8266:
TX >> 10
RX >> 11
GND >> GND
Vcc >> 5 v
CH_PD >> 5 v

Try to change 1000 to 2500 because you already have Wlevel at same time

Thank you
I just did it
But the problem is still the same :tired_face:

1 Like

Try that :
move timers to BLYNK_CONNECTED()

void setup() {
  Serial.begin(9600);
  EspSerial.begin(ESP8266_BAUD);
 
  Blynk.begin(auth, wifi, ssid, pass);
  mod.begin(4800);
  pinMode(RE, OUTPUT);
  pinMode(DE, OUTPUT);
  pinMode(RELAY_PIN, OUTPUT);
  
    // Waterlevel
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  }

 void loop(){
  Blynk.run();      
  timer.run();        
}

BLYNK_CONNECTED() {
  timer.setInterval(20000L, Soilph);
  timer.setInterval(1000L, Wlevel);
  timer.setInterval(10000L, Clockdispla);
  timer.setInterval(2500L, SoilMoisture);
}
1 Like

I still have the same problem
When I remove theSoilph() void private part.
The code works fine
The strange thing is that the Soilph() part also works when I put it in a program alone
But when I put them together it doesn’t work

But with my code, do you see blynk connected in your serial monitor ?
because timers can’t work until blynk is connected
please let us see your serial printing

image

Not possible !

add :

BLYNK_CONNECTED() {
  Serial.print ("Blynk is OK !" );
  timer.setInterval(20000L, Soilph);
  timer.setInterval(1000L, Wlevel);
  timer.setInterval(10000L, Clockdispla);
  timer.setInterval(2500L, SoilMoisture);
}

image

Ok so blynk disconnect every ~10 seconds !

i think yes!