LoginSignup
0
1

More than 1 year has passed since last update.

M5StickCでeCO2と換気扇(など)を連動してみる

Last updated at Posted at 2021-11-19

M5StackでCO2モニターを作ってみた話をしたところ、【集中力UP】NETATMO+IFTTT+SwitchBotでCO2濃度を監視+自動換気する方法という記事を紹介いただきました。
手元で余らせているM5StickCでも似たことができないかな、ということでやってみました。

準備するもの

累計 ¥7,056

あと、ピンヘッダーを切るのに必要なので持っていないようならニッパーを。
Amazon | エンジニア マイクロニッパー ESD 静電気対策 120㎜ NS-04 | 小型ニッパ

接続

TVOC/eCO2ガスセンサユニットは付属のコネクタで HY2.0-4P(GROVE)に接続。

赤外線送受信ユニットは、GROVE 4ピン-ジャンパメスケーブル に両方長いピンヘッダを差して

GND -> GND
5V -> 5V
OUT -> G26
IN -> G36

に接続。

リモコンコンセントを換気扇のコンセントに接続する。

できたもの

image.png

Arduion IDEのコード

eCO2が500を境に電源を制御するようになっています。値は実際に使って見て調整予定です。

#include "Adafruit_SGP30.h"
#include <M5StickC.h>
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>

Adafruit_SGP30 sgp;
int i = 15;
long last_millis = 0;

const uint16_t kIrLed = 26;
IRsend irsend(kIrLed);
// on
uint16_t onRawData[19] = {2578, 2664,  816, 876,  838, 850,  840, 1890,  840, 1892,  840, 1890,  842, 1892,  816, 876,  836, 852,  812};  // UNKNOWN 8F0C8B3A
//off
uint16_t offRawData[19] = {2554, 2688,  816, 878,  812, 1916,  840, 850,  812, 876,  814, 1918,  814, 876,  812, 1918,  840, 1890,  838};  // UNKNOWN D410BC59


void setup() {
  M5.begin();
  irsend.begin();

  Serial.begin(115200);
  delay(1000);

  Wire.begin(32, 33); // M5StickC

  if (!sgp.begin()) {
    Serial.println("Sensor not found");
    while (1);
  }
  M5.Lcd.setRotation(3);
  M5.Axp.ScreenBreath(12);
  M5.Lcd.setTextColor(WHITE, BLACK);
}

void loop() {
  M5.update();
  if (! sgp.IAQmeasure()) {
    Serial.println("Measurement failed");
    return;
  }
  Serial.println("TVOC " + String(sgp.TVOC));
  Serial.println("eCO2 " + String(sgp.eCO2));

  if (sgp.eCO2 > 500) {
   Serial.println("eCO2 over 500 ");
   irsend.sendRaw(onRawData, 19, 38);  // Send a raw data capture at 38kHz.    
  }
  if (sgp.eCO2 <= 500) {
   Serial.println("eCO2 under 500 "); 
    irsend.sendRaw(offRawData, 19, 38);  // Send a raw data capture at 38kHz.    
  }


  M5.Lcd.fillScreen(BLACK);
  M5.Lcd.setCursor(0, 0, 2);
  M5.Lcd.print("eCO2");
  M5.Lcd.setCursor(0, 30, 4);
  M5.Lcd.print(sgp.eCO2);
  M5.Lcd.print("ppm");
  delay(1000);
}

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1