#include <DHT.h>
#include <LedControl.h>
#define DHTPIN 2
#define DHTTYPE DHT22
#define buzzerPin 8
DHT dht(DHTPIN, DHTTYPE);
// Initialize the LED matrix (Pin 12: Data, Pin 11: Clock, Pin 10: Load/CS)
LedControl lc = LedControl(12, 11, 10, 1);
void setup() {
Serial.begin(9600);
dht.begin();
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
delay(2000);
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
if (isnan(humidity) || isnan(temperature)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(F("Humidity: "));
Serial.print(humidity);
Serial.print(F("% Temperature: "));
Serial.print(temperature);
Serial.println(F("°C"));
displayNumber(int(temperature)); // Display temperature on the LED matrix
if (temperature > 30) { // Sound buzzer if temperature is above 30°C
tone(buzzerPin, 1000); // Generate a tone at 1000 Hz
delay(100);
noTone(buzzerPin);
}
}
void displayNumber(int num) {
lc.clearDisplay(0);
lc.setDigit(0, 1, (num / 10) % 10, false);
lc.setDigit(0, 0, num % 10, false);
}