#include <TM1637Display.h>
#include <DHT.h>
// Define the DHT11 sensor and TM1637 pins
#define DHTPIN 2 // DHT11 sensor data pin connected to digital pin 2
#define DHTTYPE DHT22 // Define the type of DHT sensor (DHT11)
#define CLK 4 // TM1637 clock pin connected to digital pin 4
#define DIO 5 // TM1637 data pin connected to digital pin 5
DHT dht(DHTPIN, DHTTYPE); // Initialize the DHT11 sensor
TM1637Display display(CLK, DIO); // Initialize the TM1637 display
void setup() {
dht.begin(); // Start the DHT sensor
display.setBrightness(0x0f); // Set the brightness of the TM1637 display
}
void loop() {
float humidity = dht.readHumidity(); // Read humidity from DHT11
float temperature = dht.readTemperature(); // Read temperature from DHT11
// Check if readings are valid
if (isnan(humidity) || isnan(temperature)) {
display.showNumberDec(9999); // Show error if reading fails
} else {
// Display temperature on TM1637
int temp = (int)temperature; // Convert temperature to int for display
display.showNumberDec(temp); // Show temperature on the TM1637 display
}
delay(2000); // Wait 2 seconds before reading again
}