Arduino Data Logger & Alarm System

preview_player
Показать описание
Arduino based Data Logger + Alarm System.The system consists of an Arduino Nano+LCD Screen+microSD module+Sensors (Temp-RH+Flame+Gas/Smoke).

Temperature and humidity are displayed in a LCD and measurements taken and stored to a microSD card.

The data can be used for diagrams creation through EXCEL.The system also alarms when gas/smoke or flame is detected.
Рекомендации по теме
Комментарии
Автор

Sensors:
1) DHT11 (Combo Temp+RH)
2) MQ2 (Gas/Smoke)
3) KY-026 (Flame)

ΓιώργοςΤσαλμπούρης-ρβ
Автор

Arduino Code:


* SD CARD + DHT11
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 10 (SDCARD_SS_PIN)
*/

#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"

#define DHTPIN 8 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);

const int chipSelect = 10; //SD CARD CS pin 10

const byte gasPin=2; //gas sensor to pin 2
const byte flamePin=3; //flame sensor to pin 3

boolean flame_flag=LOW; //flags for hardware interrupts ISR
boolean gas_flag=LOW;

LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27

void setup()
{
//GAS-FLAME SENSORS SETUP
pinMode(gasPin, INPUT);
pinMode(flamePin, INPUT);
attachInterrupt(digitalPinToInterrupt(gasPin), gas_ISR, FALLING); //hardware inerrupts
attachInterrupt(digitalPinToInterrupt(flamePin), flame_ISR, RISING);

//LCD INIT CODE
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.setCursor(1, 0); // (column, row)
lcd.print("Temp & Humidity");
delay(1500);
lcd.setCursor(1, 1);
lcd.print("Smoke & Gas");
delay(2000);
lcd.clear();
lcd.setCursor(3, 0); // (column, row)
lcd.print("Detection");
delay(1000);
lcd.setCursor(4, 1);
lcd.print("System");
delay(2000);
lcd.clear();
dht.begin(); //DHT begin

if (!SD.begin(chipSelect))
{
lcd.setCursor(0, 0);
lcd.print("Card Failed");
lcd.setCursor(0, 1);
lcd.print("or missing");
delay(3000);
lcd.clear();
return;
}
lcd.setCursor(0, 0);
lcd.print("SD card OK.");
delay(3000);
lcd.clear();
}

void loop()
{
//CODE for GAS and FLAME Check
while (flame_flag==HIGH || digitalRead(flamePin)==HIGH)
{
flame();
}
while (gas_flag==HIGH || digitalRead(gasPin)==LOW)
{
gas();
}

// DHT MEASUREMENT
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f))
{
lcd.setCursor(0, 0);
lcd.print("Failed to read");
lcd.setCursor(0, 1);
lcd.print("from DHT sensor");
delay(2000);
lcd.clear();
return;
}

//MESSAGE to LCD
lcd.setCursor(0, 0);
lcd.print("Temp=");
lcd.print(t);
lcd.print("C*");

lcd.setCursor(0, 1);
lcd.print("Humidity=");
lcd.print(h);
lcd.print("%");

//SD CARD STORAGE CODE
String dataString = ""; // make a string for assembling the data to log:

// pick sensor values (t, h)
dataString += String(t);
dataString += ", ";
dataString += String(h);

delay(5000);

// open the file.Only one file can be opened at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt", FILE_WRITE);

// if the file is available, write to it:
if (dataFile)
{
dataFile.println(dataString);
dataFile.close();
}
// if the file isn't open, pop up an error:
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Error opening ");
lcd.setCursor(0, 1);
lcd.print("datalog.txt");
delay(3000);
lcd.clear();
}
}

void gas_ISR()
{
gas_flag=HIGH;
}

void flame_ISR()
{
flame_flag=HIGH;
}

void flame()
{
lcd.clear();
lcd.setCursor(1, 0); // (column, row)
lcd.print("Flame");
lcd.setCursor(1, 1);
lcd.print("Detected!!");
delay(3000);
flame_flag=LOW;
lcd.clear();
}

void gas()
{
lcd.clear();
lcd.setCursor(1, 0); // (column, row)
lcd.print("GAS/SMOKE");
lcd.setCursor(1, 1);
lcd.print("Detected!!");
delay(3000);
gas_flag=LOW;
lcd.clear();
}

ΓιώργοςΤσαλμπούρης-ρβ
join shbcf.ru