Home > Other >Special Application Circuits > Using BMP280 to make a weather station

Using BMP280 to make a weather station

Source: InternetPublisher:宋元浩 Keywords: Weather station DIY design BMP280 Updated: 2024/12/31

The project is a weather station that displays the local atmospheric pressure, temperature humidity and UV index without any internet connection.

background

For a long time I wanted to make a weather station without the use of the internet, to measure the weather data around you and view the data when needed. So, I set out to make a cool looking local weather station that can measure the air pressure, temperature, humidity around you and the UV index of the day (if you place it near a window). It also has a clock screen to show the time, date and day of the week.

pYYBAGMoJMKAb63QAAGGM5n0tMk078.png

poYBAGMoJMiAPdOQAAG5ZjEm-nU261.png

pYYBAGMoJMyAQRnNAAJILOymKtg273.png

In this article, I will show you how to make this cool weather station in just a few steps.

Step 1: Build the enclosure

I created the shell using Autodesk fusion 360 and printed it in green PLA. It needed supports and I printed it on my Ender 3 at 70mm/s with 20% infill.

poYBAGMoJNKAVwAkAALwqEs8wfE804.png

Step 2: BMP280

BMP280 is an atmospheric pressure and temperature sensor, which uses I2C or SPI protocol to communicate with Arduino . Here I use SPI. To use SPI, connect -

CS to D10

SDA to D11

SDO to D12

SCK to D13

In the code section, to use this sensor, we need a library. First, I included the library in the code #include < Adafruit_BMP280.h>. You can find the jump below this article.

Then I define the SPI pins of the sensor. In the setup function I initialize the BMP sensor and in the loop function I read the pressure and temperature data using the bmp.readPressure() and bmp.readTemperature() commands. I divide the pressure value by 100 to measure the pressure in hPa. To measure the altitude I use the bmp.readAltitude(1005.47) command. In this step you have to change the value according to the average pressure in your area. (1005.47)

Step 3: DS3231 RTC

This weather station also has a time screen which can show the current time, date and day of the week. For this purpose, I have used a DS231 RTC module which uses the I2C protocol for communication. So to use this, connect -

SCL to A5

SDA to A4

First you must set the time and date on the RTC using the DS3231_set.ino program from the library examples.

In the main program, I include the library #include <DS3231.h> and read the time data according to the instructions in the library. Here I use the examples in the library as a reference for the code. I created a case for each day of the week to find the current date.

Step 4: DHT11

I use this sensor to measure humidity. For this, I connect its data to Arduino D2. In the program, I include the DHT library, #include <DHT.h> and then initialize the sensor in the setup. In the loop, I read the humidity value using the dht.readHumidity() command.

Step 5: GUVA-S12SD UV Sensor

GUVA-S12SD is a Schottky type photodiode based on Gallium Nitride . It has a typical UV detection wavelength of 240-370nm (covering UVB and most of the UVA spectrum). It outputs a calibrated analog voltage that varies with the intensity of UV light. Therefore, we can read the analog value through the Arduino ADC.

In the loop function I simulate reading the sensor value and calculating the UV index

float sens orValue = analogRead(A0);

float sensorVoltage = sensorValue / 1024 * 5.0;

int UV_index = sensorVoltage / 0.1;

Step 6: OLED Display

I am using 0.96" 128*64 OLED display in this project, it uses I2C protocol, so I connected it to Arduino as shown below -

SCK to A5

SDA to A4

In the program, I first covered the Adafruit_SSD1306 and Adafruit_GFX libraries

#include 《Adafruit_GFX.h》

#include "Adafruit_SSD1306.h"

Then I create the display variable and add some bitmaps to show some images. In the setup, I initialize the display. Then in the loop, I use the display.print() function to display each data. I display the data on four pages, time, pressure, temperature and humidity, and UV_index. There is a 5 second delay between each page.

Local weather station code:

#include

#include

Then I create the display variable and add some bitmaps to show some images. In the setup, I initialize the display. Then in the loop, I use the display.print() function to display each data. I display the data on four pages, time, pressure, temperature and humidity, and UV_index. There is a 5 second delay between each page.

Local weather station code:

#include

#include

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET 4
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define BMP_SCK (13)
#define BMP_MISO (12)
#define BMP_MOSI (11)
#define BMP_CS (10)

DS3231 clock;
bool century = false;
bool h12Flag;
bool pmFlag;

Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);

#define DHT PIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

const unsigned char PROGMEM frame0 [] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0x80, 0x00, 0x00, 0x0F, 0xFF, 0xF0, 0x00, 0x00, 0x3F, 0xFF, 0xFC, 0x00, 0x00, 0x7F, 0x81, 0xFE, 0x00, 0x00, 0xFC, 0x00, 0x3F, 0x00, 0x01, 0xF0, 0x00, 0x0F, 0x80, 0x03, 0xE0, 0x18, 0x07, 0xC0, 0x07, 0x86, 0x18, 0x61, 0xE0, 0x0F, 0x02, 0x00, 0x40, 0xF0, 0x0F, 0x02, 0x00, 0x40, 0xF0, 0x1E, 0x00, 0x00, 0x00, 0x78, 0x1C, 0x40, 0x00, 0x02, 0x38, 0x3C, 0x61, 0x00, 0x06, 0x3C, 0x3C, 0x01, 0x80, 0x00, 0x3C, 0x38, 0x00, 0x80, 0x00, 0x1C, 0x38, 0x00, 0xC0, 0x00, 0x1C, 0x78, 0x00, 0xE0, 0x00, 0x1E, 0x79, 0xC0, 0xF0, 0x03, 0x9E, 0x79, 0xC0, 0x7C, 0x03, 0x9E, 0x78, 0x00, 0x7E, 0x00, 0x1E, 0x38, 0x00, 0x7E, 0x00, 0x1C, 0x38, 0xFC, 0xFF, 0x3F, 0x1C, 0x3C, 0xFC, 0x7E, 0x3F, 0x3C, 0x3C, 0xFE, 0x7E, 0x7F, 0x3C, 0x1C, 0x7E, 0x18, 0x7E, 0x38, 0x1E, 0x3F, 0x00, 0xFC, 0x78, 0x0F, 0x3F, 0xC3, 0xFC, 0xF0, 0x0F, 0x0F, 0xFF, 0xF8, 0xF0, 0x07, 0x87, 0xFF, 0xE1, 0xE0, 0x03, 0xC1, 0xFF, 0x83, 0xC0, 0x03, 0xF0, 0x3C, 0x0F, 0xC0, 0x01, 0xFC, 0x00, 0x3F, 0x80, 0x00, 0x7F, 0x81, 0xFE, 0x00, 0x00, 0x3F, 0xFF, 0xFC, 0x00, 0x00, 0x0F, 0xFF, 0xF0, 0x00, 0x00, 0x01, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
const unsigned char PROGMEM frame1 [] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0xC3, 0x00, 0x00, 0x01, 0x00, 0x9D, 0x80, 0x00, 0x03, 0x80, 0xB4, 0xE0, 0x00, 0x06, 0x80, 0xA6, 0x80, 0x00, 0x04, 0xC0, 0xA6, 0xE0, 0x00, 0x0C, 0x40, 0xA6, 0xE0, 0x00, 0x08, 0x60, 0xA6, 0x80, 0x00, 0x08, 0x20, 0xA6, 0xE0, 0x00, 0x08, 0x60, 0xA6, 0x80, 0x00, 0x0E, 0xC0, 0xA6, 0xE0, 0x00, 0x03, 0x80, 0xA6, 0x80, 0x00, 0x00, 0x10, 0xA6, 0xC0, 0x00, 0x00, 0x38, 0xA6, 0xE0, 0x00, 0x00, 0x38, 0xA6, 0x80, 0x00, 0x00, 0x6C, 0xA6, 0xE0, 0x00, 0x00, 0x44, 0xA6, 0x80, 0x00, 0x00, 0x6C, 0xA6, 0xE0, 0x00, 0x00, 0x38, 0xA6, 0x80, 0x00, 0x00, 0x00, 0xA6, 0x80, 0x00, 0x00, 0x00, 0xA4, 0xE0, 0x00, 0x00, 0x00, 0xA6, 0x80, 0x00, 0x00, 0x40, 0xA6, 0xE0, 0x00, 0x00, 0xC0, 0xA6, 0x80, 0x00, 0x01, 0xA0, 0xA6, 0xE0, 0x00, 0x01, 0x30, 0xA6, 0xE0, 0x00, 0x03, 0x10, 0xA6, 0x80, 0x00, 0x02, 0x18, 0xA6, 0xE0, 0x00, 0x06, 0x08, 0xA6, 0x80, 0x00, 0x06, 0x08, 0xA6, 0x80, 0x00, 0x02, 0x19, 0xA6, 0xC0, 0x00, 0x03, 0xF3, 0x26, 0x60, 0x00, 0x00, 0xC6, 0x26, 0x30, 0x00, 0x00, 0x0C, 0xE3, 0x10, 0x00, 0x00, 0x09, 0x80, 0x98, 0x00, 0x00, 0x19, 0x00, 0xC8, 0x00, 0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xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80};

void setup() {
Serial.begin(57600);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
 Serial.println(F("SSD1306 fai led"));
}
Wire.begin();
dht.begin( );
if (!bmp.begin()) {
 Serial.println(F("Problem.bmp"));
 while (1) delay(10);
}
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCu rsor(0 , 9);
display.se tFont(&FreeSans9pt7b);
display.println("**** LOCAL ****");
display.setCursor(0, 38);
display.setFont(&FreeMonoBo ldOblique12pt7b);
display.println("wather");
display.setCursor(27, 58);
display.println("Station");
display.display();
delay(2000);


bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
Adafruit_BMP280::FILTER_X16, /* Filtering. */
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */

}


void loop() {

//Time
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(13, 15);
display.setFont(&FreeMonoBoldOblique12pt7b);
display.print(clock.getHour(h12Flag, pmFlag) ));
display.setCursor(38, 15);
display.println(":");
display.setCursor(50, 15);
display.println(clock.getMinute());
display.setCursor(70, 15);
if (pmFlag) {
 display.println(" PM" );
} else {
 display.println(" AM ");
}
display.setFont(&FreeSans9pt7b);

display.setCursor(20, 60);
display.println(clock.getDate());
display.setCursor(40, 60);
display.println("/");
display.setCursor(46, 60);
display.println (clock.getMonth(century));
display.setCursor(65, 60);
display.println("/");
display.setCursor(70, 60);
display.println("20");
display.setCursor(90, 60);
display.println(clock.getYear());
display.setCursor(30, 30);
display.setFont (&FreeSans9pt7b);
switch (clock.getDoW()) {
 case 1:
  display.println("Saturday");
  break;
 case 2:
  display.println("Sunday");
  break;
 case 3:
  display.println("Monday");
  break;
 case 4:
  display.println("Tu esday");
  break;
 case 5:
  display.println("Wednesday");
  break;
 case 6:
  display.println("Thursday" );
  break;
 case 7:
  display.println("Friday");
  break;
}


display.display();
delay(5000);
//P
display.clearDisplay();
display.drawBitmap(0, 0, frame0, 40, 40, 1);
display.setFont(&FreeSans9pt7b);
display.setCursor(41, 28);
display.println(bmp.readPressure() / 100);
display.setCursor(110, 28);
display.setFont();
display.println("hPa");
display.setCursor(0, 55);
display.setFont(&FreeSans9pt7b);
display.println("Altitude:");
display.setCursor(65, 62);
display.println(bmp.readAltitude(1005.47));
display.setCursor(113, 62);
display.println("m");
display.display();
delay(5000);
//T&RH
display.clearDisplay();
display.setFont(&FreeMonoBoldOblique12pt7b);
display.drawBitmap(0, 5, frame1, 40, 51, 1);
display.setCursor(35, 30);
display.print(bmp.readTemperature( ));
display.setFont(&FreeSans9pt7b);
display.setCursor(102, 28);
display.println(" *");
display.setCursor(110, 31);
display.println(" C");
display.setFont();
display.setCursor(66, 45) ;
display.println("RH :");
byte RH = dht.readHumidity();
display.setCursor(95, 45);
display.println(RH);
display.setCursor(110, 45);
display.println("%");
display.drawBitmap(0, 56, frame2, 135, 15, 1);
display.display();
delay(5000);
//UV
display.clearDisplay();
float sensorValue = analogRead (A0);
float sensorVoltage = sensorValue / 1024 * 5.0;
int UV_index = sensorVoltage / 0.1;
display.setFont(&FreeSans9pt7b);
display.setCursor(0, 15);
display.print(" UV INDEX ");
display.setCursor(58, 45);
display.println(UV_index);
display.display();
delay( 5000);
}

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号