BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Need Help In Flag with Blynk Notification


#1

Before creating the topic

  1. Search forum for similar topics
  2. Check http://docs.blynk.cc and http://help.blynk.cc/
  3. Add details :
    • Hardware model + communication type. For example: Arduino UNO with Ethernet Shield
    • Smartphone OS (iOS or Android) + version
    • Blynk server or local server
    • Blynk Library version
    • Add your sketch code. :point_up:Code should be formatted as example below.

Simply paste your code between ``` If you don’t format your code, your topic can be deleted by moderators.


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

// defines pins numbers
#define echoPin D3                         
#define trigPin D4
                            
// defines variables
long Duration, Distance;
int FlageState = 0 ; // set flageState to false                         
WidgetLCD lcd(V1);
const unsigned int Period = 2500;      

char auth[] = "xxxxxxx";
char ssid[] = "xxx";
char pass[] = "xxx";

SimpleTimer timer;

void sendSensorReadings()
{
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);

  digitalWrite(trigPin, LOW);
  Duration = pulseIn(echoPin, HIGH);

  Distance = ((Duration / 2) / 29.1);

// Initiates Blynk
  Blynk.virtualWrite(1, Distance);            

 Serial.println();
    Serial.println();
    Serial.println("Distance Cm: " + String(Distance));                                   

 if(Distance >= 30 ) 
{  
  FlageState = 1; 
 
  }
  else if (Distance < 3 ) {
   Serial.println("Out of Range");
   lcd.clear();
   lcd.print(0,0,"Distance in cm");
   Serial.print(Distance);
   Serial.println("Cm");
   lcd.print(7, 1, Distance);
  }

}

void setup() 
{
  timer.setInterval(Period, sendSensorReadings); //Repeat 5 times    
 
  Serial.begin(9600);                                
  Serial.println("Start");
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  Blynk.begin(auth, ssid, pass);
    while (Blynk.connect() == false) {
     //Wait until connected
     //Serial.print("x");
   }
  if (FlagState == 1){
  Blynk.notify("Dustbin is almost full"); 
  Serial.println("Dustbin is almost full");
  Serial.print(Distance);
  Serial.println(" cm");
  
  lcd.clear();
  lcd.print(0,0,"Distance in cm");
  Serial.print(Distance);
  Serial.println("Cm");
  lcd.print(7, 1, Distance);
  
  }
 
  lcd.clear();
  lcd.print(0, 0, "Distance in cm"); 
  Blynk.setProperty(V2, "min", 3); // Distance
  Blynk.setProperty(V2, "max", 100);
}

void loop() {
  
  Blynk.run();
  timer.run();
  delay(3500); // cek whether can cancel
    
}

Hi everyone, Currently i’m working on my final year project using nodeMcu.
I want to Display notification once the distance from ultrasonic sensor is more than 30cm.
But now i manage to produce the notification in blynk app but unfortunately, it works like spam… like it repeat so many time.
So, i want to use flag to set that the blynk will display notification only when the distance more than 30 cm.
I don’t know how to used flag… Please share ur knowledge… Tq so much…


#2
if(Distance >= 30 ) 
{  
  FlageState = 1; 
   }else{
 FlageState = 0; 
  }

if (Distance < 3 ) {
   Serial.println("Out of Range");
   lcd.clear();
   lcd.print(0,0,"Distance in cm");
   Serial.print(Distance);
   Serial.println("Cm");
   lcd.print(7, 1, Distance);
 }

never put that in the loop

delay(3500); // cek whether can cancel

it is better to increase periode to 5000


#3

I don’t think a flag is really required for such a simple range exclusion… a basic if() else will suffice.

Distance = ((Duration / 2) / 29.1);
  if (Distance >= 30 ) {
  // do something
  } else {
  // don't do anything
  }

#4

Cool ! @Alexis_Cabrera,
Tq so much sir… Really appreciate your sharing… it just display as i want !


#5

Tq so much sir for your help… @Gunner.
It turn out so great…

Sir, if i have another question regarding blynk can i just post in same topic but not related with the title?


#6

Generally it is about keeping a topic to a specific issue… But in your case your titles are a bit misleading as you are not needing help on any single concept but rather more a general lack of programming experience throughout your project as a whole.

So in this case I would almost prefer to keep it all in one topic that is all about your bin sensor.

I may merge this one back in with your prior one??.. I will think on that. EDIT - I will leave this as is and mark it solved

Meanwhile what is your next question… :slight_smile: EDIT - I did move this to another topic as it seems a totally different issue :smiley:


#7

A post was split to a new topic: I have issue in display latitude, longitude data in blynk app