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?