Code Logic Explained - santhoshsharuk/-AI-Weather-Station-MVP- GitHub Wiki

Here's the Code Logic Explained page in Markdown format for your GitHub Wiki:


# 🧠 Code Logic Explained

This page explains how the **AI Weather Station MVP** Arduino sketch works β€” step by step.

The code reads data from sensors (DHT11 & BMP180), applies rule-based logic, and outputs a weather forecast via the **Serial Monitor**.

---

## πŸ” Main Flow of the Code

```cpp
void loop() {
  readSensors();
  calculateForecast();
  displayOutput();
  delay(5000); // Wait 5 seconds before next update
}

πŸ“₯ 1. Reading Sensor Data

DHT11 β€” Temperature & Humidity

float temp = dht.readTemperature();
float humidity = dht.readHumidity();
  • dht.readTemperature() gets the temperature in Celsius.
  • dht.readHumidity() gets the relative humidity in percentage.

BMP180 β€” Pressure

float pressure = bmp.readPressure() / 100.0; // Convert to hPa
  • bmp.readPressure() returns pressure in Pascals, so it’s divided by 100 to convert to hPa.

🧠 2. Rule-Based Forecasting Logic

The forecast is made using simple if-else rules that simulate AI behavior:

if (humidity > 80 && pressure < 1000) {
  forecast = "Rain Possible";
} else if (humidity < 50 && pressure > 1015) {
  forecast = "Clear Day";
} else {
  forecast = "Stable Weather";
}

βœ… Explanation:

  • Rain Possible β†’ High humidity AND low pressure
  • Clear Day β†’ Low humidity AND high pressure
  • Stable Weather β†’ Anything else (no strong weather signal)

πŸ“€ 3. Displaying Output

All the data is shown in the Serial Monitor using:

Serial.print("Temp: ");
Serial.print(temp);
Serial.println(" Β°C");

Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");

Serial.print("Pressure: ");
Serial.print(pressure);
Serial.println(" hPa");

Serial.print("Forecast: ");
Serial.println(forecast);
Serial.println("-------------------------");

⏱ Delay Between Updates

The following line ensures the system waits 5 seconds before repeating:

delay(5000);

πŸ“„ Sample Output

Temp: 27.8 Β°C  
Humidity: 85.2 %  
Pressure: 998.7 hPa  
Forecast: Rain Possible  
-------------------------

πŸ§ͺ Want to Expand?

You can:

  • Modify thresholds for your local environment
  • Add more rules
  • Integrate with machine learning later using SD card or cloud data

Check out the [Future Plans](./Future-Plans) page to learn how.



---

### βœ… To Add This Page to Your Wiki:

1. Go to your **GitHub Wiki**.
2. Click **"New Page"**.
3. Title it `Code Logic Explained`.
4. Paste the Markdown content above.
5. Click **Save**.

Would you like the next page (like **Circuit Diagram**, **Future Plans**, or **FAQ**) too?