Eton XiongRebecca Cai
Published

Kitchen Safety Monitor using Wio Ternimal

Measure the temperature and CO level of kitchen using sensors and Wio Terminal, providing warning of a possible gas leak or fire

BeginnerFull instructions provided3 hours222
Kitchen Safety Monitor using Wio Ternimal

Things used in this project

Story

Read more

Code

Code of Kitchen Safety Monitor Project

Arduino
#include "TFT_eSPI.h"
#include <Multichannel_Gas_GMXXX.h>
#include <Wire.h>
GAS_GMXXX<TwoWire> gas;
TFT_eSPI tft;
unsigned int Val;
const int B = 4275;                   // B value of the thermistor
const int R0 = 100000;                // R0 = 100k
const int pinTempSensor = A0;         // Grove - Temperature Sensor connect to A0
TFT_eSprite spr = TFT_eSprite(&tft);  // Sprite
void setup() {
  tft.begin();
  Wire.begin();
  tft.setRotation(3);
  gas.begin(Wire, 0x08);
  pinMode(WIO_BUZZER, OUTPUT);
  Serial.begin(9600);
  tft.fillScreen(0x39F);
  tft.setTextSize(3);
  tft.setRotation(3);
  tft.setTextColor(0xFFFF);
}



void loop() {
  spr.fillSprite(TFT_BLACK);
  spr.setFreeFont(&FreeSansBoldOblique18pt7b);
  spr.setTextColor(TFT_BLUE);

  int a = analogRead(pinTempSensor);
  float R = 1023.0 / a - 1.0;
  R = R0 * R;
  Val = gas.getGM702B();
  float CO = gas.calcVol(Val);
  Serial.print("CO: ");
  Serial.print(CO);
  Serial.println(" ppm");
  float temperature = 1.0 / (log(R / R0) / B + 1 / 298.15) - 273.15;  // convert to temperature via datasheet

  Serial.print("temperature = ");
  Serial.println(temperature);

  delay(100);

  if (temperature > 54) {

    tft.fillScreen(0x39F);
    tft.setTextSize(3);
    tft.drawString((String) "A fire risk", 25, 100);
    tone(WIO_BUZZER, 262);
    delay(1000);
    noTone(WIO_BUZZER);

  } else if (CO > 35) {

    tft.fillScreen(0x39F);
    tft.setTextSize(3);
    tft.drawString((String) "A gas leak risk", 25, 100);
    tone(WIO_BUZZER, 262);
    delay(1000);
    noTone(WIO_BUZZER);

  } else if (temperature > 54 & CO > 35) {

    tft.fillScreen(0x39F);
    tft.setTextSize(2);
    tft.drawString((String) "Fire and gas leak risk", 25, 100);
    tone(WIO_BUZZER, 262);
    delay(1000);
    noTone(WIO_BUZZER);


  } else {

    tft.fillScreen(0x39F);
    tft.drawString((String) "Temperature:", 40, 70);
    tft.drawFloat(temperature, 2, 40, 100);
    tft.drawString((String) "C", 140, 100);

    tft.drawString((String) "CO:", 40, 140);
    tft.drawFloat(CO, 2, 40, 170);
    tft.drawString((String) "ppm", 140, 170);
  }



  delay(2000);
}

Credits

Eton Xiong
1 project • 0 followers
Rebecca Cai
0 projects • 0 followers

Comments