-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.cpp
More file actions
68 lines (55 loc) · 2.06 KB
/
Copy pathCode.cpp
File metadata and controls
68 lines (55 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
Project: AetherSense
Description:
AetherSense is an Arduino UNO-based temperature and humidity monitoring system
using the DHT11 sensor. It displays real-time readings on the Serial Monitor
and controls an LED indicator when temperature exceeds a set threshold.
Hardware:
- Arduino UNO
- DHT11 sensor (connected to pin 7)
- LED with resistor (connected to pin 12)
Libraries Required:
- DHT sensor library by Adafruit
- Adafruit Unified Sensor library
*/
#include <DHT.h>
// ------------------ Pin Configuration ------------------
#define DHTPIN 7 // DHT11 Data pin connected to Arduino pin 7
#define DHTTYPE DHT11 // Define sensor type
#define LED_PIN 12 // LED connected to pin 12
// ------------------ Threshold & Constants ------------------
const float TEMP_THRESHOLD = 30.0; // Temperature threshold in °C
// Create DHT object
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600); // Initialize Serial Monitor
dht.begin(); // Initialize DHT11 sensor
pinMode(LED_PIN, OUTPUT); // Set LED pin as output
Serial.println(F("🌡️ AetherSense Initialized"));
Serial.println(F("Monitoring Temperature & Humidity..."));
Serial.println(F("-----------------------------------"));
}
void loop() {
// Read temperature (°C) and humidity (%)
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// Check if reading failed
if (isnan(temperature) || isnan(humidity)) {
Serial.println(F("Error: Failed to read from DHT11 sensor!"));
delay(2000);
return;
}
// ------------------ LED Control ------------------
if (temperature >= TEMP_THRESHOLD) {
digitalWrite(LED_PIN, HIGH); // Turn LED ON if hot
} else {
digitalWrite(LED_PIN, LOW); // Turn LED OFF if normal
}
// ------------------ Serial Output ------------------
Serial.print(F("Temperature: "));
Serial.print(temperature);
Serial.print(F(" °C | Humidity: "));
Serial.print(humidity);
Serial.println(F(" %"));
delay(5000); // Wait for 5 seconds before next reading
}