BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Create Push Notification over Flame Sensor

#186

I have combine the circuit:

And the code:

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#define LDR A0
#define PIR1 11
#define LED1 12
#define PIR2 8
#define LED2 13

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Redmi 3s";
char pass[] = "*********";

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 = 2; // define the flame sensor interface
int analoog = A1; // define the flame sensor interface

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

BlynkTimer timer;

void readSensor1()
{
   ldrValue = analogRead(LDR);

   if (ldrValue <= 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()
{
   sensor = analogRead(analoog);
   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 setup()
 {
    pinMode(LED, 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);

    // 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, readSensor);
  }
  // Setup a function to be called every 200ms Costas
  timer.setInterval(150L, readSensor);  // Costas
  //Blynk.email("nurlela.dabukke@gmail.com", "Flame!!!", "Sensor activated");
 }

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

I want to combine Wemos to Arduino, but I still don’t know how to call the function if I have three functions. By the way, the LDR and both PIR don’t need connect to WiFi. Could you help me to fix it?

0 Likes

#187

You are using the wrong connection method in your sketch.
Take a look at the ESP8266_Shield example but study closely the commented out lines because the sketch is written for a Mega / Leonardo that has more than one serial port. As you are using an Uno you will need to make some changes and just to warn you this connection method can be very difficult to set up.

0 Likes

#188

Then, is it mean the one which connect to PC is wemos? How about setting board on arduino?

0 Likes

#190

From your limited understanding it will be very, very difficult for you to setup the WeMos as a shield.
If I were you I would work more slowly through the WeMos only projects and then consider WeMos as a shield when you are more familiar with ESP’s and Blynk.

0 Likes

#191

Sorry for my limited understanding cause it’s my first time to use Wemos as arduino’s shield. It’s my first time to use Arduino and WiFi board at the same time.
I have remake the sketch:

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266_SSL.h>

#define LDR A0
#define PIR1 11
#define LED1 12
#define PIR2 8
#define LED2 13

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Redmi3s";
char pass[] = "********";

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 = 2; // define the flame sensor interface
int analoog = A1; // define the flame sensor interface

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

BlynkTimer timer;

void readSensor1()
{
   ldrValue = analogRead(LDR);

   if (ldrValue <= 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()
{
   sensor = analogRead(analoog);
   Serial.println(sensor);  // display temperature

   // 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);
     //}
   }

   void setup()
   {
      pinMode(LED, 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);

      // 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, readSensor);
   }
   // Setup a function to be called every 200ms Costas
   timer.setInterval(150L, readSensor);  // Costas
   //Blynk.email("nurlela.dabukke@gmail.com", "Flame!!!", "Sensor activated");
 }

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

Yes, I know. I’ll be careful to setup the circuit.

0 Likes

#192

That is nothing like a shield sketch.

0 Likes

#193

Sorry, I still don’t get what you mean. Is it mean in that sketch, I have to change the board to Arduino Uno with connection Software Serial?

0 Likes

#194

Yes but it also involves many other things like flashing the WeMos with AT firmware etc.

0 Likes

#195

Is it correct if I follow this step for wemos Firmware?

https://wiki.wemos.cc/tutorials:get_started:revert_to_at_firmware#tutorial_-_returning_a_wemos_d1_mini_to_factory_firmware_at

0 Likes

#196

As I have said I would stick with WeMos in standalone mode if I were you.

0 Likes

#197

But, I need arduino since I need two analog pin. If I still use wemos standalone, can I use two analog pins?

0 Likes

#198

Or do you mean I should remove the LDR sensor?

0 Likes

#199

If you need more analogue ports use several WeMos’ with the bridge widget or add a port extender. It will be easier than trying the shield route.

0 Likes

#200

It’ll better if I use port extender. Is PCF8574 chip suitable as port extender for wemos?

0 Likes

#201

Yes if you search this site for PCF8574 you will see other Blynkers are using it.

0 Likes

#202

It seems I can’t use PCF8574 cause that chip just for digital pin not for analog pin. So, I change the chip to ADS1115. ADS1115 can expand analog pin, right?

0 Likes

#203

Yes there are examples on this site like this ADS1115 with Wemos Mini D1

0 Likes

#205

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();
 }
0 Likes

split this topic #206

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

0 Likes

closed #207
0 Likes