hi blynkers,
I am trying to notify via a message to the user using blynk when there is an lpg leak. But I am not able to find whats wrong with this code anyhow there were no error during compilation but still the notification is not coming. I am using MQ 6 gas sensor and Arduino uno connected to blynk using usb.
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
=>
=> USB HOWTO: http://tiny.cc/BlynkUSB
=>
Simple push notification example
App project setup:
Push widget
Connect a button to pin 2 and GND...
Pressing this button will also push a message! ;)
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT SwSerial
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
#include <BlynkSimpleStream.h>
int GAS_DO = 7;
int sensorThres = 500;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "dfe8ce156c5a4a1990fb55bb91326ded";
void notifyOnlpg()
{
// Invert state, since button is "Active LOW"
//Blynk.virtualWrite(V2,GAS_DO );
int GAS_DO= !digitalRead(7);
if (GAS_DO == LOW) {
SwSerial.println(" LPG LEAKAGE");
// Note:
// We allow 1 notification per 15 seconds for now.
Blynk.notify("DANGER");
}
}
void setup()
{
// 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 notification button on pin 7
pinMode(7, INPUT_PULLUP);
// Attach pin 2 interrupt to our handler
attachInterrupt(digitalPinToInterrupt(7), notifyOnlpg, CHANGE);
}
void loop()
{
Blynk.run();
}
Does the MQ6 produce a simple Digital HIGH / LOW for Gas / NoGas? If not then you need a proper library and/or interpretation code.
And your notification routine has no preventative measures from potentially broadcasting each and every time a state change happens on your interrupt. Likely to be more than once in every 15 seconds, particularly when testing
I recommend that you SEARCH this forum for others whom have asked similar questions and/or have similar projects, and read what they determined, then try it out.
After that if you have further questions then post them here with details, not just ask us to do your troubleshooting for you
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
=>
=> USB HOWTO: http://tiny.cc/BlynkUSB
=>
Simple push notification example
App project setup:
Push widget
Connect a button to pin 2 and GND...
Pressing this button will also push a message! ;)
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT SwSerial
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
#include <BlynkSimpleStream.h>
int D1 = 7;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "dfe8ce156c5a4a1990fb55bb91326ded";
// Corresponding Password
int gas_value;
int gas_avalue;
void setup()
{
pinMode(7, INPUT);
SwSerial.begin(9600);
Serial.begin(9600);
Blynk.begin(Serial, auth);
}
void loop()
{
gas_avalue = digitalRead(7);
//Blynk.notify("danger");
if (gas_avalue < 1)
{
Serial.println("DANGER!!!!");
Blynk.notify("danger");
}
else
{
Serial.println("NO LEAKAGE");
Blynk.notify("no danger");
}
delay(100);
Blynk.run();
}
if I unquote this line the notification is coming but irrespective of the sensor value
I want it to be like I need to a get a notification if the sensed value by the sensor exceeds a particular value
No, you made the matter worse!
I your first code example, the Blynk notification would occur each time the state of the gas detector changed. If it detected gas, then it didn’t, within 15 seconds of each other, two Blynk notificvations would be sent withion 15 seconds of each other.
With your latest code, a Blynk notification send attempt will happen every time your void loop is executed, which will be hundreds of times per second.
Go back to your original code.
You don’t say which Arduino board you’re using, but if it’s an Uno then you only have two pins that can be used for interrupts. These are 2 and 3. You’re attempting to use pin 7 as an interrupt.
Your original code is also using the variable GAS_DO to both identify the pin that the D0 output of your sensor is connected to, and to store the reading that you’re getting from that pin. As it happens, you’re not referencing the GAS_D0 pin when you do the digitalRead, instead you’re specifying the pin number directly.
As a result, you can delete these two lines:
The sensor threshold would only be used if you were using the A0 (Analogue) output of the sensor. With the D0 output, the threshold is set using the trimpot on the sensor board.