I don’t think I need to visit any barber this year. I changed the code again to the following below and the relay is working properly and now I’m back to Notification, which is not showing in the Blynk app.
What am I missing that is not sending notification to Blynk app?
//Declaration of devices and Timer.
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
//#include <SimpleTimer.h>
#define BLYNK_PRINT Serial
//Blynk online details.
char auth[] = "XXXX"; //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(D0); //Read Flame5Pin_1
int val_2 = digitalRead(D1); //Read Flame5Pin_2
int val_3 = digitalRead(D2); //Read Flame5Pin_3
if (val == 1) {
if (digitalRead(val_1) == HIGH)
digitalWrite(D0, HIGH);
Serial.println("Button 1 is pressed.");
Blynk.notify("FIRE in Room 1");
if (digitalRead(val_2) == HIGH)
digitalWrite(D1, HIGH);
Serial.println("Button 2 is pressed.");
Blynk.notify("Fire in Room 2");
if (digitalRead(val_3) == HIGH)
digitalWrite(D2, 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);
pinMode(D1,INPUT);
pinMode(D2,INPUT);
//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();
}
Are you getting the Serial.println("Button 1 is pressed."); in your monitor?
If not, then the code is not executing the notification part of the code.
Where does val get set? if (val == 1){
Try changing int val; to int val = 1;
Also, you read the state of the pin and store it as a variable, but then just read the state of the pin for the if statement. Doesn’t make much sense to me? I would Either not store the pin state as a variable, or use them in the if statement.
void Flame5(void){
int val_1 = digitalRead(D0); //Read Flame5Pin_1
int val_2 = digitalRead(D1); //Read Flame5Pin_2
int val_3 = digitalRead(D2); //Read Flame5Pin_3
if (val == 1) {
if (val_1 == HIGH)
digitalWrite(D0, HIGH);
Serial.println("Button 1 is pressed.");
Blynk.notify("FIRE in Room 1");
if (val_2 == HIGH)
digitalWrite(D1, HIGH);
Serial.println("Button 2 is pressed.");
Blynk.notify("Fire in Room 2");
if (val_3 == HIGH)
digitalWrite(D2, HIGH);
Serial.println("Button 3 is pressed.");
Blynk.notify("Fire in Room 3");
}
}
I would also try to be a bit more consistent with stuff. first you use Flame5Pin_1, but then later you use D0?
How am I storing this not sure it would help if you explain more. I have copy pasted from every source I found to make the notification on Blynk app work. Now I’m completely lost.
OK Now I am getting a different error @Toro_Blanco. I have changed to if (val=1) by removing a = and the
notification is working back on to normal but look at the image below, it’s working a bit too much as it’s always notifying as marked below… What did I do wrong now :(
What is the error? It is doing exactly what your code is telling it to do. That is, every .5 seconds check the state of the pins, if they are high send notification.
As mentioned you need to learn about coding. There isn’t always an exact piece of code out there waiting for you to cut and paste.
As a hint you need to learn about flags. Although I suspect you need to learn about a lot more as far as programming goes. I suggest a few YouTube videos on some Arduino programming basics.
I think you may have bit off a little more then you can chew.
Start with some simple examples/projects, and once you have a better understanding of how to do things come back to this project. It will make things much easier.
The 5 Way Flame Sensor triggers the val to High, this is what I need. When it gets triggered to High, I need Blynk to notify on app, not before or without.
Hope I was able to explain myself. But now I think I modified it in a wrong way, as a result of which this trigger is notifying even when the 5 Way Flame Sensor is Low. What it is?
I am sorry, I have taken all your advice. I never meant to disobey it. Please point me if I didn’t, as I am a newbie and might miss interpetate.
All I did was changed the signal value to Low and it stated to function just like I wanted it to be. The relay as well is turning On and Off.
Please, advice I don’t want to kill anyone.