Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. #include "RTClib.h"
  2. #include <Wire.h>
  3. #include <LiquidCrystal_I2C.h>
  4. #include "DHT.h"
  5.  
  6. //DHT22
  7. #define DHTPIN 2 // Digital pin connected to the DHT sensor
  8. #define DHTTYPE DHT22
  9. DHT dht(DHTPIN, DHTTYPE);
  10.  
  11. //LCD Screen
  12. LiquidCrystal_I2C lcd(0x27,20,4);
  13.  
  14.  
  15. //Real Time Clock
  16. RTC_DS3231 rtc;
  17. char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  18. DateTime now = rtc.now();
  19.  
  20.  
  21. /**************************** void setup ***************************/
  22. void setup() {
  23.  
  24. Serial.begin(9600);
  25.  
  26.  
  27. //DHT22
  28. dht.begin();
  29.  
  30. //Real Time Clock
  31. if (! rtc.begin()) {
  32. Serial.println("Couldn't find RTC");
  33. while (1);
  34. }
  35.  
  36. if (rtc.lostPower()) {
  37. Serial.println("RTC lost power, lets set the time!");
  38. rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  39. }
  40. DateTime now = rtc.now();
  41.  
  42. //LCD Screen
  43. lcd.init();
  44. lcd.backlight();
  45.  
  46. //Print REV Version
  47. lcd.clear();
  48. lcd.setCursor(0,0);
  49. lcd.print("Generator ATS");
  50. lcd.setCursor(2,1);
  51. lcd.print("REV 1.0");
  52. Serial.println("Generator ATS");
  53. Serial.println("REV 1.0");
  54. delay(2000);
  55.  
  56.  
  57.  
  58. }
  59.  
  60.  
  61. /**************************** void loop ***************************/
  62. void loop() {
  63.  
  64. void DHT_sensor();
  65.  
  66.  
  67.  
  68. }
  69.  
  70.  
  71.  
  72. /**************************** void DHT_sensor ****************************/
  73.  
  74.  
  75. void DHT_sensor() {
  76.  
  77. delay(2000);
  78. Serial.println(F("Reading Humidity & Temprature..."));
  79. delay(1000);
  80.  
  81. float humidity = dht.readHumidity();
  82. float temp = dht.readTemperature();
  83.  
  84. // Check if any reads failed and exit early (to try again).
  85. if (isnan(humidity) || isnan(temp)) {
  86. Serial.println(F("Failed to read from DHT sensor!"));
  87. return;
  88. }
  89.  
  90. Serial.print(F("Humidity: "));
  91. Serial.print(humidity);
  92. Serial.print(F("Temperature: "));
  93. Serial.print(temp);
  94. Serial.println(F("°C "));
  95. delay(1000);
  96. }
  97.  
  98.  
  99. /**************************** End of void DHT_sensor ***************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement