#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
// These are the interrupt and control pins for СС3000
#define ADAFRUIT_CC3000_IRQ 3
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10
#include <SPI.h>
#include <Adafruit_CC3000.h>
#include <BlynkSimpleCC3000.h>
#include <SimpleTimer.h>
//------------------------
#include <string.h>
#include<stdlib.h>
#include “utility/debug.h”
#include “DHT.h”
#include <avr/wdt.h>
// temperature and humidity sensor
#define DHTPIN 7
#define DHTTYPE DHT22
int gas_status;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = “ee25eeb01b334bb695c01da8c27a675d”;
// Your WiFi credentials.
// Choose wifi_sec from WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
char ssid[] = “Shahbaz”;
char pass[] = “pakistan123”;
int wifi_sec = WLAN_SEC_WPA2;
SimpleTimer timer;
//-----------------------------------------------------
// Define variable and pins for sensors
const int sensorPin[] = {22, 24, 26, 28, 30 };
int Gassensor = 6;
// For temperature and humidity
DHT dht(DHTPIN, DHTTYPE);
//-------------------------------------------------------
void setup()
{
//------------------------------------------
for (byte idx = 0; idx < 5; idx++) {
pinMode(sensorPin[idx], INPUT);
}
//Configured this pin 6 as input for Gas sensor
pinMode(Gassensor, INPUT);
//----------------------------------------------------
Serial.begin(9600);
Blynk.begin(auth, ssid, pass, wifi_sec);
// Setup a function to be called every 30 second
timer.setInterval(30000L, myTimerEvent);
}
void loop()
{
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer
}
// This function sends Arduino’s up time every second to Virtual Pin (5).
// In the app, Widget’s reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
// You can send any value at any time.
// Please don’t send more that 10 values per second.
// Get data from DHT 22 & transform to integers
//------------------------------------------------
float h = dht.readHumidity();
float t = dht.readTemperature();
//------------------------------------
//Get data from gas sensor
int g = digitalRead(Gassensor);
if(g==0)
{
gas_status = 1;
}
else
{
gas_status = 0;
}
//--------------------------------------------
//Get data from flame sensor
bool anySensor = false;
for (byte idx = 0; idx < 5; idx++) {
if (digitalRead(sensorPin[idx])) {
anySensor = true;
}
}
int fireState=anySensor;
//------------------------------------------------------
// print data collected by sensors on serial monitor
Serial.print("Temperature = ");
Serial.println(t);
Serial.print("Humidity = ");
Serial.println(h);
Serial.print("Gas Status = ");
Serial.println(gas_status);
Serial.print("FlameStatus = ");
Serial.println(fireState);
//-----------------------------------------------
int temperature = (int) t;
int humidity = (int) h;
String tem=String(temperature, DEC); //Thingspeak only data stream is string type
String hum=String(humidity, DEC); // Converting integer data to string
String gas=String(gas_status, DEC);
String flame=String(fireState, DEC);
Blynk.virtualWrite(V0, tem, hum, flame, gas);
}