Login
A   A   A  
welcome

 Album 

米Teen唔鐘意玩現成品,喜歡由零件開始砌。99次失敗唔係問題,最緊要係有1次成功!

米Teen總部設在聖公會白約翰會督中學506室,在午膳後和放學後集會。有興趣參與的同學,請與會長或導師聯絡。

米Teen專頁

506室內 2020-11-04 21:43:57
溫度 26℃ 濕度 95%
街景 2020-11-04 21:41:52
街景
5樓室外 2020-11-04 21:43:43
溫度 22℃ 濕度 95%
街景 2020-11-04 21:34:34
街景

水耕種植機控制器

icon

Home>製作項目...>水耕種植機控制器...

設計

市面上有許多水耕種植機,價錢由幾百到過萬都有。因為QEF計劃要發展環控種植,所以先DIY一座水耕機來吸收經驗。這部機的設計可以獨立調控各色LED的開關,營養液的循環輸送時間,漏走殘留在水喉的"死水"。還要考慮安全泵出營養液的方法,避色植物根部阻塞膠喉而導致滿溢或水缸缺而開動水泵。

主要組件

Arduino原始碼

/* Hydroponics Controller
 Version 2
 2018.4.19
 Matthew Li
*/

// Digital Output Pins
const int resetPin=12;
const int whiteLEDPin = 7;
const int redLEDPin = 6;
const int blueLEDPin = 5;
const int valvePin = 4;
const int warningLEDPin = 3;
const int pumpPin = 2;

// Digital Input Pins
const int overflowBallPin = 9; // float switch, overflow
const int bottomBallPin = 10; // float switch, detect bottom water level
const int topBallPin = 11; // float switch, detect top water level

// Analog Input Pins
const int CDSPin = A0; // map input voltages between 0 and 5 volts into integer values between 0 and 1023

// Constant parameters
const int CDSThreshold=400; // In darkness, CDS value gets higher
const long LEDOnOffInterval=10000L;  // this sets the minimum interval for LED=ON state, 10 seconds
const long pumpOnInterval=30000L;  // pump on interval, 30 seconds
const long pumpOffInterval=240000L; // pump off interval, 240 seconds
const long pumpPauseInterval=10000L; // pump off interval if overflow occurs, 10 seconds
const long resetInterval=10*24*60*60*1000L; // reset Arduino regularly, reset the timer, for every 10 days

// Variables
long lastLEDOnTime=0;
long lastPumpOnTime=0;
long lastPumpOffTime=0;
long lastPumpPauseTime=0;
long currentTime=0;
int CDSValue = 0;
int pumpState=LOW;
bool pumpPauseState=false;

void setup() {
  digitalWrite(resetPin,HIGH);pinMode(resetPin,OUTPUT);digitalWrite(resetPin,HIGH);  // these statements must be put at the first line & execute immediately
  
  // initialize serial communication at 9600 bits per second, for debug
  Serial.begin(9600);

  pinMode(whiteLEDPin, OUTPUT);
  pinMode(redLEDPin, OUTPUT);
  pinMode(blueLEDPin, OUTPUT);
  pinMode(valvePin, OUTPUT);
  pinMode(warningLEDPin, OUTPUT);
  pinMode(pumpPin, OUTPUT);

  pinMode(overflowBallPin, INPUT_PULLUP);  // use built-in 20K pullup resistors
  pinMode(bottomBallPin, INPUT_PULLUP);  // use built-in 20K pullup resistors
  pinMode(topBallPin, INPUT_PULLUP);  // use built-in 20K pullup resistors

  digitalWrite(whiteLEDPin,LOW);
  digitalWrite(redLEDPin,LOW);
  digitalWrite(blueLEDPin,LOW);
  digitalWrite(valvePin,LOW);
  digitalWrite(warningLEDPin,LOW);
  digitalWrite(pumpPin,LOW);
  currentTime=millis(); // returns the number of milliseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 49.7 days.
  // currentTime is long, millis() is unsigned long, therefore, must handle the case after 20 days
  lastPumpOffTime=-pumpOffInterval-1000; // To start immediately
  // lastPumpOffTime=currentTime;  // To start after pumpOffInterval
}

void loop() {
  currentTime=millis();
  
  CDSValue=analogRead(CDSPin);
  if (CDSValue>=CDSThreshold) {
    lastLEDOnTime=currentTime;
  }
  
  if (CDSValue>=CDSThreshold || (currentTime-lastLEDOnTime)pumpOffInterval && digitalRead(topBallPin)==HIGH && digitalRead(bottomBallPin)==HIGH && digitalRead(overflowBallPin)==LOW) {
    pumpState=HIGH;
    digitalWrite(pumpPin,pumpState);
    digitalWrite(valvePin,HIGH);
    lastPumpOnTime=currentTime;
    pumpPauseState=false;
  }

  if (pumpState==HIGH && (currentTime-lastPumpOnTime)>pumpOnInterval || digitalRead(bottomBallPin)==LOW) {
    pumpState=LOW;
    digitalWrite(pumpPin,pumpState);
    digitalWrite(valvePin,LOW);
    lastPumpOffTime=currentTime;
    pumpPauseState=false;
  }

  if (pumpState==HIGH && (currentTime-lastPumpOnTime)pumpPauseInterval && digitalRead(bottomBallPin)==HIGH && pumpPauseState==true && digitalRead(overflowBallPin)==LOW) {
    pumpPauseState=false;
    digitalWrite(pumpPin,HIGH);
  }

/*
  // for debug only
  Serial.print("current ");
  Serial.print(currentTime/1000,1);

  Serial.print("    CDS ");
  Serial.print(CDSValue);
  
  Serial.print("    Last pump on ");
  Serial.print(lastPumpOnTime/1000,1);
  Serial.print("  diff. ");
  Serial.print((currentTime-lastPumpOnTime)/1000,1);

  Serial.print("  Overflow sensor. ");
  Serial.print(digitalRead(overflowBallPin));
  Serial.print("     Last pump pause ");
  Serial.print(lastPumpPauseTime/1000,1);
  Serial.print("  diff. ");
  Serial.print((currentTime-lastPumpPauseTime)/1000,1);

  Serial.println();
*/
  delay(100);

  // Reset Arduino regularly
  if (currentTime>resetInterval)
    digitalWrite(resetPin,LOW);
}
welcome

 Album 

米Teen唔鐘意玩現成品,喜歡由零件開始砌。99次失敗唔係問題,最緊要係有1次成功!

米Teen總部設在聖公會白約翰會督中學506室,在午膳後和放學後集會。有興趣參與的同學,請與會長或導師聯絡。

米Teen專頁

506室內 2020-11-04 21:43:57
溫度 26℃ 濕度 95%
街景 2020-11-04 21:41:52
街景
5樓室外 2020-11-04 21:43:43
溫度 22℃ 濕度 95%
街景 2020-11-04 21:34:34
街景
 ⇧