Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <OneWire.h>
- #include <LiquidCrystal.h>
- #include <DallasTemperature.h>
- //LCD 20x4 pins
- LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
- // Data wire is plugged into pin 3 on the Arduino
- #define ONE_WIRE_BUS 3
- //#define contrastPin 9
- //#define contrast 110
- // 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 pinnaseThermometer = { 0x28, 0x0A, 0x03, 0xD9, 0x04, 0x00, 0x00, 0x93 };
- DeviceAddress kasvuhoonesThermometer = { 0x28, 0xF3, 0x33, 0xD8, 0x04, 0x00, 0x00, 0x7C };
- DeviceAddress outdoorThermometer = { 0x28, 0xB3, 0xD9, 0xD8, 0x04, 0x00, 0x00, 0x6E };
- DeviceAddress mullasThermometer = { 0x28, 0x1F, 0xAA, 0xDA, 0x02, 0x00, 0x00, 0xBA };
- #define moisture_input A0 // analog pin 0 nael 1
- #define divider_top A1 // takisti analog pin 1 10K A1-st A0-i, divider top
- #define divider_bottom A2 // nael 2 analog pin 2
- int waterPump =A5; // led, water pump analog pin 5
- int moisture;
- int Koguprotsent;
- int tempHigh =A3; // relee mis avab luugi
- int tempLow =A4; //relee mis suleb luugi
- int X=0;
- void setup(void)
- {
- lcd.begin(16, 2);
- lcd.clear();
- lcd.setCursor(0,0);
- pinMode (tempLow, OUTPUT);
- pinMode (tempHigh, OUTPUT);
- pinMode (waterPump, OUTPUT);
- digitalWrite(waterPump, HIGH);
- digitalWrite (tempLow, HIGH);
- digitalWrite (tempHigh, HIGH);
- // start serial port
- Serial.begin(9600);
- // Start up the library
- sensors.begin();
- // set the resolution to 10 bit (good enough?)
- sensors.setResolution(pinnaseThermometer, 9);
- sensors.setResolution(kasvuhoonesThermometer, 9);
- sensors.setResolution(outdoorThermometer, 9);
- sensors.setResolution(mullasThermometer, 9);
- }
- void printTemperature(DeviceAddress deviceAddress)
- {
- float tempC = sensors.getTempC(deviceAddress);
- if (tempC == -127.00) {
- Serial.print("Error getting temperature");
- } else {
- Serial.print(tempC);
- Serial.print("C ");
- //-- panin koodi siia..
- }
- Serial.println();
- if (tempC >= 27 && X ==0){
- digitalWrite(tempHigh, HIGH);
- Serial.print("Palav on liiga.Avame luugi.");
- delay(6000); //luugi avamise aeg mootorile
- digitalWrite(tempHigh, LOW);
- X = 1;
- }
- if (tempC <= 24 && X ==1){
- Serial.print("Jahedaks kisub.Sulgeme luugi.");
- X = 0;
- digitalWrite(tempLow, HIGH);
- delay(6000); // luugi sulgemise aeg mootorile
- digitalWrite(tempLow, LOW);
- }
- }
- void loop(void)
- {
- //---- soil
- // digitalWrite(waterPump, HIGH);
- // Serial.print("Getting Soil Moisture...\n\r");
- moisture=SoilMoisture(); // soilmoister as variable
- Koguprotsent = ((moisture*100)/900); // mina sain max väärtuseks 950
- Serial.print("Niiskuse absoluut arv: ");
- Serial.println(moisture);
- delay(2000);
- Serial.print("Mullas on niiskust ");
- Serial.print(Koguprotsent);
- Serial.print(" % ");
- Serial.println();
- delay(2000); // tuleks sättida endale sobivaks.
- if (Koguprotsent >= 38){
- Serial.print("Pinnas on niiske parajalt.");
- delay(1000);
- Serial.println();
- // digitalWrite(waterPump, HIGH);
- }
- if (Koguprotsent <= 37){
- Serial.print("Peab kastma.Appi-appi!!!Kuivame!");
- digitalWrite(waterPump, LOW);
- delay(1000); //pumba töö aeg.Katsetamise käigus selgub palju oleks normaalne aeg pumba tööks,et ei tekiks uputust.
- digitalWrite(waterPump, HIGH);
- Serial.println();
- }
- //---------- temp
- delay(1000);
- Serial.print("Getting temperatures...\n\r");
- sensors.requestTemperatures();
- delay(2000);
- Serial.print("Mulla temperature is: ");
- printTemperature(pinnaseThermometer);
- Serial.print("\n\r");
- delay(1000);
- Serial.print("Kasvuhoones temperature is: ");
- printTemperature(kasvuhoonesThermometer);
- Serial.print("\n\r");
- delay(1000);
- Serial.print("Outdoor temperature is: ");
- printTemperature(outdoorThermometer);
- Serial.print("\n\r");
- delay(1000);
- Serial.print("Mullas temperature is: ");
- printTemperature(mullasThermometer);
- Serial.print("\n\r");
- delay(1000);
- }
- 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);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement