Hello guys, thanks for spending time here and reading this post.
Lets begin:
I am creating a project something like fire detection system by using:
- Arduino UNO
- ESP 8266 (ESP-01)
- Red LED
- Buzzer
- MQ2
- DHT11
- IR Flame sensor
Basically I am able to connect with Blynk application if there are only 2 sensors working (etc. mq2&dht11 only). Every hardware is working fine. I am really new in this field and not sure if I had flood the server and causing me keep on disconnecting and not able to let it works. Or maybe other factor that causing it. Please help…
Below is my codes:
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <dht11.h>
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
ESP8266 wifi(&EspSerial);
char auth[] = "";
char ssid[] = "";
char pass[] = "";
BlynkTimer timer;
dht11 DHT11;
#define ESP8266_BAUD 9600
#define DHT11PIN 4
#define buzzer 12//buzzer to pin12
#define redLED 13//redLED to pin13
WidgetLCD lcd (V2);
void setup() {
Serial.begin(9600);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
pinMode(redLED, OUTPUT);//act as an output
pinMode(buzzer, OUTPUT);
Blynk.begin(auth, wifi, ssid, pass);
timer.setInterval(5000L, MQ2sensor);//timer will run every 5 sec
timer.setInterval(6000L, IRsensor);
timer.setInterval(7000L, DHT11sensor);
}
void loop()
{
Blynk.run();
timer.run();
}
void MQ2sensor()
{
int mq2Value = analogRead(A0);
Blynk.virtualWrite(V1, mq2Value);
Serial.print("Smoke & Gases: ");
Serial.println(mq2Value);
}
void IRsensor()
{
int flame = analogRead(A2);//read flame sensor reading at pin A2
Serial.print("IR Sensor Value: ");
Serial.println(flame);
if (flame > 800)
{
lcd.clear();
lcd.print(0,0,"MY Room");
lcd.print(0,1,"Condition:Normal");
digitalWrite(buzzer, LOW);
digitalWrite(redLED, LOW);
}
else
{
lcd.clear();
lcd.print(0,0,"ALERT!");
lcd.print(0,1,"FIRE Detected!");
Serial.println("Flame detected!");
digitalWrite(buzzer, HIGH);
digitalWrite(redLED, HIGH);
Blynk.notify("Flame detected!Please ACT IMMEDIATELY.");
}
}
void DHT11sensor()
{
int chk = DHT11.read(DHT11PIN);
float t = DHT11.temperature;
float h = DHT11.humidity;
Serial.print("Temperature (C): ");
Serial.println(t, 1);
Serial.print("Humidity (%): ");
Serial.println(h);
Serial.println("");
Blynk.virtualWrite(V3,t);
Blynk.virtualWrite(V4,h);
if(h < 50 || h > 90 || t < 20 || t > 35)
{
digitalWrite(buzzer,HIGH);
digitalWrite(redLED, HIGH);
Blynk.notify("Alert!Surrounding reading abnormal.");
}
else
{
digitalWrite(buzzer,LOW);
digitalWrite(redLED, LOW);
}
}
BLYNK_WRITE(V12)
{
short alarmstatus = param.asInt();
if(alarmstatus == HIGH)
{
digitalWrite(buzzer,HIGH);
digitalWrite(redLED,HIGH);
}
else
{
digitalWrite(buzzer,LOW);
digitalWrite(redLED,LOW);
}
}