Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <Adafruit_BMP085.h>
- #include "DHT.h"
- #include <DS3231.h>
- #include <OneWire.h>
- #include "DallasTemperature.h"
- #include <EtherCard.h>
- static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
- byte Ethernet::buffer[700];
- static uint32_t timer;
- const char website[] PROGMEM = "www.mojastrona.pl";
- char buffer[128];
- static void my_callback (byte status, word off, word len)
- {
- Serial.println(">>>");
- Ethernet::buffer[off+300] = 0;
- Serial.print((const char*) Ethernet::buffer + off);
- Serial.println("...");
- }
- DS3231 clock;
- RTCDateTime dt;
- LiquidCrystal_I2C lcd(0x27,20,4); //set the LCD address to 0x27 for a 20 chars and 4 line display
- byte thermometer[8] = //icon for thermometer
- {
- B00100,
- B01010,
- B01010,
- B01110,
- B01110,
- B11111,
- B11111,
- B01110
- };
- byte droplet[8] = //icon for droplet
- {
- B00100,
- B00100,
- B01010,
- B01010,
- B10001,
- B10001,
- B10001,
- B01110,
- };
- Adafruit_BMP085 bmp;
- #define DHTPIN 9 // what pin we're connected to
- #define DHTTYPE DHT22 //DHT 22 (AM2302)
- DHT dht(DHTPIN, DHTTYPE); //initialize DHT sensor for normal 16mhz Arduino
- #define ONE_WIRE_BUS1 7 //data wire is plugged into port 7 on the Arduino
- #define ONE_WIRE_BUS2 6 //data wire is plugged into port 6 on the Arduino
- OneWire oneWire1(ONE_WIRE_BUS1); //setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
- OneWire oneWire2(ONE_WIRE_BUS2); //setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
- DallasTemperature sensors1(&oneWire1); //pass our oneWire reference to Dallas Temperature.
- DallasTemperature sensors2(&oneWire2); //pass our oneWire reference to Dallas Temperature.
- float temp1, min1 = 100, max1 = -100;
- float temp2, min2 = 100, max2 = -100;
- float hum, hummin = 99, hummax = 1;
- float currentPressurehp, presmin = 1020, presmax = 980;
- const int buttonPin = 2;
- int buttonState = 0;
- int nRainIn = A1;
- int nRainDigitalIn = 8;
- int nRainVal;
- boolean bIsRaining = false;
- String strRaining;
- void setup()
- {
- Serial.begin(57600);
- pinMode(buttonPin, INPUT); //przycisk
- pinMode(12, INPUT); //czujnik deszczu
- Serial.println(F("\n[webClient]")); // tu sie zaczyna kod dla ethernetu
- if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
- Serial.println(F("Failed to access Ethernet controller"));
- if (!ether.dhcpSetup())
- Serial.println(F("DHCP failed"));
- ether.printIp("IP: ", ether.myip);
- ether.printIp("GW: ", ether.gwip);
- ether.printIp("DNS: ", ether.dnsip);
- if (!ether.dnsLookup(website))
- Serial.println("DNS failed");
- ether.printIp("SRV: ", ether.hisip);
- lcd.init(); //initialize the lcd
- lcd.backlight(); //switch on backlight on lcd
- clock.begin();
- clock.setDateTime(__DATE__, __TIME__);
- Wire.begin();
- dht.begin();
- bmp.begin();
- sensors1.begin(); //start up the library
- sensors2.begin(); //start up the library
- sensors1.setResolution(12); // ustalamy rozdzielczoฤนโบรโก pomiaru
- lcd.createChar(1, thermometer);
- lcd.createChar(2, droplet);
- lcd.setCursor(4,3);
- lcd.print("#powitanie#");
- lcd.setCursor(0,0);
- lcd.print("Stacja pogodowa z");
- lcd.setCursor(0,1);
- lcd.print("wykorzystaniem");
- lcd.setCursor(0,2);
- lcd.print("Arduino :)");
- delay(2000);
- lcd.clear();
- }
- void loop()
- {
- nRainVal = analogRead(nRainIn); //czujnik deszczu
- bIsRaining = !(digitalRead(nRainDigitalIn)); //czujnik deszczu
- if(bIsRaining)
- {
- strRaining = "PADA";
- }
- else
- {
- strRaining = "NIE PADA";
- }
- buttonState = digitalRead(buttonPin); //przycisk
- sensors1.requestTemperatures(); //send the command to get temperatures
- sensors2.requestTemperatures(); //send the command to get temperatures
- temp1 = sensors1.getTempCByIndex(0);
- temp2 = sensors2.getTempCByIndex(0);
- if(temp1 < min1)
- min1 = temp1;
- if(temp1 > max1)
- max1 = temp1;
- if(temp2 < min2)
- min2 = temp2;
- if(temp2 > max2)
- max2 = temp2;
- lcd.setCursor(0,0);
- lcd.write(1);
- lcd.print("in");
- lcd.print(" ");
- lcd.print(temp1, 1); //temperature for the device 1
- lcd.write(0b11011111);
- lcd.print("C");
- lcd.setCursor(0,1);
- lcd.write(1);
- lcd.print("out");
- lcd.print(" ");
- lcd.print(temp2, 1); //temperature for the device 2
- lcd.write(0b11011111);
- lcd.print("C");
- dt = clock.getDateTime();
- lcd.setCursor(15,0);
- if (dt.hour<10) lcd.print("0");
- lcd.print(dt.hour);
- lcd.print(":");
- if (dt.minute<10) lcd.print("0");
- lcd.print(dt.minute);
- lcd.setCursor(0,2);
- lcd.write(2);
- lcd.print(" ");
- lcd.print(hum, 1); //print out humiditi from dht22
- lcd.print("%");
- float seaLevelPressure = 102150;
- float currentPressure = bmp.readPressure();
- float currentPressurehp = (currentPressure /100);
- float altitude = bmp.readAltitude(seaLevelPressure);
- lcd.setCursor(0,3);
- lcd.print("P ");
- lcd.print(currentPressurehp);
- lcd.print("hPa");
- lcd.setCursor(12,2);
- lcd.print(strRaining);
- if(hum < hummin)
- hummin = hum;
- if(hum > hummax)
- hummax = hum;
- if(currentPressurehp < presmin)
- presmin = currentPressurehp;
- if(currentPressurehp > presmax)
- presmax = currentPressurehp;
- bool przyciskbool = false;
- delay(1000);
- if(buttonState == HIGH)
- przyciskbool = true;
- else
- przyciskbool = false;
- if(przyciskbool = true)
- {
- delay(20);
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.write(1);
- lcd.print("in max ");
- lcd.print(max1); //temperature for the device 1
- lcd.write(0b11011111);
- lcd.print("C");
- lcd.setCursor(0,1);
- lcd.write(1);
- lcd.print("in min ");
- lcd.print(min1); //temperature for the device 1
- lcd.write(0b11011111);
- lcd.print("C");
- lcd.setCursor(0,2);
- lcd.write(1);
- lcd.print("out max ");
- lcd.print(max2);
- lcd.setCursor(0,3);
- lcd.write(1);
- lcd.print("out min ");
- lcd.print(min2);
- delay(3500);
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.write(2);
- lcd.print("max ");
- lcd.print(hummax);
- lcd.setCursor(0,1);
- lcd.write(2);
- lcd.print("min ");
- lcd.print(hummin);
- lcd.setCursor(0,2);
- lcd.print("Pmax ");
- lcd.print(presmax);
- lcd.setCursor(0,3);
- lcd.print("Pmin ");
- lcd.print(presmin);
- }
- if (millis() > timer)
- {
- timer = millis() + 5000;
- Serial.println();
- Serial.print("<<< REQ ");
- sprintf(buffer, "temp1=%d&temp2=%d&hum=%d&pressure=%d&rain=%d", String(temp1).c_str(), String(temp2).c_str(), String(hum).c_str(), String(currentPressurehp).c_str(), String(strRaining).c_str());
- ether.browseUrl(PSTR("/add.php?"), buffer, website, my_callback);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement