Advertisement
Guest User

Untitled

a guest
Nov 5th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.36 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3. #include <Adafruit_BMP085.h>
  4. #include "DHT.h"
  5. #include <DS3231.h>
  6. #include <OneWire.h>
  7. #include "DallasTemperature.h"
  8. #include <EtherCard.h>
  9.  
  10. static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
  11. byte Ethernet::buffer[700];
  12. static uint32_t timer;
  13. const char website[] PROGMEM = "www.mojastrona.pl";
  14. char buffer[128];
  15. static void my_callback (byte status, word off, word len)
  16. {
  17. Serial.println(">>>");
  18. Ethernet::buffer[off+300] = 0;
  19. Serial.print((const char*) Ethernet::buffer + off);
  20. Serial.println("...");
  21. }
  22.  
  23. DS3231 clock;
  24. RTCDateTime dt;
  25. LiquidCrystal_I2C lcd(0x27,20,4); //set the LCD address to 0x27 for a 20 chars and 4 line display
  26.  
  27. byte thermometer[8] = //icon for thermometer
  28. {
  29. B00100,
  30. B01010,
  31. B01010,
  32. B01110,
  33. B01110,
  34. B11111,
  35. B11111,
  36. B01110
  37. };
  38.  
  39. byte droplet[8] = //icon for droplet
  40. {
  41. B00100,
  42. B00100,
  43. B01010,
  44. B01010,
  45. B10001,
  46. B10001,
  47. B10001,
  48. B01110,
  49. };
  50.  
  51. Adafruit_BMP085 bmp;
  52.  
  53. #define DHTPIN 9 // what pin we're connected to
  54. #define DHTTYPE DHT22 //DHT 22 (AM2302)
  55. DHT dht(DHTPIN, DHTTYPE); //initialize DHT sensor for normal 16mhz Arduino
  56.  
  57. #define ONE_WIRE_BUS1 7 //data wire is plugged into port 7 on the Arduino
  58. #define ONE_WIRE_BUS2 6 //data wire is plugged into port 6 on the Arduino
  59. OneWire oneWire1(ONE_WIRE_BUS1); //setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
  60. OneWire oneWire2(ONE_WIRE_BUS2); //setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
  61. DallasTemperature sensors1(&oneWire1); //pass our oneWire reference to Dallas Temperature.
  62. DallasTemperature sensors2(&oneWire2); //pass our oneWire reference to Dallas Temperature.
  63.  
  64. float temp1, min1 = 100, max1 = -100;
  65. float temp2, min2 = 100, max2 = -100;
  66. float hum, hummin = 99, hummax = 1;
  67. float currentPressurehp, presmin = 1020, presmax = 980;
  68.  
  69. const int buttonPin = 2;
  70. int buttonState = 0;
  71.  
  72. int nRainIn = A1;
  73. int nRainDigitalIn = 8;
  74. int nRainVal;
  75. boolean bIsRaining = false;
  76. String strRaining;
  77.  
  78. void setup()
  79. {
  80. Serial.begin(57600);
  81.  
  82. pinMode(buttonPin, INPUT); //przycisk
  83. pinMode(12, INPUT); //czujnik deszczu
  84.  
  85. Serial.println(F("\n[webClient]")); // tu sie zaczyna kod dla ethernetu
  86. if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
  87. Serial.println(F("Failed to access Ethernet controller"));
  88. if (!ether.dhcpSetup())
  89. Serial.println(F("DHCP failed"));
  90. ether.printIp("IP: ", ether.myip);
  91. ether.printIp("GW: ", ether.gwip);
  92. ether.printIp("DNS: ", ether.dnsip);
  93. if (!ether.dnsLookup(website))
  94. Serial.println("DNS failed");
  95. ether.printIp("SRV: ", ether.hisip);
  96.  
  97. lcd.init(); //initialize the lcd
  98. lcd.backlight(); //switch on backlight on lcd
  99.  
  100. clock.begin();
  101. clock.setDateTime(__DATE__, __TIME__);
  102. Wire.begin();
  103. dht.begin();
  104. bmp.begin();
  105. sensors1.begin(); //start up the library
  106. sensors2.begin(); //start up the library
  107. sensors1.setResolution(12); // ustalamy rozdzielczoฤนโ€บร„โ€ก pomiaru
  108.  
  109. lcd.createChar(1, thermometer);
  110. lcd.createChar(2, droplet);
  111.  
  112. lcd.setCursor(4,3);
  113. lcd.print("#powitanie#");
  114. lcd.setCursor(0,0);
  115. lcd.print("Stacja pogodowa z");
  116. lcd.setCursor(0,1);
  117. lcd.print("wykorzystaniem");
  118. lcd.setCursor(0,2);
  119. lcd.print("Arduino :)");
  120. delay(2000);
  121. lcd.clear();
  122. }
  123.  
  124.  
  125. void loop()
  126. {
  127. nRainVal = analogRead(nRainIn); //czujnik deszczu
  128. bIsRaining = !(digitalRead(nRainDigitalIn)); //czujnik deszczu
  129.  
  130. if(bIsRaining)
  131. {
  132. strRaining = "PADA";
  133. }
  134. else
  135. {
  136. strRaining = "NIE PADA";
  137. }
  138.  
  139. buttonState = digitalRead(buttonPin); //przycisk
  140.  
  141. sensors1.requestTemperatures(); //send the command to get temperatures
  142. sensors2.requestTemperatures(); //send the command to get temperatures
  143. temp1 = sensors1.getTempCByIndex(0);
  144. temp2 = sensors2.getTempCByIndex(0);
  145.  
  146. if(temp1 < min1)
  147. min1 = temp1;
  148. if(temp1 > max1)
  149. max1 = temp1;
  150.  
  151. if(temp2 < min2)
  152. min2 = temp2;
  153. if(temp2 > max2)
  154. max2 = temp2;
  155.  
  156. lcd.setCursor(0,0);
  157. lcd.write(1);
  158. lcd.print("in");
  159. lcd.print(" ");
  160. lcd.print(temp1, 1); //temperature for the device 1
  161. lcd.write(0b11011111);
  162. lcd.print("C");
  163.  
  164. lcd.setCursor(0,1);
  165. lcd.write(1);
  166. lcd.print("out");
  167. lcd.print(" ");
  168. lcd.print(temp2, 1); //temperature for the device 2
  169. lcd.write(0b11011111);
  170. lcd.print("C");
  171.  
  172. dt = clock.getDateTime();
  173. lcd.setCursor(15,0);
  174. if (dt.hour<10) lcd.print("0");
  175. lcd.print(dt.hour);
  176. lcd.print(":");
  177. if (dt.minute<10) lcd.print("0");
  178. lcd.print(dt.minute);
  179.  
  180. lcd.setCursor(0,2);
  181. lcd.write(2);
  182. lcd.print(" ");
  183. lcd.print(hum, 1); //print out humiditi from dht22
  184. lcd.print("%");
  185.  
  186. float seaLevelPressure = 102150;
  187. float currentPressure = bmp.readPressure();
  188. float currentPressurehp = (currentPressure /100);
  189. float altitude = bmp.readAltitude(seaLevelPressure);
  190.  
  191. lcd.setCursor(0,3);
  192. lcd.print("P ");
  193. lcd.print(currentPressurehp);
  194. lcd.print("hPa");
  195.  
  196. lcd.setCursor(12,2);
  197. lcd.print(strRaining);
  198.  
  199. if(hum < hummin)
  200. hummin = hum;
  201. if(hum > hummax)
  202. hummax = hum;
  203.  
  204. if(currentPressurehp < presmin)
  205. presmin = currentPressurehp;
  206. if(currentPressurehp > presmax)
  207. presmax = currentPressurehp;
  208.  
  209. bool przyciskbool = false;
  210. delay(1000);
  211.  
  212. if(buttonState == HIGH)
  213. przyciskbool = true;
  214. else
  215. przyciskbool = false;
  216.  
  217. if(przyciskbool = true)
  218. {
  219. delay(20);
  220. lcd.clear();
  221. lcd.setCursor(0,0);
  222. lcd.write(1);
  223. lcd.print("in max ");
  224. lcd.print(max1); //temperature for the device 1
  225. lcd.write(0b11011111);
  226. lcd.print("C");
  227.  
  228. lcd.setCursor(0,1);
  229. lcd.write(1);
  230. lcd.print("in min ");
  231. lcd.print(min1); //temperature for the device 1
  232. lcd.write(0b11011111);
  233. lcd.print("C");
  234.  
  235. lcd.setCursor(0,2);
  236. lcd.write(1);
  237. lcd.print("out max ");
  238. lcd.print(max2);
  239.  
  240. lcd.setCursor(0,3);
  241. lcd.write(1);
  242. lcd.print("out min ");
  243. lcd.print(min2);
  244.  
  245. delay(3500);
  246. lcd.clear();
  247.  
  248. lcd.setCursor(0,0);
  249. lcd.write(2);
  250. lcd.print("max ");
  251. lcd.print(hummax);
  252.  
  253. lcd.setCursor(0,1);
  254. lcd.write(2);
  255. lcd.print("min ");
  256. lcd.print(hummin);
  257.  
  258. lcd.setCursor(0,2);
  259. lcd.print("Pmax ");
  260. lcd.print(presmax);
  261.  
  262. lcd.setCursor(0,3);
  263. lcd.print("Pmin ");
  264. lcd.print(presmin);
  265. }
  266.  
  267.  
  268.  
  269. if (millis() > timer)
  270. {
  271. timer = millis() + 5000;
  272. Serial.println();
  273. Serial.print("<<< REQ ");
  274. 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());
  275. ether.browseUrl(PSTR("/add.php?"), buffer, website, my_callback);
  276. }
  277.  
  278. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement