Problems with notifications (Soil Moisture sensor)

Hi , im having problems receveing notifications on my project, im new with blynk and im doing my school final project with it, i am not receveing a notification when i remove my soil moisture sensor.
Im using a code from the internet and ive been investigating and in the new blynk app 2.0 i need to do notification in the events section, but im missing something it just doesnt pop

Post your whole sketch please.

I’d start by reading this…

Pete.

This my code, when i remove the soil moisture i should be geting a notification when the value goes to 800-1024(Water your plants) but im not getting it.


#define BLYNK_TEMPLATE_ID "TMPL_QaulLhk"
#define BLYNK_DEVICE_NAME "Projeto Final"
#define BLYNK_AUTH_TOKEN ""


#define BLYNK_PRINT Serial   
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#include <SimpleTimer.h>
#include <DHT.h>
#define BLYNK_PRINT Serial
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS D2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

char auth[] ="";               //Authentication code sent by Blynk
char ssid[] = "";  // type your wifi name
char pass[] = "";  // type your wifi password                     //WiFi Password

#define sensorPin D3 
int sensorState = 0;
int lastState = 0;
#define DHTPIN 2    
#define DHTTYPE DHT11     
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
 
  Blynk.virtualWrite(V5, h);  //V5 is for Humidity
  Blynk.virtualWrite(V6, t);  //V6 is for Temperature
}
void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
   pinMode(sensorPin, INPUT);
  dht.begin();

  timer.setInterval(1000L, sendSensor);
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
   sensors.begin();
}
int sensor=0;
void sendTemps()
{
sensor=analogRead(A0);
sensors.requestTemperatures();
float temp = sensors.getTempCByIndex(0); 
Serial.println(temp);
Serial.println(sensor);
Blynk.virtualWrite(V1, temp);
Blynk.virtualWrite(V2,sensor);
delay(1000);
}
void loop()
{
  Blynk.run(); 
  timer.run(); 
  sendTemps();
  sensorState = digitalRead(sensorPin);
Serial.println(sensorState);

if (sensorState == 1 && lastState == 0) {
  Serial.println("needs water, send notification");
  Blynk.logEvent("water_plant","Rega as Plantas!!");
  lastState = 1;
  delay(1000);
//send notification
    
  } 
  else if (sensorState == 1 && lastState == 1) {
    //do nothing, has not been watered yet
  Serial.println("has not been watered yet");
  delay(1000);
  }
  else {
    //st
    Serial.println("does not need water");
    lastState = 0;
    delay(1000);
  }
  
  delay(100);
}

Quoting Pete: Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Then, read some of the docs:

https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean

2 Likes

I’d suggest that you restructure your code to clean-up your void loop, remove all of your blocking delays use BlynkTimer instead of SimpleTimer.

When you’ve done that, re-post your code, along with screenshots which illustrate the event and notification setup, and your timeline from the web console.

Pete.