fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. // -----------------------------------------------------
  6. // MOCK SENSOR FUNCTIONS (Replace with real sensor code)
  7. // -----------------------------------------------------
  8.  
  9. float readDHT11Temperature() { return 25.0; } // Example data
  10. float readDHT11Humidity() { return 55.0; }
  11.  
  12. float readLM35Temperature() { return 24.5; }
  13. float readDS18B20Temperature(){ return 25.2; }
  14.  
  15. bool readRainSensor() { return false; } // false = NO rain, true = RAIN
  16. bool readMoistureSensor() { return false; } // false = DRY, true = WET
  17. bool readWaterLevelSensor() { return false; } // false = NORMAL, true = HIGH
  18.  
  19. int readMQ135() { return 250; } // Higher = more polluted
  20. bool readLDR() { return true; } // true = Bright, false = Dark
  21.  
  22. int readBMP180Pressure() { return 101325; }
  23. float readBMP180Altitude() { return 45.6; }
  24.  
  25. bool readWindSensor() { return false; } // false = normal, true = high wind
  26.  
  27. // -----------------------------------------------------
  28. // WINDOW CONTROL (Mock Servo Motor)
  29. // -----------------------------------------------------
  30. void openWindow() {
  31. cout << "🪟 Window State : OPENED\n";
  32. }
  33. void closeWindow() {
  34. cout << "🪟 Window State : CLOSED\n";
  35. }
  36.  
  37. // -----------------------------------------------------
  38. // MAIN PROGRAM
  39. // -----------------------------------------------------
  40. int main() {
  41.  
  42. cout << "\n========== AUTOMATIC CLIMATE SENSITIVE WINDOW ==========\n\n";
  43.  
  44. // ------------ READ ALL SENSORS -----------------
  45. float dhtTemp = readDHT11Temperature();
  46. float dhtHum = readDHT11Humidity();
  47. float lm35 = readLM35Temperature();
  48. float ds18b20 = readDS18B20Temperature();
  49. bool rain = readRainSensor();
  50. bool moist = readMoistureSensor();
  51. bool water = readWaterLevelSensor();
  52. int air = readMQ135();
  53. bool light = readLDR();
  54. int pressure = readBMP180Pressure();
  55. float altitude= readBMP180Altitude();
  56. bool wind = readWindSensor();
  57.  
  58. // ------------ DISPLAY SENSOR DATA ---------------
  59. cout << "📡 SENSOR READINGS:\n";
  60. cout << "-----------------------------------------------------\n";
  61. cout << "DHT11 Temperature : " << dhtTemp << " °C\n";
  62. cout << "DHT11 Humidity : " << dhtHum << " %\n";
  63. cout << "LM35 Temperature : " << lm35 << " °C\n";
  64. cout << "DS18B20 Temp : " << ds18b20 << " °C\n";
  65. cout << "Rain Sensor : " << (rain ? "RAINING" : "NO RAIN") << "\n";
  66. cout << "Soil Moisture : " << (moist ? "WET" : "DRY") << "\n";
  67. cout << "Water Level : " << (water ? "HIGH" : "NORMAL") << "\n";
  68. cout << "Air Quality (MQ135): " << air << " (higher = polluted)\n";
  69. cout << "Light Sensor (LDR): " << (light ? "BRIGHT" : "DARK") << "\n";
  70. cout << "BMP180 Pressure : " << pressure << " Pa\n";
  71. cout << "BMP180 Altitude : " << altitude << " m\n";
  72. cout << "Wind Sensor : " << (wind ? "HIGH WIND" : "NORMAL") << "\n";
  73. cout << "-----------------------------------------------------\n\n";
  74.  
  75. // ------------ DECISION LOGIC -------------------
  76. cout << "🤖 SYSTEM DECISION:\n";
  77.  
  78. // Best temperature source
  79. float finalTemp = dhtTemp;
  80. if (finalTemp == 0) finalTemp = lm35;
  81. if (finalTemp == 0) finalTemp = ds18b20;
  82.  
  83. // Safety first
  84. if (rain) {
  85. cout << "🌧 Rain Detected → Window Closed\n";
  86. closeWindow();
  87. }
  88. else if (wind) {
  89. cout << "💨 High Wind → Window Closed\n";
  90. closeWindow();
  91. }
  92. else if (water) {
  93. cout << "💧 High Water Level → Window Closed\n";
  94. closeWindow();
  95. }
  96. else if (air > 400) {
  97. cout << "🌫 Poor Air Quality → Window Closed\n";
  98. closeWindow();
  99. }
  100. // Temperature logic
  101. else if (finalTemp < 20) {
  102. cout << "❄ Too Cold → Window Closed\n";
  103. closeWindow();
  104. }
  105. else if (finalTemp > 30) {
  106. cout << "☀ Too Hot → Window Closed\n";
  107. closeWindow();
  108. }
  109. else if (moist) {
  110. cout << "💧 Moisture Detected → Window Closed\n";
  111. closeWindow();
  112. }
  113. else {
  114. cout << "🌤 Comfortable Range → Window Opened\n";
  115. openWindow();
  116. }
  117.  
  118. cout << "\n=======================================================\n";
  119. return 0;
  120. }
  121.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
========== AUTOMATIC CLIMATE SENSITIVE WINDOW ==========

📡 SENSOR READINGS:
-----------------------------------------------------
DHT11 Temperature : 25 °C
DHT11 Humidity    : 55 %
LM35 Temperature  : 24.5 °C
DS18B20 Temp      : 25.2 °C
Rain Sensor       : NO RAIN
Soil Moisture     : DRY
Water Level       : NORMAL
Air Quality (MQ135): 250 (higher = polluted)
Light Sensor (LDR): BRIGHT
BMP180 Pressure   : 101325 Pa
BMP180 Altitude   : 45.6 m
Wind Sensor       : NORMAL
-----------------------------------------------------

🤖 SYSTEM DECISION:
🌤 Comfortable Range → Window Opened
🪟 Window State : OPENED

=======================================================