Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <OneWire.h>
- #include <LiquidCrystal.h>
- #include <DallasTemperature.h>
- #include <Wire.h>
- #include "Sodaq_DS3231.h"
- char weekDay[][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
- uint32_t old_ts;
- //LCD 20x4 pins
- LiquidCrystal lcd(22, 24, 26, 28, 30, 32);
- // 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 };
- int tempHigh1 =53; // relee 1 mis avab luugi
- int tempLow1 =51; //relee 2 mis suleb luugi
- int tempHigh2 =49; // relee 3 mis avab luugi
- int tempLow2 =47; //relee 4 mis suleb luugi
- int tempHigh3 =45; // relee 5 mis avab luugi
- int tempLow3 =43; //relee 6 mis suleb luugi
- int X=0;
- void setup(void)
- {
- Serial.begin(57600);
- Wire.begin();
- rtc.begin();
- lcd.begin(20, 4);
- lcd.clear();
- //lcd.setCursor(0,0);
- pinMode (tempLow1, OUTPUT);
- pinMode (tempHigh1, OUTPUT);
- pinMode (tempLow2, OUTPUT);
- pinMode (tempHigh2, OUTPUT);
- pinMode (tempLow3, OUTPUT);
- pinMode (tempHigh3, OUTPUT);
- digitalWrite (tempLow1, HIGH);
- digitalWrite (tempHigh1, HIGH);
- digitalWrite (tempLow2, HIGH);
- digitalWrite (tempHigh2, HIGH);
- digitalWrite (tempLow3, HIGH);
- digitalWrite (tempHigh3, 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(tempHigh1, HIGH);
- Serial.print("Palav on liiga.Avame luugi.");
- delay(6000); //luugi avamise aeg mootorile
- digitalWrite(tempHigh1, LOW);
- X = 1;
- }
- if (tempC <= 24 && X ==1){
- Serial.print("Jahedaks kisub.Sulgeme luugi.");
- X = 0;
- digitalWrite(tempLow1, HIGH);
- delay(6000); // luugi sulgemise aeg mootorile
- digitalWrite(tempLow1, LOW);
- }
- }
- void loop(void)
- {
- //---------- 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);
- //{
- DateTime now = rtc.now(); //get the current date-time
- uint32_t ts = now.getEpoch();
- if (old_ts == 0 || old_ts != ts)
- old_ts = ts;
- Serial.print(now.year(), DEC);
- Serial.print('/');
- Serial.print(now.month(), DEC);
- Serial.print('/');
- Serial.print(now.date(), DEC);
- Serial.print(' ');
- Serial.print(now.hour(), DEC);
- Serial.print(':');
- Serial.print(now.minute(), DEC);
- Serial.print(':');
- Serial.print(now.second(), DEC);
- Serial.print(' ');
- Serial.print(weekDay[now.dayOfWeek()]);
- Serial.println();
- Serial.print("Seconds since Unix Epoch: ");
- Serial.print(ts, DEC);
- Serial.println();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement