Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <OneWire.h>
- #include <LiquidCrystal.h>
- #include <DallasTemperature.h>
- #include <DHT.h>
- #define DHTPIN 7 // what pin we're connected to D7
- // Uncomment whatever type you're using!
- //#define DHTTYPE DHT11 // DHT 11
- #define DHTTYPE DHT22 // DHT 22 (AM2302)
- //#define DHTTYPE DHT21 // DHT 21 (AM2301)
- DHT dht(DHTPIN, DHTTYPE);
- /*LCD 20x4 pins for Mega
- 1- GND
- 2- +5V
- 3- GND in my 20x4 lcd contrast
- 4- D22
- 5- GND
- 6- D24
- 7- NC
- 8- NC
- 9- NC
- 10- NC
- 11- D26
- 12- D28
- 13- D30
- 14- D32
- 15- NC
- 16- NC
- pins D8, D9 for first h-bridge, for motor nr.1 what open and close window nr.1
- I used Stepper-Motor-Drive-Controller-Board-Module-L298N-Dual-H-Bridge-DC-For-Arduino
- in bridged mode In1+In3 and In2+In4 is bridged and outputs 1-3 and 2-4 is bridged for 4A
- current
- */
- LiquidCrystal lcd(22, 24, 26, 28, 30, 32);
- // Data wire is plugged into pin D2 on the Arduino
- #define ONE_WIRE_BUS 2
- // 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
- //sensors.getAddress(deviceAddress, index)
- //DeviceAddress pinnaseThermometer = { 0x28, 0x0A, 0x03, 0xD9, 0x04, 0x00, 0x00, 0x93 };
- DeviceAddress kasvuhoonesThermometer = { 0x28, 0xEA, 0xD6, 0xBB, 0x05, 0x00, 0x00, 0x0A };
- DeviceAddress outdoorThermometer = { 0x28, 0xBB, 0xF1, 0xBB, 0x05, 0x00, 0x00, 0xBA };
- //DeviceAddress mullasThermometer = { 0x28, 0x1F, 0xAA, 0xDA, 0x02, 0x00, 0x00, 0xBA };
- int tempHigh =A3; // relee mis avab luugi i do not use this time
- int tempLow =A4; //relee mis suleb luugi, i do not use this time
- //int MOTOR1 =8;
- //int MOTOR2 =9;
- int X=0;
- void setup(void)
- {
- lcd.begin(20, 4);
- lcd.clear();
- //lcd.setCursor(0,0);
- pinMode (tempLow, OUTPUT);
- pinMode (tempHigh, OUTPUT);
- //pinMode (MOTOR1. OUTPUT); //for motor 1
- //pinMode (MOTOR2, OUTPUT); //for motor1
- 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); //greenhouse
- sensors.setResolution(outdoorThermometer, 9);
- //sensors.setResolution(mullasThermometer, 9);
- }
- void printTemperature(DeviceAddress deviceAddress)
- {
- float tempC = sensors.getTempC(outdoorThermometer);
- float tempC1 = sensors.getTempC(kasvuhoonesThermometer); // temp in greenhouse
- if (tempC == -127.00) {
- Serial.print("Error getting temperature");
- } else {
- Serial.print(tempC);
- Serial.print(tempC1);
- Serial.print("C ");
- lcd.setCursor(11, 1);
- lcd.print("Out:");
- lcd.print(tempC ,1);
- lcd.print("C");
- lcd.setCursor(0,1);
- lcd.print("In:");
- lcd.print(tempC1 ,1);
- lcd.print("C");
- //-- panin koodi siia..
- }
- Serial.println();
- if (tempC >= 27 && X ==0){
- digitalWrite(tempHigh, HIGH);
- digitalWrite(8, HIGH); //start open window pin for H-bridge 1
- digitalWrite(9, LOW); // start open window pin for H-bridge 1
- Serial.print("Palav on liiga.Avame luugi.");//fucking warm, i open windows
- lcd.setCursor(0,0);
- lcd.print(" Avame luugi");
- delay(6000); //time for h-bridge to open window
- digitalWrite(tempHigh, LOW);
- digitalWrite(8, LOW); // stop motor, pin for H-bridge 1
- digitalWrite(9, LOW); // stop motor, pin for H-bridge 1
- lcd.setCursor(0,0);
- lcd.print(" Luuk on avatud"); //window is open
- X = 1;
- }
- if (tempC <= 26 && X ==1){
- Serial.print("Jahedaks kisub.Sulgeme luugi"); //this means, weather is cold and needed close window
- lcd.setCursor(0, 0);
- lcd.print(" Sulgeme luugi"); //start close window
- Serial.print(tempC);
- Serial.print("C ");
- lcd.setCursor(0, 1);
- lcd.print("Out:");
- lcd.print(tempC ,1);
- lcd.print("C");
- X = 0;
- digitalWrite(tempLow, HIGH);
- digitalWrite(8, LOW); //start close window pin for H-bridge 1
- digitalWrite(9, HIGH); // start clse window pin for H-bridge 1
- delay(6000); // time for h-bridge close window
- digitalWrite(tempLow, LOW);
- digitalWrite(8, LOW); //stop close window pin for H-bridge 1
- digitalWrite(9, LOW); // stop close window pin for H-bridge 1
- lcd.setCursor(0,0);
- lcd.print(" Luuk on suletud"); //window is closed
- }
- }
- void loop(void)
- {
- float h = dht.readHumidity();
- float t = dht.readTemperature();
- // check if returns are valid, if they are NaN (not a number) then something went wrong!
- if (isnan(t) || isnan(h)) {
- Serial.println("Failed to read from DHT");
- } else {
- Serial.print("Humidity: ");
- Serial.print(h);
- Serial.print(" %\t");
- Serial.print("Temperature: ");
- Serial.print(t);
- Serial.println(" *C");
- lcd.setCursor(7,2);
- lcd.print("DHT22");
- lcd.setCursor(0,3);
- lcd.print("H:");
- lcd.print(h ,1);
- lcd.print("% ");
- lcd.print(" T:");
- lcd.print(t ,1);
- lcd.print("*C");
- }
- //---------- 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);
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement