SHARE
TWEET

Home_weather_station

Al_Ninyo Mar 18th, 2015 (edited) 464 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <DS1302.h>
  3.  
  4. namespace {
  5.  
  6. // Set the appropriate digital I/O pin connections. These are the pin
  7. // assignments for the Arduino as well for as the DS1302 chip. See the DS1302
  8. // datasheet:
  9. //
  10. //   http://datasheets.maximintegrated.com/en/ds/DS1302.pdf
  11.  
  12. //DS1302 pins
  13. const int kCePin   = 10;  // Chip Enable (RST)
  14. const int kIoPin   = 9;  // Input/Output (DA)
  15. const int kSclkPin = 8;  // Serial Clock (CLK)
  16.  
  17. //LCD pins
  18. //RST - 6
  19. //CE - 7
  20. //DC - 5
  21. //Din - 4
  22. //Clk - 3
  23.  
  24.  
  25. // Create a DS1302 object.
  26. DS1302 rtc(kCePin, kIoPin, kSclkPin);
  27.  
  28. String dayAsString(const Time::Day day) {
  29.   switch (day) {
  30.     case Time::kSunday: return "Вс";
  31.     case Time::kMonday: return "Пн";
  32.     case Time::kTuesday: return "Вт";
  33.     case Time::kWednesday: return "Ср";
  34.     case Time::kThursday: return "Чт";
  35.     case Time::kFriday: return "Пт";
  36.     case Time::kSaturday: return "Сб";
  37.   }
  38.   return "(unknown day)";
  39. }
  40. }  // namespace
  41.  
  42. #include <PCD8544.h>
  43. static PCD8544 lcd;
  44.  
  45. #include "DHT.h"
  46.  
  47. #define DHTPIN 13
  48. #define DHTTYPE DHT11
  49.  
  50. DHT dht(DHTPIN, DHTTYPE);
  51.  
  52. float tempOut;
  53. int tOut;
  54. int tempOutPin = 7; // пин подключения LM35DZ
  55.  
  56. void setup() {
  57.   Serial.begin(9600);
  58.   dht.begin();
  59.   lcd.begin(84, 48);
  60.   //раскомментить, чтобы задать время!
  61.  
  62. //  rtc.writeProtect(false);
  63. //  rtc.halt(false);
  64.     // Sunday, September 22, 2013 at 01:38:50.
  65. //  Time t(2015, 3, 18, 20, 54, 50, Time::kWednesday);
  66.  
  67.     // Set the time and date on the chip.
  68. //  rtc.time(t);
  69.   lcd.setCursor(0,0);
  70.   lcd.print("Подождите,");
  71.   lcd.setCursor(0,1);
  72.   lcd.print("включаюсь!");
  73. }
  74.  
  75. void loop() {
  76.       // Get the current time and date from the chip.
  77.   Time t = rtc.time();
  78.  
  79.   // Name the day of the week.
  80.   const String day = dayAsString(t.day);
  81.  
  82.   // Format the time and date and insert into the temporary buffer.
  83.   char buf[50];
  84.   snprintf(buf, sizeof(buf), "%s %02d.%02d.%04d %02d:%02d:%02d      ",
  85.            day.c_str(),
  86.            t.date, t.mon, t.yr,
  87.            t.hr, t.min, t.sec);
  88.   if (fmod(t.min,10) == 0 && t.sec == 0) {
  89.    lcd.clear();
  90.   }
  91.   if (fmod(t.sec,10) == 0) {
  92.     int h = dht.readHumidity();
  93.     int t = dht.readTemperature();
  94.     tempOut = analogRead(tempOutPin);
  95.     tempOut = tempOut * 0.48828125;
  96.     tOut = (int) tempOut;
  97.     if (isnan(t) || isnan(h)) {
  98.       Serial.println("Failed to read from DHT");
  99.       lcd.setCursor(0, 0);
  100.       lcd.print("Failed to read from DHT");
  101.     } else {
  102.       lcd.setCursor(0, 0);
  103.       lcd.print("Темп-ра Дом/Ул");
  104.       lcd.setCursor(0, 1);
  105.       if (t < 10) {
  106.         lcd.print(t);
  107.         lcd.print(" ");
  108.       } else {
  109.          lcd.print(t);
  110.         }
  111.       lcd.setCursor(12, 1);
  112.       lcd.print(" / ");
  113.       if (tempOut < 10) {
  114.         lcd.print(tOut);
  115.         lcd.print(" ");
  116.       } else {
  117.          lcd.print(tOut);
  118.         }
  119.       lcd.print(" *C");
  120.       lcd.setCursor(0, 2);
  121.       lcd.print("Влажность ");
  122.       lcd.setCursor(0, 3);
  123.       lcd.print(h);
  124.       lcd.setCursor(12, 3);
  125.       lcd.print("%");
  126.       lcd.setCursor(24, 3);
  127.         if (h < 40) {
  128.           lcd.print("- сухо\t");
  129.         } else if (h > 60) {
  130.           lcd.print("- мокро\t");
  131.         } else {
  132.           lcd.print("- норма\t");
  133.         }
  134. /*    Serial.print("Humidity: ");
  135.     Serial.print(h);
  136.     Serial.print(" %\t");
  137.     Serial.print("Temperature: ");
  138.     Serial.print(t);
  139.     Serial.println(" *C");
  140.     Serial.print("TEMPRATURE = ");
  141.   Serial.print(tempOut);
  142.   Serial.print("*C");
  143.   Serial.println();
  144. */
  145.     }
  146.   }
  147.   // Print the formatted string to serial so we can see the time.
  148.   Serial.println(buf);
  149.   lcd.setCursor(0, 4);
  150.   lcd.print(buf);
  151. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top