Create Push Notification over Flame Sensor

I have remake the circuit, but I still don’t know if it’s correct or not.

I also remake the sketch, please let me know if I’m wrong.

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#inlclude <Adafruit_ADS1015.h>

#define LDR A1
#define PIR1 D5
#define LED1 D8
#define PIR2 D3
#define LED2 D4

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
 char auth[] = "f40e7c2f2e3245258332dbc89c7e9e78";
 char ssid[] = "Redmi 3s";
 char pass[] = "69AEE473";

 Adafruit_ADS1115 ads(0x48); /* Use this for the 16-bit version */
 //Adafruit_ADS1015 ads;     /* Use thi for the 12-bit version */
 int pirState1; // define numeric variables val for PIR1
 //int ldrValue;

 int pirState2 = 0;// define numeric variables val for PIR2

 //int buzzer = D1 ;// define buzzer Interface
 int flame = D0; // define the flame sensor interface
  //int analoog = A0; // define the flame sensor interface

  int val ;// define numeric variables val
  //float sensor; //read analoog value

  bool isFirstConnect = true;
  SimpleTimer timer;

  void readSensor1()
  {
      int16_t adc0; 
      adc0 = ads.readADC_SingleEnded(0);
      //ldrValue = analogRead(LDR);

      if (adc0 <= 270) { // dark
      digitalWrite(LED1, HIGH);
  }
  else {
       pirState1 = digitalRead(PIR1);
       if (pirState1 == HIGH) {
           digitalWrite(LED1, HIGH);
           delay(1000);
           digitalWrite(LED1, LOW);
           delay(1000);
       }
   else { // pirState1 == LOW
   digitalWrite(LED1, LOW);
   }
   }
   }

   void readSensor2()
   {
      pirState2 = digitalRead(PIR2);
      digitalWrite(LED2,pirState2);

      if (pirState2 == 1)
        digitalWrite(LED2,LOW);
    }

   void readSensor3()
   {
      int16_t adc1;
      adc1 = ads.readADC_SingleEnded(1);  
      //sensor = analogRead(analoog);
      Serial.println(adc1);
      //Serial.println(sensor);  // display temperature
      //long uptime = millis() / 60000L;

      // You can send any value at any time.
      // Please don't send more that 10 values per second.
      Blynk.virtualWrite(V1, millis() / 1000);

      val = digitalRead (flame) ;// 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);
           Blynk.email("nurlela.dabukke@gmail.com", "Flame!!!", "Sensor activated");
        }
       //else
       //{
       // digitalWrite (buzzer, LOW);
       //}
       // Actually send the message.
       // Note:
       //   We allow 1 notification per 15 seconds for now.
       //Blynk.notify(String("Running for ") + uptime + " minutes.");
  }

  void reconnectBlynk() {
       if (!Blynk.connected()) {
           if(Blynk.connect()) {
              BLYNK_LOG("Reconnected");
           } else {
              BLYNK_LOG("Not reconnected");
           }
         }
    }

   void setup()
   {
      pinMode(LED1, OUTPUT);
      pinMode(PIR1, INPUT);
      digitalWrite(LED1, LOW);

      pinMode (LED2,OUTPUT);
      pinMode (PIR2, INPUT);

      //pinMode (buzzer, OUTPUT) ;// define buzzer as output interface
       pinMode (flame, INPUT) ;// output interface defines the flame sensor
      //pinMode (analoog, INPUT) ;// output interface defines the flame sensor

      // Debug console
      Serial.begin(115200);

      Blynk.begin(auth, ssid, pass);
      // You can also specify server:
      //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
      //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

      while (Blynk.connect() == false) { // try to connect to server for 10 seconds
       // Notify immediately on startup
      Blynk.notify("Device started"); 
      // 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 minute
         timer.setInterval(10L, readSensor3);
      }
     // Setup a function to be called every 200ms Costas
     timer.setInterval(150L, readSensor3);  // Costas
     //Blynk.email("nurlela.dabukke@gmail.com", "Flame!!!", "Sensor activated");
  }
  //timer.setInterval(350L, readSensor3);
  timer.setInterval(30000L, reconnectBlynk);  // check every 30s if still connected to server   

  // The ADC input range (or gain) can be changed via the following
  // functions, but be careful never to exceed VDD +0.3V max, or to
  // exceed the upper and lower limits if you adjust the input range!
  // Setting these values incorrectly may destroy your ADC!
  //                                                                ADS1015  ADS1115
  //                                                                -------  -------
  // ads.setGain(GAIN_TWOTHIRDS);  // 2/3x gain +/- 6.144V  1 bit = 3mV      0.1875mV (default)
  // ads.setGain(GAIN_ONE);           // 1x gain   +/- 4.096V  1 bit = 2mV      0.125mV
  // ads.setGain(GAIN_TWO);        // 2x gain   +/- 2.048V  1 bit = 1mV      0.0625mV
  // ads.setGain(GAIN_FOUR);       // 4x gain   +/- 1.024V  1 bit = 0.5mV    0.03125mV
  // ads.setGain(GAIN_EIGHT);      // 8x gain   +/- 0.512V  1 bit = 0.25mV   0.015625mV
  // ads.setGain(GAIN_SIXTEEN);    // 16x gain  +/- 0.256V  1 bit = 0.125mV  0.0078125mV

  ads.begin();
  }

 BLYNK_CONNECTED() {
     if (isFirstConnect) {
         Blynk.syncAll(); 
         Blynk.notify("ADS1115 STARTING!!!!");
         isFirstConnect = false;
     }
 }

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

3 posts were split to a new topic: Problem with Notifications