Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <OneWire.h>
- #include <DallasTemperature.h>
- //relay and moisture sensor
- //http://robocraft.ru/blog/arduino/444.html in russian
- //temperature from DS18B20
- // Data wire is plugged into pin 3 on the Arduino
- #define ONE_WIRE_BUS 3
- // 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, 0x2B, 0xE6, 0xDA, 0x02, 0x00, 0x00, 0x43 };
- //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 9 // moisture resistor digital pin 9
- #define divider_bottom 10 // moisture sensor 1 digital pin 10
- int waterPump =7; // led, water pump digital pin 7
- int moisture;
- int Koguprotsent; //moisture % in Estonian
- int tempHigh =6; // relay who open window
- int tempLow =5; //relay who close window
- int X=0;
- void setup(void)
- {
- pinMode (tempLow, OUTPUT);
- pinMode (tempHigh, OUTPUT);
- pinMode (waterPump, OUTPUT);
- digitalWrite(waterPump, LOW);
- digitalWrite (tempLow, LOW);
- digitalWrite (tempHigh, LOW);
- // 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..,comment in estonian means nothing, only for me
- }
- if (tempC >= 24 && X ==0){ // if temp => 27 window opened
- digitalWrite(tempHigh, HIGH);
- delay(6000);
- digitalWrite(tempHigh, LOW);
- X = 1;
- }
- if (tempC <= 22 && X ==1){ // if temp <= 24 window close
- X = 0;
- digitalWrite(tempLow, 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/1024); // moisture %
- Serial.print("Sensors moisture value: ");
- Serial.println(moisture);
- Serial.print("Moisture is ");
- Serial.print(Koguprotsent);
- Serial.print(" % ");
- Serial.println();
- delay(1000); // pause 1 sec.
- if (Koguprotsent >= 80){ //if moisture is 90 % water pump off
- digitalWrite(waterPump, LOW);
- }
- if (Koguprotsent <= 75){
- digitalWrite(waterPump, LOW); // if moisture is 75 % water pump on
- delay(1000); //how many sec water pump is ON
- digitalWrite(waterPump, HIGH); // water pump OFF
- }
- //---------- 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);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement