Create Push Notification over Flame Sensor

not very relaible. i mean not realtime.
as i said, create a sketch containing nothing else just sending the uptime every second.

if you can see that increments somewhat regulalry on phone, for several minutes, that i call a good connection.

The email have been coming. But, itā€™s so long to come.

please try this:

https://examples.blynk.cc/?board=Arduino%20Uno&shield=Serial%20or%20USB&example=GettingStarted%2FPushData

and report back what it does.
edit: i assume you are on uno + usb serial internet
if not, correct it accordingly,

I have make the code as you said:

    #define BLYNK_PRINT SwSerial


    #include <SoftwareSerial.h>
    SoftwareSerial SwSerial(10, 11); // RX, TX
    
    #include <BlynkSimpleStream.h>

    // You should get Auth Token in the Blynk App.
    // Go to the Project Settings (nut icon).
    char auth[] = "******************************************";

    int buzzer = 13 ;// define buzzer Interface
    int pin = 2; // define the flame sensor interface
    int analoog = A0; // define the flame sensor interface
 
    int val ;// define numeric variables val
    float sensor; //read analoog value

    BlynkTimer timer;

    // This function sends Arduino's up time every second to Virtual Pin (5).
    // In the app, Widget's reading frequency should be set to PUSH. This means
    // that you define how often to send data to Blynk App.
    void myTimerEvent()
    {
      sensor = analogRead(analoog);
      Serial.println(sensor);  // display temperature

     val = digitalRead (pin) ;// digital interface will be assigned a value of 3 to read val
     if (val == HIGH) // When the flame sensor detects a signal, buzzer beep
     {
        // You can send any value at any time.
       // Please don't send more that 10 values per second.
       Blynk.virtualWrite(V5, millis() / 1000);
       digitalWrite (buzzer, HIGH);
     }
       else
    {
       digitalWrite (buzzer, LOW);
    }
    }

    void setup()
    {
      pinMode (buzzer, OUTPUT) ;// define buzzer as output interface
      pinMode (pin, INPUT) ;// output interface defines the flame sensor
      pinMode (analoog, INPUT) ;// output interface defines the flame sensor
      // Debug console
     SwSerial.begin(9600);

     // Blynk will work through Serial
     // Do not read or write this serial manually in your sketch
     Serial.begin(9600);
     Blynk.begin(Serial, auth);

     // Setup a function to be called every second
     timer.setInterval(1000L, myTimerEvent);
     }

    void loop()
    {
       Blynk.run();
       timer.run(); // Initiates BlynkTimer
     }

Nothing happened after I upload the sketch. So, what should I do so that the app can be realtime?

As it states in the sketchā€¦ this example sends data to the App on V5ā€¦ so create a Display Widget on Virtual Pin 5 and set itā€™s reading frequency to PUSH (that means it waits until data is PUSHED to it from the Server). Then once your MCU and App are properly connected through the server you will see the seconds add up on the display.

This is an example of how timers can be used in Blynk instead of ā€œmanuallyā€ counting millis() or using delay()

I have set the input to V5 and reading frequency to PUSH. But, still nothing value appear on my app. What causes the appā€™s is not real-time?

I donā€™t know, it could be many things.

Have you ever had a basic Blynk example sketch successfully functioning?

Like the one @wanek suggested and I was refering tooā€¦ NOT one where you have tried to merge in your other fire sensor codeā€¦ just the basic Blynk example sketchā€¦

Yes, I have tried that and nothing value appear. But, the app just online if I connect to internet and the email coming on my push notif code. Is it because I use usb serial?

OK, lets focus on that sketch by itself then, no email, no fire sensorā€¦ just load up that example and create a simple project with a single display widget in it, set to V5 and PUSH. Make sure you have the same authcode from that project loaded in the sketch.

You are using an UNO with USB link correct? Do you have a 2nd USB-TTL adapter to use with the software serial for monitoring data on the IDE monitor?

No, I donā€™t have that USB-TTL.

Too badā€¦ it would make your diagnostics easier.

Well, just load up that simple sketch and widget and let me know if it works or not.

By the way, which usb-ttl should I use? Cause I still never use it. Beside, usb-ttl pl2303 and rs232 have same pins.

They all work the same way, but driver support for your PC is probably the most important.

On the USB-TTL there will be Power, and Groundā€¦ this is usually to supply 5v power from the USB the board you are connecting toā€¦ and both can be ignored (donā€™t plug them into anything) in this case, as your Arduino is already getting power from itā€™s own USB connector.

The TX (usually green) & RX (usually white) connect to correspondingly opposite RX & TX pins on the Arduino, determined by the software serial setup. This is a simple RS232 connection.

Then I use a program called Termite - Termite: a simple RS232 terminal to display the data from that USB-TTL adapter. In most Blynk example cases, that data is the diagnostic info coming from the Blynk sketch on the Arduino.

Try to avoid the PL2303 if you are using a fairly modern Windows machine. There are a lot of fake chips around and Prolific drivers donā€™t seem to work with Windows 7 and on beyond even for genuine chips.

They can be made to work by using a driver from 2003 but Windows keeps insisting you should use the latest, broken, driver. For me it involves a lot of driver removal and PC reboots to get them to work. You canā€™t simply plug and unplug them or Windows will give you the broken drivers.

Ahh, thatā€™s probably what I am running into thenā€¦ I have to manually direct it to a Pyramid driver, then all works until next rebootā€¦ but since my PC runs 24/7, that is a rare issue (and now that I have ESP, even rarer needed :wink: )

but you can buy one decent version with 0.6 euro:

Best quality 1Pcs USB to TTL converter UART CH340G CH340 3.3V 5V switch replace of CP2102 PL2303 module
http://s.aliexpress.com/eeY3emmI
(from AliExpress Android)

1 Like

@wanek yes the CH340ā€™s are fine. Might get hold of some but I have 20+ PL2303ā€™s to use up.

The PL2303ā€™s are OK if you just want to power up an ESP / MCU rather than actually flash it :slight_smile:

I have try upload push data code with CH340, and the value has been appeared. Is it indicate the connection has been real time?
I also try upload my push notif sketch with CH340. Nothing email coming. Instead, if I just use usb serial, the email coming. But, I have to wait some minutes.

@Maria please provide your sketch that fails i.e the one with CH340.

Do you have Serial Monitor wired up and can you paste the data from it?

Here is my code:

   #define BLYNK_PRINT SwSerial


    #include <SoftwareSerial.h>
    SoftwareSerial SwSerial(10, 11); // RX, TX
    
    #include <BlynkSimpleStream.h>

    // You should get Auth Token in the Blynk App.
    // Go to the Project Settings (nut icon).
    char auth[] = "********************************************";

    int buzzer = 13 ;// define buzzer Interface
    int pin = 2; // define the flame sensor interface
    int analoog = A0; // define the flame sensor interface
 
    int val ;// define numeric variables val
    float sensor; //read analoog value

    BlynkTimer timer;

    void readSensor()   // Costas
    {
      sensor = analogRead(analoog);
      Serial.println(sensor);  // display temperature
      // long uptime = millis() / 60000L;  Costas

     val = digitalRead (pin) ;// digital interface will be assigned a value of 3 to read val
     if (val == HIGH) // When the flame sensor detects a signal, buzzer beep
     {
       digitalWrite (buzzer, HIGH);
     }
       else
    {
       digitalWrite (buzzer, LOW);
    }
      //delay(1000);  // Costas
    }

    void setup()
      {
         pinMode (buzzer, OUTPUT) ;// define buzzer as output interface
         pinMode (pin, INPUT) ;// output interface defines the flame sensor
         pinMode (analoog, INPUT) ;// output interface defines the flame sensor
  
          // Debug console
         SwSerial.begin(9600);

         // Blynk will work through Serial
         // Do not read or write this serial manually in your sketch
         Serial.begin(9600);
         Blynk.begin(Serial, auth);

         // Notify immediately on startup
         if(val==HIGH){
         //Blynk.notify("Flame!!!");
         Blynk.email("nurlela.dabukke@gmail.com", "Flame!!!", "Sensor activated");
       }

       // Setup a function to be called every 200ms Costas
       timer.setInterval(10L, readSensor);  // Costas
       Blynk.email("nurlela.dabukke@gmail.com", "Flame!!!", "Sensor activated");
    }

    void loop()
    {
       Blynk.run();
       timer.run();
    }

But, everytime the flame went out, always there are comment in the app ā€œthe device is offlineā€. If I click serial monitor, the port always busy.
I think, itā€™ll better if I use wemos d1 mini.