How to add blynk specific code in arduino code to control the arduino using blynk app

Details :
• ARDUINO UNO + ESP8266
• Smartphone OS (Android) + BLYNK
• Blynk server

I want the MQ2 sensor connected to A5 and the flame sensor connected to D10 show their value on blynk using ‘gauge’. I want to use ESP8266 WIFI MODULE TO ESTABLISH COMMUNICATION between arduino and blynk server. How could i easily modify my tweet?
In analog else statement i want to add tweet, email and notification option from blynk and in digital , in if & then else statement , i want to add the same features.


int greenLed = 9;
int redLed = 7;
int exhaust = 6;
int buzzer = 8;
int smokeA0 = A5;
int sensorThres = 375; //Change this thresold value according to required sensitivity and speed of response
int flamePin = 10;
int Flame = HIGH;

void setup() 
{
pinMode(greenLed, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(exhaust, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
pinMode(flamePin, INPUT);

Serial.begin(9600);
}

void loop() 
{
int analogSensor = analogRead(smokeA0);
Serial.print("Pin A0: ");   
Serial.println(analogSensor);
if (analogSensor > sensorThres)
{
digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
digitalWrite(exhaust, HIGH);
digitalWrite(buzzer, HIGH);

}
else
{
digitalWrite(greenLed, HIGH);
digitalWrite(redLed, LOW);
digitalWrite(exhaust, LOW);
digitalWrite(buzzer, LOW);
}
delay(100);
{
Flame = digitalRead(flamePin);
if (Flame == HIGH)
{
digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
digitalWrite(exhaust, HIGH);
digitalWrite(buzzer, HIGH);
}
else
{
digitalWrite(greenLed, HIGH);
digitalWrite(redLed, LOW);
digitalWrite(exhaust, LOW);
digitalWrite(buzzer, LOW);
}
}
{
 Flame = digitalRead(flamePin);
 if (Flame == LOW)
{
digitalWrite(greenLed, HIGH);
digitalWrite(redLed, LOW);
digitalWrite(exhaust, LOW);
digitalWrite(buzzer, LOW);
}
else
{
digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
digitalWrite(exhaust, HIGH);
digitalWrite(buzzer, HIGH);

}
}
}

My advice first advice would be to throw away the Uno and ESP-01 and use a NodeMCU or Wemos D1 Mini instead.

Then, I would be to search this forum for other projects that use this sensor, with whatever board you choose to use, and use that code as a starting point.

https://community.blynk.cc/search?q=MQ2

If you want to stick with the original plan the start by reading this:
http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/keep-your-void-loop-clean

and look at the Sketch Builder examples here:

Pete.

1 Like