栽培環境構築関連

サボテン用温室の温度・湿度・照度をリアルタイムで測定するぞ!

栽培環境構築関連
スポンサーリンク

概要

 マイコンでフレーム内の温度・湿度・照度をマイコンを用いてリアルタイムでロギングし、WEB上に表示させます。ちなみに、各日でプログラムを変えたり、センサの位置を移動したりしている関係で、それぞれの日、時間のデータを単純に比べることはできません。

仕様とか

  • 構成は、Arduino uno、Arduino Ethanet Shield、照度センサ、温度・湿度センサ
  • 照度についてはフォトダイオードBS520を使用。200Ωの抵抗で電圧変換した結果、仕様的には、50mVで50000lux。レールツーレールオペアンプ(LMC6484AIN[4回路入りを贅沢に1つだけ利用])で100倍して5Vで50000lux(真夏の直射日光が100000lux、恐らく遮光するので最大50000luxぐらいでよいとおもう)。arduinoのアナログインプットで検出。校正はかなり適当で、信頼性はないが、桁ぐらいは合っていると思う。
  • 温度、湿度については、RHT03を使用。参考文献通りのプログラムでArduino unoで検出。
  • データの保存については、WEBサーバーにGETメソッドでデータ保存用PHPプログラムに送る。
  • データの表示については、jqueryのhighcharts.jsを使用。
  • 各日のデータの最大値、最小値および平均値をPHPで計算(2個目のグラフ)。
 
回路図
 
 
センサ部

 

 Arduino部

 

測定している温室


 

Arduinoプログラム

#include <SPI.h>
#include <Ethernet.h>
#include <dht.h>

dht DHT;
#define DHT22_PIN 5

// ***は適宜変更
byte mac[] = {  0x**, 0x**, 0x**, 0x**, 0x**, 0x** };
EthernetClient client;

void setup() {
  Serial.begin(9600);
  
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
  }
  delay(1000);
  Serial.println("connecting...");
}

void loop()
{
    int chk = DHT.read22(DHT22_PIN);
    double temperature = DHT.temperature;
    double humidity = DHT.humidity;
    int lux = analogRead(0);

  // ***は適宜変更
  if (client.connect("***.***.***", 80)) {
    Serial.println("connected");
    client.print("GET /*********.php?temperature=");
    client.print(temperature,DEC);
    client.print("&humidity=");
    client.print(humidity,DEC);
    client.print("&lux=");
    client.print(lux,DEC);
    client.println(" HTTP/1.1");
    client.println("Host: ***.***.***");
    client.println("Connection: close");
    client.println();
    client.stop();
    
  } 
  else {
    Serial.println("connection failed");
    client.stop();
  }

  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
  }
  
  delay(300000);
}

 

サーバサイドデータ取得プログラム(PHP)

<?php

 echo "1. Arduino get program start<br>";

 //日付を取得(ファイル用)
 $today = date("Ymd");
 echo "2. Today is $today<br>";

 // 'temperature' という名前で Arduino からGET送信された温度の値を受け取る
 $strTempVal = $_GET['temperature'];
 echo "3. Temperature is $strTempVal<br>";
 
 // 'humidity' という名前で Arduino からGET送信された温度の値を受け取る
 $strHumiVal = $_GET['humidity'];
 echo "4. Humidity is $strHumiVal<br>"; 

 // 'lux' という名前で Arduino からGET送信された照度の値を受け取る 
 $strLuxVal = $_GET['lux'];
 echo "5. Lux is $strLuxVal<br>"; 

 $strLuxVal = $strLuxVal . "n"; 

 // 時刻
 $time = date("Y/m/d H:i:s");
 echo "6. Time is $time<br>";

 // データを保存するテキストファイルの相対パス
 $strDataFilePath = 'data/' . $today . '.txt';
 echo "7. File path is $strDataFilePath<br>";

 // データを保存するテキストファイルを追記モードでオープン
 $fp = fopen($strDataFilePath, "a");

 // 送信された値をテキストファイルに書き込み
 fwrite($fp, $time . "," .$strTempVal . "," . $strHumiVal  . "," . $strLuxVal);

 // ファイルポインタをクローズ
 fclose($fp);

 echo "8. Arduino get program end<br>";
?>

 

感想と今後

湿度と温度が、一定の値を境に反転しているだけのようなグラフ結果なんですが(温度が上がると、湿度が下がる。温度=f(湿度) ?)、そういうもんなんでしょうかね。あと冬に向けて30℃を超えたらファンが回るようにする予定。

 

参考文献

タイトルとURLをコピーしました