This is an old revision of the document!
This project describes a local weather station, which is included in a larger Android application.
The purpose of this project is to provide a proof-of-concept for adding local weather stations to standard weather applications, in order to have a more granular approach on weather based on customizable location and measured data.
In the above schematics, the following pins are connected:
The local weather station will send data to a database, in order to facilitate access to retrieved data. For this project, a Firebase real-time database is used.
The Arduino code consists of a few key elements used, from both a Firebase connection perspective, and a BME280 sensor perspective. The full code can be found at the Github link provided in the references section.
In order to measure altitude correctly, BME280 needs a reference pressure for sea level:
#define SEALEVELPRESSURE_HPA (1013.25)
BME280 can transmit data using either I2C or SPI. For this project, I2C was used. By default, the sensor uses I2C, but if the user would like to use SPI, this is possible by editing the if structure and calling bme using the SPI pins as parameters.
#define USEIIC 1 #if(USEIIC) Adafruit_BME280 bme; #else // define SPI pins #endif
In order to use Firebase and connect to WiFi for data transmission, multiple defines are used.
In the setup function, the BME280 sensor is initialized and the network connection is done.
void setup(){ Serial.begin(115200); // Init the BME280 sensor bool rslt; rslt = bme.begin(); if (!rslt) { Serial.println("Could not initialize sensor, make sure it is properly connected!"); while(1); } Serial.println("BME280 successfully initialized"); ....... // Start connecting to WiFi network WiFi.begin(WIFI_SSID, WIFI_PASSWORD); Serial.print("Connecting to Wi-Fi"); while (WiFi.status() != WL_CONNECTED){ Serial.print("."); delay(300); } Serial.println(); Serial.print("Connected with IP: "); Serial.println(WiFi.localIP()); Serial.println(); /* Assign the api key (required) */ config.api_key = API_KEY; /* Assign the RTDB URL (required) */ config.database_url = DATABASE_URL; /* Sign up */ if (Firebase.signUp(&config, &auth, "", "")){ Serial.println("ok"); signupOK = true; } ....... }
The Firebase database is a real-time database, which stores the values captured by the sensor in respective nodes: temperature, humidity, pressure and altitude respectively. The below picture gives a look into the database from an admin perspective:
The Android application used is part of a larger project, which also provides access to global weather forecast using an API. By using the data collected by the BME280 sensor and stored in the Firebase database, the granularity of data (across a city, for example) is increased. The screenshots below illustrate how the app can be navigated in order to access the local weather station in Bucharest. A different forecast can also be retrieved for Bucharest using the API, thus providing two points of data collection in Bucharest.