View Single Post
Eski 03-06-2012, 15:24   #1
Potasyum
Ağaçsever
 
Giriş Tarihi: 10-02-2012
Şehir: Glasgow
Mesajlar: 58
Topraksız Tarım Kontrol Sistemleri

Topraksiz tarim toprakli tarima nazaran daha cok kontrol ve incelik istemektedir.Topraksiz tarimda kontrolun avantaji zaman ve kalite acisindan onemli rol oynar.

Topraksiz tarim ticari veya profesyonel yapilacaksa,Serada hava(CO2,O2) orani,nem,isi,isik,bitki icin sudaki besin orani,su asitligi,koklerdeki bakteriyel fonksiyonlarin kontrolu,nft'de suya karismis veya koklerdeki gereksiz gazlarin atilmasi ornegin (alkol),bocek,fungi,kimyasal,gibi kontrol mekanizmalari yetistirmede kaliteyi yukseltmekte zamani en alt seviyeye indirmektedir.

Bu sistemler topraksiz tarimin omurgasini olusturmaktadir.Hobi olarak basladigimda isin ilk olarak kontrolunden basladim.Evimde kullandigim kapali sera icin kurdugum eski sistemin ekran ve tuslar bolumune gelistirme ve yeni eklemeler yapmaktayim.

Video

Sera Kontrol Sistemleri/Gelistirme - YouTube


Eski sistemin programlaridan Ec/co2/ph kontrol Arduino bazli

Alıntı:
#include <LiquidCrystal.h>

#include <stdlib.h> // for itoa() call
#include <EEPROM.h>




/* Temperature/Thermistor Calibration
5v--100k_Therm--input--100k --gnd
y = bit value from input, x = Temperature Value
y = mx +c */
#define TEMPERATURE_M 20
#define TEMPERATURE_C -163

/* Carbon dioxide calibration
y = MLogn(x) + C
x = e^((y-C)/M)

where y is bit value and x is c02 concentration
C02 Bit Value
400 279.98

10000 -0.03
=-87*(LN(N25))+800
*/
#define Carbon_M 0.25//-87//-1.47 // was-87
#define Carbon_C 175//800 //1300 //was 800

/*PH calibration
y = MLogn(x) + C
x = e^((y-C)/M)

where y is bit value and x is c02 concentration
C02 Bit Value
400 279.98

10000 -0.03
=-87*(LN(N25))+800
*/
#define Ph_M 0.25//-87//-1.47 // was-87
#define Ph_C 175//800 //1300 //was 800

#define Ec_M 0.25//-87//-1.47 // was-87
#define Ec_C 175//800 //1300 //was 800
/***********************/
/* Interval Definitions*/
#define INTERVAL 30000 //Define ms INTERVAL in between trigerring
#define SENSOR_INTERVAL 400 // SENSOR INTERVAL
#define BACKLIGHT_TIME 180000 // 1 minute for backlight on after no keypress. NOT BEING USED NOW
#define EE_PROM_INTERVAL 600000 //write data to eeprom every 10minutes

/*******/
/*Define array size to be used for averaging. */
/*In The array, the max value and min value are taken out and the rest averaged*/
/* If 2 or less, it is just averaged*/
#define ARRAY_SIZE 10



/**********************/
/*Hysterisis Intervals*/
#define TEMP_LO 1
#define TEMP_HI 1
#define CO2_LO 10
#define CO2_HI 10
#define PH_LO 10
#define PH_HI 10
#define EC_LO 10
#define EC_HI 10
/**********************/
/* Define input Pins */
//Analog
#define THERM1 1 // Analog 1 Thermistor 1 voltage
#define CARBONDI3 2
#define PH 3
#define EC 4
/// Analog 3


/**********************/
/*Define output Pins */
//Digital
#define RELAY1 12
#define RELAY2 3
#define RELAY3 13
#define RELAY4 11
#define BACKLIGHT 10 //backlight Pin Value
//Can use pins 0 + 1 if serial not being used.. or use an analog pin.

/******Define Size of storage array for values*/
#define ARRAY_STORE 200 //how many lines to store in eeprom. ARRAY_STORE*4 <1k


/*****************************/
/*set Triggers *************/
int heatTrigger1 = 25;
int C02Trigger = 1000;
int PHTrigger = 1000;
int ECTrigger = 1000;
/***************************/
/* Sensor Value initialize */
int thermValue1 = 0;
int carbonDiVal = 0;
int PhVal = 0;
int EcVal = 0;

int therm1[ARRAY_SIZE];
int carbonD[ARRAY_SIZE];
int Ph[ARRAY_SIZE];
int Ec[ARRAY_SIZE];

int Whole, Fract;
int keypad_delay = 10;

/************************/
/*Set time check ms */
long last_check = millis();
long sensor_check = millis();
long backlight = millis();
int timing = millis();
long time_eeprom = millis();

/**************************/
/** LCD Shield */
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
char buf[5]; //used in conversion of int to char for lcd

int configure = 0; //use select as an on/off for configuring
int showReading = 0; //select which value to modify 0-3
int adc_key_in = 1024; //Start with -1 key value

int adc_key_val[5] = {
100, 160, 360, 770, 800 }; //Analog values from Keys on keypad shield


int NUM_KEYS = 5;
int key= -1;

char trigger_names[4][15] = {
"Temp Trigger 1",
"C02 Trigger",
"PH Trigger",
"EC Trigger" };

boolean Heat_on = false;
boolean CO2_on = false;
boolean Ph_on = false;
boolean Ec_on = false;
/* Set up index value for storing values in eeprom*/
int k=0;



void setup()
{
// declare pins as output
//pinMode(LEDPIN, OUTPUT);
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
pinMode(RELAY4, OUTPUT);

//Setup averaging arrays
int i;


for(i=0; i< ARRAY_SIZE; i++)
{
therm1[i] = 512;
carbonD[i] = 700;
Ph[i] = 700;
Ec[i] = 700;
}
//pinMode(BACKLIGHT,OUTPUT); Backlight on all the time, so comment out this.

// lcd.init();
// lcd.clear();
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);

pinMode(BACKLIGHT, OUTPUT);
digitalWrite(BACKLIGHT,HIGH);
//Start serial comms with computer
Serial.begin(115200);

delay(100); //delay for sensor setup

}

void loop() {


key = get_key(adc_key_in); //In case

//reset sensor_check if millis() has overflowed
if( millis() < sensor_check ){ sensor_check = millis(); }

/* This is for backlight off delay.
if ( (millis() < backlight) || millis() > (backlight + BACKLIGHT_TIME))
{ digitalWrite(BACKLIGHT,LOW); }
*/


/*Read sensor only after delay of sensor_check*/
if(millis() - sensor_check > SENSOR_INTERVAL )
{
sensor_check = millis();

int i;

for (i=0; i < ARRAY_SIZE -1 ; i++) {
therm1[i] = therm1[i+1];
carbonD[i] = carbonD[i+1];
Ph[i] = Ph[i+1];
Ec[i] = Ec[i+1];
}



/*** Read in sensor values and change to fit actual temp/hum/ppm values*/
therm1[ARRAY_SIZE -1] = analogRead(THERM1);
int temp1 = mov_avg(therm1);
thermValue1 = (temp1 - TEMPERATURE_C)/TEMPERATURE_M; // x = (y-c)/m



int c_temp = analogRead(CARBONDI3);
Serial.print(c_temp);
/*if (( c_temp > 0 ) && (c_temp <300)) //stops unecessary calcs which grind arduino to a halt
{*/
carbonD[ARRAY_SIZE -1] = c_temp;
c_temp = mov_avg(carbonD);
Serial.print(":");
Serial.print(c_temp);
float c_float = c_temp - Carbon_C; // For ease of use in power function
c_float = c_float/Carbon_M;
Serial.print(":");
Serial.print(c_float);
carbonDiVal = pow(2.718,c_float);
//}
Serial.print(":");
Serial.println(carbonDiVal);

////PH////////***////////



int p_temp = analogRead(PH);
Serial.print(p_temp);
/*if (( c_temp > 0 ) && (c_temp <300)) //stops unecessary calcs which grind arduino to a halt
{*/
Ph[ARRAY_SIZE -1] = p_temp;
p_temp = mov_avg(Ph);
Serial.print(":");
Serial.print(p_temp);
float p_float = p_temp - Ph_C; // For ease of use in power function
p_float = p_float/Ph_M;
Serial.print(":");
Serial.print(p_float);
PhVal = pow(2.718,p_float);
//}
Serial.print(":");
Serial.println(PhVal);



int e_temp = analogRead(EC);
Serial.print(3_temp);
/*if (( c_temp > 0 ) && (c_temp <300)) //stops unecessary calcs which grind arduino to a halt
{*/
Ph[ARRAY_SIZE -1] = 3_temp;
3_temp = mov_avg(Ec);
Serial.print(":");
Serial.print(e_temp);
float e_float = e_temp - Ec_C; // For ease of use in power function
e_float = e_float/Ec_M;
Serial.print(":");
Serial.print(e_float);
EcVal = pow(2.718,e_float);
//}
Serial.print(":");
Serial.println(EcVal);
/**Add first line of Display**/
if (configure == 0)
{

lcd.setCursor(0,0);
lcd.print("ISI CO2 PH EC");
}
/**** Add second line of the Display *****/
if (configure == 0)
{
lcd.setCursor(0,1); //
itoa(thermValue1, buf, 10);
lcd.print(buf);

lcd.setCursor(4,1);
Whole = (carbonDiVal / 100); // separate off the whole and fractional portions
Fract = (carbonDiVal % 100);

if (Whole >= 10) {
Whole = 9;
}
lcd.print(Whole, DEC);
delay(keypad_delay);
lcd.print(".");
delay(keypad_delay);
if (Fract < 10){
lcd.print("0");
delay(keypad_delay);
}
lcd.print(Fract, DEC);
delay(keypad_delay);


lcd.setCursor(8,1);
Whole = (PhVal / 100); // separate off the whole and fractional portions
Fract = (PhVal % 100);

if (Whole >= 10) {
Whole = 9;
}
lcd.print(Whole, DEC);
delay(keypad_delay);
lcd.print(".");
delay(keypad_delay);
if (Fract < 10){
lcd.print("0");
delay(keypad_delay);
}
lcd.print(Fract, DEC);
delay(keypad_delay);

lcd.setCursor(11,1);
Whole = (EcVal / 100); // separate off the whole and fractional portions
Fract = (EcVal % 100);

if (Whole >= 10) {
Whole = 9;
}
lcd.print(Whole, DEC);
delay(keypad_delay);
lcd.print(".");
delay(keypad_delay);
if (Fract < 10){
lcd.print("0");
delay(keypad_delay);
}
lcd.print(Fract, DEC);
delay(keypad_delay);



}
//*************************TEST ICIN****************//

// Print Output Values*/

/*Serial.print(thermValue1);
Serial.print(":");
Serial.print(carbonDiVal);
Serial.println(":");

//PRINT ARRAYS THAT ARE AVERAGED
Serial.print("**Therm1*");
Serial.print(thermValue1);
Serial.print("*(");
for( i=0; i<ARRAY_SIZE; i++)
{
Serial.print(therm1[i]);
Serial.print(":");
}
Serial.print(")**carbonD*");
Serial.print(carbonDiVal);
Serial.print("*(");
for( i=0; i<ARRAY_SIZE; i++)
{
Serial.print(carbonD[i]);
Serial.print(":");
}
Serial.println(")");


}

/********************************************/
/*EEPROM STORAGE CODE *********************/
if(millis() < time_eeprom) { time_eeprom = millis(); }
/**Put values into eeprom*/
if(millis() - time_eeprom > EE_PROM_INTERVAL)
{
time_eeprom = millis();
EEPROM.write((k*4),(thermValue1));
EEPROM.write((k*4+1),(carbonDiVal/10));
EEPROM.write((k*4+2),(PhVal/10));
EEPROM.write((k*4+3),(EcVal/10));
k=k+1;
if(k>=ARRAY_STORE) { k=0; }
}/****************************************/


/************************************************** *****/
/*RELAY Changes and value checks, after time INTERVAL***/
if( millis() < last_check ) { last_check = millis(); }

if (millis() - last_check > INTERVAL)
{
last_check = millis(); //left out until final test, no wait 30sec

//Temperature 1 check and Relay Change
if (thermValue1 > (heatTrigger1 +TEMP_HI) ) {
digitalWrite(RELAY1, HIGH);
Heat_on = true;
}

if (thermValue1 < (heatTrigger1 -TEMP_LO) ) {
digitalWrite(RELAY1, LOW);
Heat_on = false;
}


//Carbon Dioxide check and Relay Change

if ( carbonDiVal < C02Trigger- CO2_LO ) {
digitalWrite(RELAY2,HIGH);
CO2_on = true; }
if ( carbonDiVal > C02Trigger+ CO2_HI ) {
digitalWrite(RELAY2, LOW);
CO2_on = false; }


//Carbon Dioxide check and Relay Change

if ( PhVal < PHTrigger- PH_LO ) {
digitalWrite(RELAY3,HIGH);
Ph_on = true; }
if ( PhVal > PHTrigger+ PH_HI ) {
digitalWrite(RELAY3, LOW);
Ph_on = false; }


//Carbon Dioxide check and Relay Change

if ( EcVal < ECTrigger- EC_LO ) {
digitalWrite(RELAY4,HIGH);
CO2_on = true; }
if ( EcVal > ECTrigger+ EC_HI ) {
digitalWrite(RELAY4, LOW);
CO2_on = false; }



/***************************/
/*KEYPAD CODE***************/
adc_key_in = analogRead(0);
key = get_key(adc_key_in); //convert into key press. key = 1-5. -1 for none

if ( (key != -1))
{
digitalWrite(BACKLIGHT,HIGH); //Backlight code taken out
backlight = millis();

if (configure ==1)
{ lcd.clear(); }
delay(20); //debounce
key = get_key(adc_key_in);
delay(200);

/****Select key****/
if ( key == 3 ) //Toggle the configure Key
{
lcd.clear();
if( configure == 1)
{
configure = 0;
lcd.clear();
delay(100);

}
else if ( configure == 0 )
{
configure = 1;
lcd.clear();
delay(100);
}
key = -1;
}
}

/***** Up Key Press ******/
if ( (key == 1) && ( configure == 1 ) )
{
lcd.setCursor(0,1);

switch(showReading)
{
case 0: //heatTrigger1
heatTrigger1 = heatTrigger1 +1;
itoa(heatTrigger1, buf, 10);
lcd.print(buf);
break;
case 1:
C02Trigger = C02Trigger + 100;
itoa(C02Trigger, buf, 10);
lcd.print(buf);
break;
case 2:
PHTrigger = PHTrigger + 100;
itoa(PHTrigger, buf, 10);
lcd.print(buf);
break;
case 3:
ECTrigger = ECTrigger + 100;
itoa(ECTrigger, buf, 10);
lcd.print(buf);
break;
}
}

/**** Keypress down ****/
if ( (key == 2) && ( configure == 1 ))
{
lcd.setCursor(0,1);

switch(showReading)
{
case 0: //heatTrigger1
heatTrigger1 = heatTrigger1 -1;
itoa(heatTrigger1, buf, 10);
lcd.print(buf);
break;
case 1:
C02Trigger = C02Trigger - 100;
itoa(C02Trigger, buf, 10);
lcd.print(buf);
break;
case 2:
PHTrigger = PHTrigger - 100;
itoa(PHTrigger, buf, 10);
lcd.print(buf);
break;
case 3:
ECTrigger = ECTrigger - 100;
itoa(ECTrigger, buf, 10);
lcd.print(buf);
break;
}

}

/***** Keypress Right ****/

if ( (key == 0) && (configure ==1) )
{
lcd.setCursor(0,1); //line 2 x =0

switch(showReading)
{
case 0: //heatTrigger1 to c02
showReading = 1;
itoa(C02Trigger, buf, 10);
lcd.print(buf);
break;
case 1: // C02Trigger to heatTrigger1
showReading = 2;
itoa(heatTrigger1, buf, 10);
lcd.print(buf);
break;
case 2: //heatTrigger2 to ph
showReading = 3;
itoa(PHTrigger, buf, 10);
lcd.print(buf);
break;
case 3: //PH to EC
showReading = 0;
itoa(ECTrigger, buf, 10);
lcd.print(buf);
break;

}
}
/******Dump to serial all EEPROM values if keypress right no config***/
if ( (key == 0) && (configure ==0) )
{
lcd.setCursor(0,0);
lcd.print("Upload");
char buf2[10];
lcd.setCursor(0,1);
lcd.print(" ");

lcd.setCursor(10,1);
lcd.setCursor(0,1);


Serial.println("");
Serial.print("Values end at:");
Serial.println(k+1);
for( k=0; k <=ARRAY_STORE; k++) //l=l+4

{
Serial.print(int(EEPROM.read(k*4)));
Serial.print(",");
Serial.print(int(EEPROM.read(k*4+1)));
Serial.print(",");
Serial.print(int(EEPROM.read(k*4+2)));
Serial.print(",");
Serial.println(int(EEPROM.read(k*4+3)));
}


}



/***** Add the first line of the display******/
lcd.setCursor(0,0); //line 1 x =0

if (configure == 1)
{
lcd.print(trigger_names[showReading]);

lcd.setCursor(0,1);
switch(showReading)
{
case 0:
itoa(heatTrigger1, buf, 10);
lcd.print(buf);
break;
case 1:
itoa(C02Trigger, buf, 10);
lcd.print(buf);
break;
case 2:
itoa(PHTrigger, buf, 10);
lcd.print(buf);
break;
case 3:
itoa(ECTrigger, buf, 10);
lcd.print(buf);
break;
}
}
lcd.setCursor(0,0);
if (Heat_on) {
lcd.print("*");
}
else {
lcd.print(" ");
}

lcd.setCursor(4,0);
if ( CO2_on ) {
lcd.print("*");
}
else {
lcd.print(" ");
}

lcd.setCursor(8,0);
if ( Ph_on ) {
lcd.print("*");
}
else {
lcd.print(" ");
}

lcd.setCursor(11,0);
if ( Ec_on ) {
lcd.print("*");
}
else {
lcd.print(" ");
}
}
}
//End Main loop

int get_key(unsigned int input)
{
int k;

for ( k=0; k < NUM_KEYS; k++)
{
if (input < adc_key_val[k] )
{
return k;
}
}

if ( k >= NUM_KEYS)
{
k = -1;
}
return k;
}

int mov_avg(int averages[ARRAY_SIZE])
{
int summation = averages[0];
int i=1;
for( i=1; i < ARRAY_SIZE; i++)
{
summation = averages[i] + summation;
}
if(ARRAY_SIZE >2)
{
summation = summation - max_array(averages) - min_array(averages);
summation = summation/(ARRAY_SIZE -2);
}
else
{
summation = summation/ARRAY_SIZE;
}
return summation;
}


int max_array(int array[ARRAY_SIZE])
{
int i=0;
int current= array[0];
for( i=1; i<ARRAY_SIZE; i++)
{
if (array[i] > current)
{
current = array[i];
}
}
return current;
}

int min_array(int array[ARRAY_SIZE])
{
int i=0;
int current= array[0];
for( i=1; i<ARRAY_SIZE; i++)
{
if (array[i] < current)
{
current = array[i];
}
}
return current;
}

Eklenen Resimler
     

Düzenleyen Potasyum : 09-01-2013 saat 12:38
Potasyum Çevrimdışı   Alıntı Yaparak Cevapla Başa Dön