Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

#define BLYNK_TEMPLATE_ID "TMPL3jt7uKEk6"

#define BLYNK_TEMPLATE_NAME "gas leakage detection"


#define BLYNK_AUTH_TOKEN "t32age9ZiWWutwve3Dq5TE1sLokNEOip"

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#include "Wire.h"
#include "Adafruit_GFX.h"
#include "OakOLED.h"
#include<ESP8266_ISR_Servo.h>
#include<Servo.h>
Servo servo;

#define REPORTING_PERIOD_MS 1000


OakOLED oled;

char auth[] = BLYNK_AUTH_TOKEN;

char ssid[] = "say no to supriya's wifi-2.4G"; // type your wifi name


char pass[] = "sweetnut@123"; // type your wifi password
int smokeA0 = A0;
int data = 0;
int sensorThres = 100;
#define Buzzer D6

BlynkTimer timer;

void sendSensor(){

int data = analogRead(smokeA0);


Blynk.virtualWrite(V0, data);
Serial.print("Pin A0: ");
Serial.println(data);

if(data <= 600)


{
digitalWrite(Buzzer, HIGH);
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(1);
oled.setCursor(0, 0);

oled.println(" GAS LEVEL MONITER gas levels are under


safe limits");
oled.display();

oled.setTextSize(1);
oled.setTextColor(1);
oled.setCursor(12,45);
servo.write(0);
Blynk.virtualWrite(V0, data);
oled.print(" GAS LEVELS: ");
oled.println(data);
oled.display();

}
else{

Blynk.logEvent("gas_alert","Gas Leakage Detected");


digitalWrite(Buzzer, LOW);
servo.write(180);

oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(1);
oled.setCursor(0, 0);

oled.println(" GAS LEVEL MONITER ALERT!!! gas levels have


exceeded safe limits");
oled.display();

oled.setTextSize(1);
oled.setTextColor(1);
oled.setCursor(12,55);

Blynk.virtualWrite(V0, data);
oled.print(" GAS LEVELS: ");
oled.println(data);
oled.display();
}
}

void setup()
{
pinMode(smokeA0, INPUT);
pinMode(Buzzer, OUTPUT);
servo.attach(0); //D3
servo.write(0);
delay(2000);
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
//dht.begin();
timer.setInterval(2500L, sendSensor);
Serial.begin(115200);
oled.begin();
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(1);
oled.setCursor(0, 0);

oled.println("Initializing...");
oled.display();

pinMode(16, OUTPUT);
Blynk.begin(auth, ssid, pass);
}

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

You might also like