Before creating the topic
- Search forum for similar topics
- Check http://docs.blynk.cc and http://help.blynk.cc/
- 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.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…