Lab Manual 8 Weather Forecast
Lab Manual 8 Weather Forecast
Title:
Implementation of a weather forecast system using the ADC modules of an Arduino.
Objectives:
The objectives of this experiment are to-
1. Familiarize the students with the Micro-controller-based weather forecast system
2. Measure environmental parameters, such as temperature, pressure, and humidity.
Weather Prediction
The BMP180 or MPL115A is an absolute device that can be used to predict and measure barometric
pressure to deduce weather patterns. Weather prediction requires a static location for the sensor and
2-3 hours to analyze a full weather pattern. Typically, the pressure changes due to weather are slow,
requiring a few hours to determine the sloping of the pressure change. Vertical movement or a
significant airflow can interfere with results due to only weather patterns in barometric pressure. The
sensor should be kept in a relatively protected area from any strong air flows and kept at that static
location during analysis. Temperature effects can change the results of a normal pressure sensor
especially if the measurement is done over several hours at varying temperatures. Due to the nature
of the calibration and temperature compensation, BMP180 meets these requirements, compensating
for temperature swings over a large 0 to 85°C operating range. It will not require auto-zeroing for
shifts in offset or span-over temperature.
If bad weather originates in an area in the formation of water-vapor clouds, this is falling pressure on
a barometer. The vapor will reduce the barometric pressure as the H2O reduces the mass above that
point on the earth. High pressure will signal the clearing of the water vapor as the air dries.
Another quandary is how weather during severe hurricanes/cyclones with high 150 mph winds be
defined as low pressure because hurricanes are low-pressure conditions surrounded by higher
pressure. The rush of air from higher to lower-pressure regions creates fast-moving winds. The lower
the pressure in the center, the greater the differential pressure between high and low areas. This leads
to a stronger cyclone or hurricane.
In some areas, it is harder to predict weather patterns. An example is cities located at the base of
mountainous regions where condensation and fog are a daily occurrence. An area like Hawaii where
high colder mountains meet low warm sea regions can have harder to predict results. A network of
sensors can give a more exact trend, but for a single sensor in a static location, there are a few ways
to have a simple standalone weather station.
Airports are typical reporting stations to check barometric pressure. Some display only normalized
pressure during a web search. This is such that a pilot landing at any airport can deduce the weather
conditions by knowing the barometric pressure. If the airport is located at the beach, or in a
mountainous region, normalization of this value removes the barometric variation due to the altitude.
It standardizes pressure so that weather patterns can be mapped.
Example:
An airport located at 600 m elevation would have a pressure of 93.97 kPa according to our pressure
to altitude equation. If the weather was sunny and mostly clear, it would most probably have a
published pressure of 101.3 kPa for weather conditions. It may not be extremely clear skies as this
would be a high-pressure weather system. It would be a stable pressure with neither extreme low nor
high pressure.
Remember to discern this information when trying to see if the MPL115A value matches the local
weather barometric pressure. Sometimes a disparity in the value occurs due to normalization.
Another approach that is more direct and quicker in calculating the weather in the simple approach
is to know the current altitude. This cuts the need to wait and see a “trend”.
By using the equation below:
Where p0 = 101.3 kPa, and h is the current altitude, the pressure for the local barometric can be
calculated. This is the pressure for good sunny weather at the current altitude location.
By using the pressure equation and knowing the normalized good weather pressure for the current
location (best for a static weather station), the weather can be deduced by the difference. As in the
table for the weather symbols, the ideal pressure is compared to the value from the MPL115A and
the appropriate symbol of Sun/Cloud/Rain is selected.
Below simple C code from the DEMOAPEXSENSOR demo kit that calculates which weather
symbol to display on the LCD screen.
▪ CurrentAltitude - (m) Altitude in meters that is entered into the system by the user for that
current static location.
▪ Pweather - (kPa) Pressure at the current altitude. It is calculated using the Height (m) to
Pressure (kPa) exponential equation, inputting CurrentAltitude in meters. This is the ideal
pressure for the current location on a stable relatively sunny day.
▪ decPcomp - (kPa) Value of compensated pressure from BMP180/MPL115A.
-359/7990m
For example, Altitude for Tempe, AZ = 359 m, thus PWeather = 101.3 x e = 96.85 kPa.
Observing Pressure over time will yield similar results over 12 hours. In this case, the changes in the
pressure that takes place over an extended time will be enough for the simple method to figure out
the weather patterns. This negates the need for user input of the approximate location/altitude. The
weather algorithm will be more accurate at the end of the 12-hour interval as the trend is visible
versus at initialization.
Knowing the altitude can also be useful for a dynamically changing location to predict simple
weather. Take for example a GPS unit: a GPS unit can give an approximate altitude measurement.
Measuring the difference from the MPL115A pressure sensor and calculated pressure from the GPS
altitude gives a close approximation of weather patterns quickly at that dynamically changing point.
Weather approximation can be deduced in the symbol style as above.
as time progresses, the weather can be broken into more exact categories than the simple approach
of basic symbols.
This can also use less time than waiting for a full 12 hours to see the pattern of pressure change. In
Table 3, the ranges of pressure change over time leading to the definition of the weather patterns
shown. It is a change in the pressure per hour. 2-3 hours are needed to deduce how the pressure is
migrating.
Analysis Output
dP/dt > 0.25 kPa/h Quickly rising High-Pressure System, not stable
0.05 kPa/h < dP/dt < 0.25 kPa/h Slowly rising High-Pressure System, stable good
-0.05 kPa/h < dP/dt < 0.05 kPa/h Stable weather condition
-0.25 kPa/h < dP/dt < -0.05 kPa/h Slowly falling Low-Pressure System, stable rainy
dP/dt < -0.25 kPa/h Quickly falling Low Pressure, Thunderstorm, not
In the provided flowchart, the pressure is sampled every minute for 3 hours/180 minutes into a data
array. The first 5 minutes are averaged, followed by 5 minutes near the first ½ hour point. Consecutive
½ hour marks have 5-minute averaged data points stored. This leads to 7 averaged results over the
180 minutes depicting the pressure every ½ hour. Once the data- points are collected, the patterns
are deduced. A flowchart provides the method used in deducing the weather pattern. The initial
starting point is the reference from which every ½ hour data point is compared to. As the pressure
falls, the value is compared and divided so that the change in pressure per 1 hour is compared every
half an hour.
Hardware implementation:
Connect the circuit diagram as follows, upload the program into the board, and then run the program.
Observe the weather parameters on the OLED display.
Components List
▪ Arduino Uno Board
▪ BMP180 / MPL115A
▪ inches96 inch OLED 128X64
▪ Breadboard and Jump Wires
Program:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_BMP085.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
void loop() {
// put your main code here, to run repeatedly:
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,5);
display.print("BMP180");
display.setCursor(0,19);
display.print("T=");
display.print(bmp.readTemperature(),1);
display.println("*C");
currentpressure=bmp.readPressure()/100.0;
predictedweather=(101.3*exp(((float)(currentaltitude))/(-7900)));
simpleweatherdifference=currentpressure-predictedweather;
//display.clearDisplay();
display.setCursor(0,50);
if (simpleweatherdifference>0.25)
display.print("SUNNY");
if (simpleweatherdifference<=0.25)
display.print("SUNNY/CLOUDY");
if (simpleweatherdifference<-0.25)
display.print("RAINY");
display.display();
delay(2000);
}