#include <LiquidCrystal_I2C.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include "RTClib.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
#define DHTPIN 2
#define DHTTYPE DHT22
DHT_Unified dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
int counter = 0;
void setup()
{
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Hello");
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Today is:");
dht.begin();
sensor_t sensor;
dht.temperature().getSensor(&sensor);
dht.humidity().getSensor(&sensor);
Serial.begin(115200);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
}
void loop()
{
DateTime now = rtc.now();
Serial.print("Current time: ");
Serial.print(now.day(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.year(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.print(':');
Serial.println();
Serial.println();
delay(3000);
delay(100);
sensors_event_t event;
dht.temperature().getEvent(&event);
if (!isnan(event.temperature)) {
lcd.setCursor(0,1);
lcd.print(event.temperature); // pokazwa gradusite ot senzora DHT 22
lcd.print(F("\xdf")); // oznachenie gradus
lcd.print(F("C")); // oznachenie C
}
dht.humidity().getEvent(&event);
if (!isnan(event.relative_humidity)) {
lcd.setCursor(0,2);
lcd.print(event.relative_humidity);
lcd.print(F("%"));} // procenti humidity
}