.
-
08/14/2023
Temp And Humidity Monitor
Writing about Temp And Humidity Monitor for educational and informational purposes only. however, do not hesitate to use this information on your own risk as we make no warranty of any kind.
Monitoring Temperature And Humidity with Arduino
#include
#include
#define DHTPIN 5 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11 sensor type
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
// Initialize the OLED display
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("Start");
display.display();
delay(2000);
display.clearDisplay();
}
void loop() {
delay(2000); // Wait for 2 seconds between measurements
float temperatureC = dht.readTemperature(); // Read temperature in Celsius
float humidity = dht.readHumidity(); // Read humidity in percent
// Check if any reads failed and exit if so
if (isnan(temperatureC) || isnan(humidity)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Convert Celsius to Fahrenheit
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
// Update OLED display with current LED and score
display.clearDisplay();
display.setCursor(0, 0);
display.print("FT: ");
display.println(temperatureF);
display.setCursor(0, 20);
display.print("H%: ");
display.print(humidity);
display.display();
}