Hi,
I am unable to pull up Blynk notification from the code given below.
The code is running fine and also the hardware is responding but the Blynk app is not notifying. Can you please help?
//Declaration of devices and Timer.
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#define BLYNK_PRINT Serial
int flag=0;
//Blynk online details.
char auth[] = "XXX"; //Auth code sent via Email
char ssid[] = "XXXX"; //Wifi name
char pass[] = "1XXXX"; //Wifi Password
//char server[] = "Server address here";
//Pin description.
#define relay D8 //Relay is connected to D8 pin of Esp8266
#define Flame5Pin_1 D0 //5way is connected to D0 pin of Esp8266
#define Flame5Pin_2 D1 //5way is connected to D1 pin of Esp8266
#define Flame5Pin_3 D2 //5way is connected to D2 pin of Esp8266
int Flame5State; //Define 5Way Flame Sensor state
int val; //Set value
///int x;
SimpleTimer timer;
///BLYNK_CONNECTED() {
///Blynk.syncVirtual(V0); //Virtual Pin define.
// }
//Blynk Virtual Pin define.
///BLYNK_WRITE(V0){
///x = param.asInt();
///}
//Blynk read
void Flame5val(){
int val_1 = digitalRead(Flame5Pin_1); //Read Flame5Pin_1
int val_2 = digitalRead(Flame5Pin_2); //Read Flame5Pin_2
int val_3 = digitalRead(Flame5Pin_3); //Read Flame5Pin_3
if ((val_1 == HIGH) || (val_2 == HIGH) || (val_3 == HIGH)) {
digitalWrite(relay, HIGH);
flag=1;
}
else {
digitalWrite(relay, LOW);
flag=0;
}
}
//Blynk notify set.
void Flame5(void){
if (val == 1) {
if (digitalRead(Flame5Pin_1) == HIGH)
Blynk.notify("FIRE in Room 1");
if (digitalRead(Flame5Pin_2) == HIGH)
Blynk.notify("Fire in Room 2");
if (digitalRead(Flame5Pin_3) == HIGH)
Blynk.notify("Fire in Room 3");
flag=1;
}
}
void setup(){
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
//Blynk.begin (auth, ssid, pass, server, 8080);//local server
// You can change server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
pinMode(relay, OUTPUT); //Relay output in Pin D8
pinMode(Flame5Pin_1, INPUT); //Flame5Pin D0
pinMode(Flame5Pin_2, INPUT); //Flame5Pin D1
pinMode(Flame5Pin_3, INPUT); //Flame5Pin D2
timer.setInterval(3000L,Flame5val);
delay(100);
//Set Timer interval.
timer.setInterval(2000L, Flame5val);
timer.setInterval(3000L, Flame5);
}
//Loop set.
void loop(){
Blynk.run();
timer.run();
}
Your post doesn’t appear grey to me, and your user privileges appear normal.
There are several things wrong with your code, but as you know I’m not prepared to get involved in this project so I’ll leave to to others to help you with it - assuming that they are prepared to get involved.
@PeteKnight Bro you make me sound like a Terrorist or something. Trust me I am doing this for a good cause and, I have already spent so much and I can’t get any notification on Blynk app. After hearing those details from you I have even completely disconnected Blynk from the main fire system and used a custom Buzzer for each floor separating it from the main fire alarm system. I am not that bad as you might think man.
@Gunner Thanks.
I have found that in Blynk if I write INPUT_PULLUP it sends notification to Blynk notification app. But if I use it alone without writing INPUT the code fails to compile. I am unable to get any notification on the Blynk app or in the Serial monitor.
I tried and fixed this.
Now when I try to compile the below code it works, as in compiles but when I upload it, the Blynk notification doesn’t work and also it keeps the Relay Module on at all time.
//Declaration of devices and Timer.
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
//#include <SimpleTimer.h>
#define BLYNK_PRINT Serial
//Blynk online details.
char auth[] = "XXX"; //Auth code sent via Email
char ssid[] = "XXX"; //Wifi name
char pass[] = "XXX"; //Wifi Password
//char server[] = "Server address here";
//Pin description.
#define relay D8 //Relay is connected to D8 pin of Esp8266
#define Flame5Pin_1 D0 //5way is connected to D0 pin of Esp8266
#define Flame5Pin_2 D1 //5way is connected to D1 pin of Esp8266
#define Flame5Pin_3 D2 //5way is connected to D2 pin of Esp8266
//int Flame5State; //Define 5Way Flame Sensor state
int val; //Set value
///int x;
BlynkTimer timer;
///SimpleTimer timer;
///BLYNK_CONNECTED() {
///Blynk.syncVirtual(V0); //Virtual Pin define.
// }
//Blynk Virtual Pin define.
///BLYNK_WRITE(V0){
///x = param.asInt();
///}
//Blynk read
void Flame5val(){
int val_1 = digitalRead(Flame5Pin_1); //Read Flame5Pin_1
int val_2 = digitalRead(Flame5Pin_2); //Read Flame5Pin_2
int val_3 = digitalRead(Flame5Pin_3); //Read Flame5Pin_3
if ((val_1 == HIGH) || (val_2 == HIGH) || (val_3 == HIGH)) {
digitalWrite(relay, HIGH);
}
else {
digitalWrite(relay, LOW);
}
}
/*
//New Format for notify
void notifyOnFlame0Press()
{
// Invert state, since button is "Active LOW"
int isButtonPressed = !digitalRead(D0);
if (isButtonPressed) {
Serial.println("Button 0 is pressed.");
// Note:
// We allow 1 notification per 15 seconds for now.
Blynk.notify("FIRE in Room 1");
}
void notifyOnFlame1Press()
{
// Invert state, since button is "Active LOW"
int isButtonPressed = !digitalRead(D1);
if (isButtonPressed) {
Serial.println("Button 1 is pressed.");
// Note:
// We allow 1 notification per 15 seconds for now.
Blynk.notify("FIRE in Room 2");
}
void notifyOnFlame2Press()
{
// Invert state, since button is "Active LOW"
int isButtonPressed = !digitalRead(D2);
if (isButtonPressed) {
Serial.println("Button 2 is pressed.");
// Note:
// We allow 1 notification per 15 seconds for now.
Blynk.notify("FIRE in Room 3");
}
*/
//Blynk notify set.
void Flame5(void){
int val_1 = digitalRead(Flame5Pin_1); //Read Flame5Pin_1
int val_2 = digitalRead(Flame5Pin_2); //Read Flame5Pin_2
int val_3 = digitalRead(Flame5Pin_3); //Read Flame5Pin_3
if (val == 1) {
if (digitalRead(val_1) == HIGH)
Serial.println("Button 1 is pressed.");
Blynk.notify("FIRE in Room 1");
if (digitalRead(val_2) == HIGH)
Serial.println("Button 2 is pressed.");
Blynk.notify("Fire in Room 2");
if (digitalRead(val_3) == HIGH)
Serial.println("Button 3 is pressed.");
Blynk.notify("Fire in Room 3");
}
}
void setup(){
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
//Blynk.begin (auth, ssid, pass, server, 8080);//local server
// You can change server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
pinMode(relay, OUTPUT); //Relay output in Pin D8
//pinMode(Flame5Pin_1, INPUT); //Flame5Pin D0
//pinMode(Flame5Pin_2, INPUT); //Flame5Pin D1
//pinMode(Flame5Pin_3, INPUT); //Flame5Pin D2
pinMode(D0,INPUT_PULLUP);
pinMode(D1,INPUT_PULLUP);
pinMode(D2,INPUT_PULLUP);
//timer.setInterval(3000L,Flame5val);
//Set Timer interval.
timer.setInterval(500L, Flame5val);
delay(100);
timer.setInterval(1000L, Flame5);
}
//Loop set.
void loop(){
Blynk.run();
timer.run();
}
A relay is either Active HIGH - energised when the signal pin is 3.3v or 5v… depending on MCU type
Or Active LOW - energised when the signal pin is 0v or Grounded.
So first determine how your relay works, then set your pinMode(pin, OUTPUT); as basic OUTPUT and handle the rest with a followup command digitalWrite(pin, LOW); or digitalWrite(pin, HIGH);