Introduction: Multi-functional Weather Station (Mega2560 Version)

Among the previous Arduino project outcomes, this one becomes the most useful and continually utilized for several months until today.

This is a common weather station circuit that shows temperature, humidity, and air pressure information on LCD using an Arduino Mega board.

All the weather data captured by sensors are recorded to SD card storage along with the timestamp.

But to enhance the device's usefulness, clock and digital album functionalities are also included with the weather station.

Every weekdays morning, I'm checking the time now on the LCD until go out for catching the bus going to my office.

Also checking atmospheric pressure is also helpful to look at its high or low pressure.

When it's a little bit low pressure, I'm checking the weather app of my smartphone to know whether it's raining today or not.

And for fun, I can understand the long-term indoor environment changes in my room in terms of temperature, humidity, and air pressure.

When humidity drops drastically (such as less than 40%) on any day, I turned on a humidifier to prevent sore throat the next morning.

Anyway, it's become a very useful device for my everyday living. 

Let's look at more details of the weather station circuit.

Step 1: Weather Station Functionality

When looking at more detail about weather station functionality, the picture above shows long-term indoor room temperature change trends.

Measuring started on 18th April 2021 and the result was compiled on 11th December 2021.

All sensors were accessed every 15 seconds and a total of 650,000 records are collected during 237 days.

Among the diverse weather info, and only the temperature data summary is shown in the graph above.

The maximum temperature is Celcius 34 degrees and the lowest is 19 degrees.

As Korea is located in the mid-latitude region, even room temperature is following outdoor atmospheric temperature.

Because no air conditioner is installed in my room, I spent hot summer from July 10th to 16th August.

From the 14th of November, cold winter is starting and room temperature also falling a minimum of 19 degrees.

If more data is collected in the next year, maybe I can find the general climate trends of my house in Korea.

Let's look at the circuit in more detail from the next step.

Step 2: Schematics and Parts

From the beginning, I consider connecting all possible sensors such as DHT22, atmospheric pressure sensor, noise, light sensors, and so on.

Also, I'm trying to integrate diverse functionalities such as clock and digital photograph album along with weather station.

As a result, Arduino Uno (ATmega328P) is not appropriate for this project as flash memory is just 32K.

Meanwhile Arduino Mega (ATmega2560) can support a relatively high capacity of up to 256K.

Especially, the digital photo album program is quite bulky as including diverse graphic libraries are required as shown in the previous Arduino project below.


https://www.instructables.com/BMP-Image-File-Album-and-Digital-Clock-With-Arduin/


As details are described in the Instructable above, interfacing TFT LCD along with an integrated SD reader is a little bit tricky.

Therefore, I'm using an independent SD reader break-out board for collecting all sensing data with a timestamp. (But later I found the specific wiring method for utilizing SD reader integrated to the TFT LCD module)

The following parts are used for making the Arduino weather station circuit.

- Arduino Mega2560 board

- 1.8 inch TFT LCD module (SD reader is integrated)

- SD card break-out

- DS3231 real-time clock

- DHT 22 temperature and humidity sensor

- BMP280 atmospheric pressure sensor (including temperature sensor)

- LM393 sound sensor

- LDR (Light Dependent Resistor) sensor

- Acrylic boards

- 12V external power supply

Although I had included the LM393 sound sensor in this weather station circuit, any noise capturing by the sensor is almost impossible as the sensitivity of it is quite poor.

Anyway, all these sub-components are tightly integrated and assembled inside between two acrylic boards.

Step 3: TFT LCD and DS3231 Interface

As for wiring methods of TFT LCD (SPI), SD card (SPI), and DS3231 (I2C) are explained many times in other projects (Instructables), I'll not explain details here.

In the case of TFT LCD and SD card, both devices are required to share SPI bus.

If a different CS (Chip Selector) pin is assigned to the LCD and SD module, other pins such as MOSI (51), MISO (50), SCK (52) can be shared between two devices.

Or totally different approach can be used as I had done with this weather station circuit.

You can redefine TFT LCD control lines as follow in the sketch program.

 ***

#define TFT_cs        4

#define TFT_sclk      5

#define TFT_mosi      6

#define TFT_dc        7    // Or set to -1 and connect to Arduino RESET pin

#define TFT_rst       8

// For 1.44" and 1.8" TFT with ST7735 use:

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_cs, TFT_dc, TFT_mosi, TFT_sclk, TFT_rst);

***

And you can assign frequently used pins of Arduino Mega2560 for controlling the SD card module as follows.

***

SD card module MOSI -> Mega pin 51

MISO -> Mega pin 50

SCK -> Mega pin 52

CS -> Mega pin 53

 ***


With the above wiring scheme, TFT LCD and SD card modules are correctly recognized by Arduino Mega.

As interfacing DS3231 is explained in so many web pages, I'll not mention details here.

The DS3231 is an I2C device, it can easily interface with Mega by using pin 20 (SDA) and pin 21 (SCL).

The DS3231 produces timestamps of captured weather data including temperature, humidity, and air pressure.

Step 4: Connecting DHT22 and LDR

The DHT22 is a major sensor capturing room temperature and humidity data.

As the sketch program used for controlling DHT22 is frequently introduced in other projects (or Instructables), the same program is utilized for the weather station circuit.

Actually, the LDR is no specific role in the weather station circuit from the beginning.

A data captured from LDR via Arduino analog port is a simple resistance value from 0 ~ 1024.

But with this data, I can figure out when I go to bed as the value suddenly become small because I turned off the desk lamp.

Anyway, the LDR is included in the weather station as a sensor for measuring room light intensity.

Step 5: Connecting BMP280 Atmospheric Pressure Sensor

This is the completely new type of sensor that I'm utilizing for the first time.

It supports the I2C communication bus and requires 3.3V input voltage.

The BMP280 can measure temperature and atmospheric pressure at the same time.

For correct installation, you need to know the I2C address of the sensor by scanner program which can be downloaded from the Internet.

You can refer to the following web page for the details about installing the BMP280 sensor.

https://create.arduino.cc/projecthub/SurtrTech/bmp280-measure-temperature-pressure-and-altitude-e1c857

According to the direction written on the web page, the BMP280 library header file definition should be corrected according to the identified I2C address.

This part is a little bit unique for the BMP280 when comparing other common sensors.

When correctly following the directions as described in the web page above, the BMP280 shows room temperature, air pressure, and approximate altitude. 

But the measured temperature by the BMP280 is about 2 degrees higher than the measurement from DHT22.

As DHT22 is a temperature & humidity measuring oriented sensor, I think DHT22 measurement is more reliable and correct.

Regarding the altitude measurement by the BMP280, actual altitude can be calculated by subtracting the sea level pressure from the air pressure measured by the BMP280 sensor.

As I'm stationing the made weather station circuit at the same location, (Therefore, no altitude change occurred) this altitude data has no meaning.

But if you are making a portable weather station device, you should subtract sea level pressure from the measured air pressure by the BMP280 sensor.

You need to check the information of the local Meteorological Agency to find sea level pressure in the city you are living.

Step 6: Sketch Program

As you can see in the screenshot of the sketch program, many header files (also related libraries) are included.

Except for the BMP 280 sensor controlling program code, all other functionalities are already had been introduced in the previous projects.

The reading air pressure and altitude is just simple library function calls as shown in sketch C++ code below.

*** BMP 280 code 

float t_pressure = 0; 

String air_pressure = "";

String home_height = "";

String other_temp = "";

// get temperature, pressure and altitude from library

float BMP_temp = bmp280.readTemperature(); // get temperature

float pressure   = bmp280.readPressure();    // get pressure

float altitudes  = bmp280.readAltitude(1013.25); // get altitude (this should be adjusted to your local forecast)

***

Based on the digital album program (Showing BMP files on TFT LCD), devices control (DHT22, BMP 280, LDR, LM393 sensor, DS3231 RTC) programs are simply merged together.

Therefore, I will not introduce sketch program details in this Instructable.

Please refer sketch program as attached in the file of this step.

Step 7: Data Collecting and Collected Air Pressure Data Summary

As mentioned in the previous step, weather data is collected per 15 seconds and stored in a text file in the SD card storage.

When the date is changed (from 11:59:59 pm to 12:00:00 am), a new text file is created by the following sketch code.

*** New text file creation code

today_str = "20"+(String) year+"-"+(String) month+"-"+(String) date+" "+(String) day_in_week+" ";

get_filename();

if (!SD.exists(&file_name_log[0])) {

                     myFile = SD.open(file_name_log, FILE_WRITE);

                   sound_cnt = 0; 

}

***

If today is December 11th and the date is changed, the “D211212.txt” name of the new text file is created by the C++ code above.

As the weather station is running continuously for 237 days, the same number of text files are created and stored in SD card storage.

When summarizing air pressure data into a graphic chart, the result is shown in the picture above.

The monsoon season in Korea usually starts in mid-July.

But this year (2021), the monsoon started very late and typhoons (hurricane) are rarely passing through my provincial region.

But I remember the strongest typhoon arriving on the 21st of August and windows of my house are shaking and rattling for all night long.

You can see that minimum air pressure (984.01 hecto-pascals) is observed in the graph chart above at that day.

During the winter season, high-pressure air mass usually moves to the Korean peninsula from Russia, Mongolia, and China.

Therefore, you can observe more than 1010 hecto-pascals of air pressures becomes common in the chart from mid-October.

Step 8: Collected Humidity Data Summary and Conclusion

In this year (2021) monsoon season was strangely delayed up to early October.

Therefore, the high humidity of days can be observed until early October.

Many rainy days are continued from mid-August to early October.

The full-fledged winter begins recently as it's already December.

Therefore, humidity in my room drastically decreased up to 20%.

I need to turn on the humidifier from now on for preventing sore throat the next morning.

When looking at the details of weather data change, I can understand overall climate change in my provincial region also.

Thanks for reading.