Spresense XABC Fire Detection

One group, one vision. We are looking forward to present you our project, early forest fire detection with the Sony Spresense boards.

BeginnerWork in progress184
Spresense XABC Fire Detection

Things used in this project

Hardware components

Spresense boards (main & extension)
Sony Spresense boards (main & extension)
×1
Spresense camera board
Sony Spresense camera board
×1
Grove - Gas Sensor(MQ2)
Seeed Grove - Gas Sensor(MQ2)
×1
ESP8266 ESP-01
Espressif ESP8266 ESP-01
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

RedBird

Code

RedBird

Arduino
//Display
#include <Adafruit_ST7735.h>

//Display
#define TFT_RST   8
#define TFT_CS   10
#define TFT_DC    9
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

//LED and Buzzer
#define RED 3
#define YELLOW 4
#define GREEN 5
#define BUZZER 1

//Sensors
#include "DHT.h"
#include <MQ2.h>
#define BAUDRATE (230400)

//Temeratur und Feuchtigkeit
#define DHTTYPE DHT22
#define DHTPIN 2
DHT dht(DHTPIN, DHTTYPE);

//Smoke Sensor
#define SMOKE A0
float lpg, co, smoke;
MQ2 mq2(SMOKE);

//Distance
#define DISTANCE 0

//Define Max values
#define MAX_TEMP 29
#define MAX_SMOKE 15
#define MAX_CO 15


/*
   Simple algorithm to detect fire
   @param t          current temperature
   @param co         current co value
   @param smoke      current smoke value
   @param obstacle   True if an obstacle ist detected else False
*/
boolean detektFire(float t, float co, float smoke, boolean obstacle) {

  if ((t >= MAX_TEMP) or (smoke >= MAX_SMOKE) or (co >= MAX_CO)) {
    if (obstacle == LOW) {
      digitalWrite(YELLOW, HIGH);
    }
    digitalWrite(RED, HIGH);
    digitalWrite(GREEN, LOW);
    tone(BUZZER, 400);
    return true;
  }
  else {
    digitalWrite(YELLOW, LOW);
    digitalWrite(RED, LOW);
    digitalWrite(GREEN, HIGH);
    noTone(BUZZER);
    return false;
  }
}

/*
  his function is used to print the parameters on the Screen.

  @param humidity
  @param temp
  @param lpg
  @param co
  @param smoke
  @param obstacle
  @param fire       take a boolean. True means that a fire is detected.
*/
void printAll(float humidity, float temp, float lpg, float co, float smoke, boolean obstacle, boolean fire) {

  tft.setTextWrap(true);
  tft.fillScreen(ST77XX_BLACK);
  tft.setTextSize(1);
  tft.setTextColor(ST77XX_WHITE);
  tft.setCursor(0, 0);


  tft.println("");
  tft.print("Humid...: ");
  tft.print(humidity);
  tft.print(" %\t");
  tft.println("");
  tft.print("Temp...: ");
  tft.print(temp);
  tft.print(" *C ");
  tft.println("\n");

  tft.print("LPG: ");
  tft.print(lpg);
  tft.println("");
  tft.print("CO: ");
  tft.print(co);
  tft.println("");
  tft.print("Smoke: ");
  tft.print(smoke);
  tft.println("\n");

  tft.print("obstacle: ");
  tft.print(obstacle == LOW ? "Yes" : "NO");
  tft.println("\n");

  tft.print("Fire: ");
  tft.print(fire == true ? "Yes" : "NO");
  tft.println("\n\n");
}


void setup() {
  Serial.begin(BAUDRATE);

  //Starte Sensoren
  pinMode(DISTANCE, INPUT);
  dht.begin();
  mq2.begin();
  
  //Initialisiere Sreen
  tft.initR(INITR_BLACKTAB);
  tft.fillScreen(ST77XX_BLACK);

  //Wilkommens Sreen
  tft.setTextColor(ST77XX_RED);
  tft.setTextSize(3);
  tft.setCursor(2, 50);
  tft.println("RedBird");
  delay(3000);
  tft.fillScreen(ST77XX_BLACK);

}


void loop() {
  //Reed temperatur and humidity
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  //Smoke sensor
  float* values = mq2.read(false);
  lpg = mq2.readLPG();
  co = mq2.readCO();
  smoke = mq2.readSmoke();

  //Distance
  boolean obstacle = digitalRead(DISTANCE);

  
  Serial.print("Humid...: ");
  Serial.print(h);
  Serial.println(" %");
  Serial.print("Temp...: ");
  Serial.print(t);
  Serial.println(" *C ");
  Serial.print("LPG: ");
  Serial.println(lpg);
  Serial.print("CO: ");
  Serial.println(co);
  Serial.print("Smoke: ");
  Serial.println(smoke);
  Serial.print("obstacle: ");
  Serial.println(obstacle == LOW ? "Yes" : "NO");
  Serial.print("\n");

  boolean fire = detektFire(t, smoke, co, obstacle);
  printAll(h, t, lpg, co, smoke, obstacle, fire);

  delay(500);
}

Credits

Mariam Talibe

Mariam Talibe

1 project • 5 followers
Nihad Kadi

Nihad Kadi

1 project • 5 followers
Oliver Ivic-Matijas

Oliver Ivic-Matijas

1 project • 4 followers
Interactive Media Design student at Hochschule Darmstadt (Germany)
Falk Schröder

Falk Schröder

1 project • 5 followers
industrial engineering student at Technische Universität Darmstadt
Wladislav Miretski

Wladislav Miretski

1 project • 5 followers

Comments

Add projectSign up / Login