In this video lesson we show how to build an Arduino based Weather Barometer. We will use the BMP180 pressure sensor on the GY-87 module. This lesson will likely also work fine if you are just using the BMP180 directly. We show how to measure barometric pressure, convert it to Inches of Mercury, stabilize it with a low pass filter, and then normalize it to standard sea level pressure. With this, our values should very closely match what is being seen on weather maps. This is the schematic of the circuit we will be working on.
For your convenience, here is the code we developed in the video.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
#include <SPI.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #include <Adafruit_BMP085.h> Adafruit_BMP085 BP; bool BMPconnected = false; float BarPress = 30; float BarPressNow = 30; float alt = 1127; int screenWidth = 128; int screenHeight = 64; int oledReset = -1; #define SCREEN_ADDRESS 0x3C Adafruit_SSD1306 oled(screenWidth, screenHeight, &Wire, oledReset); void setup() { // put your setup code here, to run once: Serial.begin(9600); BMPconnected = BP.begin(); if (BMPconnected == true) { Serial.println("BMP180 found and Connected"); } if (BMPconnected == false) { Serial.println("BMP180 not found, Check Connections"); } oled.begin(SSD1306_SWITCHCAPVCC,SCREEN_ADDRESS); oled.clearDisplay(); oled.display(); } void loop() { // put your main code here, to run repeatedly: BarPressNow = normPress(alt); BarPress = .95*BarPress + .05*BarPressNow; oled.clearDisplay(); oled.setCursor(0,12); oled.setTextColor(WHITE); oled.setTextSize(3); oled.println(BarPress); oled.println("In HG"); oled.display(); } float normPress(float elev){ float BPRaw; float BPNorm; float T0 = 288.15; float L = .0065 ; float R = 8.3144598; float M = .0289644; float g = 9.8; float c = M*g/(R*L); BPRaw =BP.readPressure()*.0002953; BPNorm = BPRaw/pow(1-L*elev/T0,c); return BPNorm; } |