#include <Wire.h>
#include <Adafruit_GFX.h>
#include <max7219.h>
#include <DHT.h>
#include <DS1307RTC.h>
#include <TimeLib.h>
// Konfigurasi Dot Matrix MAX7219
#define CLK_PIN 13
#define DIN_PIN 11
#define CS_PIN 10
Adafruit_7segment matrix = Adafruit_7segment();
// Konfigurasi DHT22
#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
// Inisialisasi Dot Matrix MAX7219
matrix.begin(CLK_PIN, DIN_PIN, CS_PIN);
// Inisialisasi DHT22
dht.begin();
// Inisialisasi komunikasi RTC DS1307
setSyncProvider(RTC.get);
if (timeStatus() != timeSet) {
Serial.println("Unable to sync with RTC");
} else {
Serial.println("RTC has set the system time");
}
}
void loop() {
// Baca data suhu dan kelembaban dari DHT22
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Baca waktu dari RTC DS1307
tmElements_t tm;
if (RTC.read(tm)) {
int hour = tm.Hour;
int minute = tm.Minute;
int second = tm.Second;
// Tampilkan waktu pada Dot Matrix
matrix.print(hour * 100 + minute);
matrix.drawColon(true);
matrix.writeDisplay();
// Tampilkan suhu pada Serial Monitor
Serial.print("Suhu: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Kelembaban: ");
Serial.print(humidity);
Serial.println(" %");
} else {
Serial.println("Gagal membaca waktu dari RTC");
}
delay(1000); // Tunda selama 1 detik
}