#include #include #include /* 0 - 232 rxd 1 - 232 txd 2 - enable (LCD) 3 - temp sensor (LCD) 4 - sd card 9 (ETHERNET SHIELD) 5 - lcd d4 (LCD) 6 - lcd d5 (LCD) 7 - lcd d6 (LCD) 8 - lcd d7 (LCD) 9 10 - w5100 select(ETHERNET SHIELD) 11 - SPI MOSI (ETHERNET SHIELD) 12 - SPI MISO (ETHERNET SHIELD) 13 - SPI CLK (ETHERNET SHIELD) ANALOG 0 - MOISTURE in (analog) 1 - moisture (digital) 2 - moister 1 (digital) 3 - window open (digital) 4 - window close (digital) 5 - water pump (digital) */ // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Data wire is plugged into pin 3 on the Arduino #define ONE_WIRE_BUS 9 // Setup a oneWire instance to communicate with any OneWire devices OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); // Assign the addresses of your 1-Wire temp sensors. // See the tutorial on how to obtain these addresses: // http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html DeviceAddress insideThermometer = { 0x28, 0x1F, 0xAA, 0xDA, 0x02, 0x00, 0x00, 0xBA }; //DeviceAddress outsideThermometer = { 0x28, 0x6B, 0xDF, 0xDF, 0x02, 0x00, 0x00, 0xC0 }; //DeviceAddress dogHouseThermometer = { 0x28, 0x59, 0xBE, 0xDF, 0x02, 0x00, 0x00, 0x9F }; #define moisture_input 0 // analog pin 0 #define divider_top A1 // takisti digital pin 9 #define divider_bottom A2 // nael 1 digital pin 10 int waterPump =7; // led, water pump digital pin 7 int waterLed = 8; //led kui niiskust on 450 int moisture; double Koguprotsent; int tempHigh =6; // relee mis avab luugi int tempLow =5; //relee mis suleb luugi int led = 13; //led pin kütte releele int X=0; void setup(void) { pinMode (tempLow, OUTPUT); pinMode (tempHigh, OUTPUT); pinMode (waterPump, OUTPUT); pinMode (led, OUTPUT); pinMode (waterLed, OUTPUT); digitalWrite(waterPump, LOW); digitalWrite(waterLed, HIGH); digitalWrite (tempLow, LOW); digitalWrite (tempHigh, HIGH); digitalWrite (led, HIGH); // start serial port Serial.begin(9600); // Start up the library sensors.begin(); // set the resolution to 10 bit (good enough?) sensors.setResolution(insideThermometer, 10); // sensors.setResolution(outsideThermometer, 10); // sensors.setResolution(dogHouseThermometer, 10); } void printTemperature(DeviceAddress deviceAddress) { float tempC = sensors.getTempC(deviceAddress); if (tempC == -127.00) { Serial.print("Error getting temperature"); } else { Serial.print("C: "); Serial.print(tempC); //-- panin koodi siia.. } if (tempC >= 24 && X ==0){ digitalWrite(tempHigh, LOW); Serial.print("Stop heating."); digitalWrite(led, LOW); //delay(6000); //digitalWrite(tempHigh, LOW); X = 1; } if (tempC <= 24 && X ==1){ Serial.print("Heating start"); X = 0; digitalWrite(tempHigh, HIGH); digitalWrite(led, HIGH); //delay(6000); //digitalWrite(tempLow, LOW); } // Serial.print(" F: "); // Serial.print(DallasTemperature::toFahrenheit(tempC)); } void loop(void) { //---- soil // Serial.print("Getting Soil Moisture...\n\r"); moisture=SoilMoisture(); // soilmoister as variable Koguprotsent = ((moisture*100)/950.0); // mina sain max väärtuseks 950 Serial.print("Niiskuse absoluut arv: "); Serial.println(moisture); Serial.print("Mullas on niiskust "); Serial.print(Koguprotsent); Serial.print(" % "); Serial.println(); delay(1000); // tuleks sättida endale sobivaks. if (moisture >= 650){ digitalWrite(waterPump, LOW); Serial.print(" Water pump off"); digitalWrite(waterLed, LOW); } if (moisture <= 600){ digitalWrite(waterPump, HIGH); Serial.print("Water pump High"); digitalWrite(waterLed, HIGH); delay(1000); //pumba töö aeg.Katsetamise käigus selgub palju oleks normaalne aeg pumba tööks,et ei tekiks uputust. digitalWrite(waterPump, LOW); } //---------- temp delay(1000); Serial.print("Getting temperatures...\n\r"); sensors.requestTemperatures(); Serial.print("Inside temperature is: "); printTemperature(insideThermometer); Serial.print("\n\r"); // Serial.print("Outside temperature is: "); // printTemperature(outsideThermometer); // Serial.print("\n\r"); // Serial.print("Dog House temperature is: "); // printTemperature(dogHouseThermometer); // Serial.print("\n\r\n\r"); } int SoilMoisture(){ int reading; // set driver pins to outputs pinMode(divider_top,OUTPUT); pinMode(divider_bottom,OUTPUT); // drive a current through the divider in one direction digitalWrite(divider_top,LOW); digitalWrite(divider_bottom,HIGH); // wait a moment for capacitance effects to settle delay(1000); // take a reading reading=analogRead(moisture_input); // reverse the current digitalWrite(divider_top,HIGH); digitalWrite(divider_bottom,LOW); // give as much time in 'reverse' as in 'forward' delay(1000); // stop the current digitalWrite(divider_bottom,LOW); return reading; //relays for temp pinMode(tempHigh,OUTPUT); }