Mirko Pavleski
Published © GPL3+

DIY Advanced Arduino Barometer

Pressure tendency can forecast short-term changes in the weather. This is a very sophisticated device designed for sailors, yachtsmen, etc.

BeginnerFull instructions provided10,063
DIY Advanced Arduino Barometer

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
MyOctopus i2c Barometric Air Pressure Sensor BMP280
MyOctopus i2c Barometric Air Pressure Sensor BMP280
×1
Alphanumeric LCD, 16 x 2
Alphanumeric LCD, 16 x 2
×1
LED (generic)
LED (generic)
×4
Resistor 475 ohm
Resistor 475 ohm
×2

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Schematics

Schematic diagram

Code

Arduino code

C/C++
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);
Adafruit_BMP085 bmp;

    const float mid_p = 1013.25; // Sea level atmospheric pressure
    int rLed = 10; // Rising Led
    int sLed = 11; // Steady Led
    int fLed = 12; //Falling Led
    int i;                    // For loop counter
    int j;                    // -------//---------
    long p;                   // Current pressure in Pa (1Pa = 0.0075006376 mmHg)
    long sum_p6;              // The sum of the results of pressure measurements for 6 sec.
    long mini_p6;             // Minimum pressure in 6 seconds
    long maxi_p6;             // Maximum pressure in 6 sec. 
    float  hg_p;              // Pressure in mmHg
    float dif_pm;             // Difference of pressure - current and average (mid_p) in mm Hg.
    float dif_p1;             // The difference in pressure - current and what was 1 hour ago
    float dif_p3;             // The difference in pressure - current and what was 3 hours ago
    float dif_p10;            // The difference in pressure - current and what was 10 hours ago
    boolean flag;             // Flag allowing to output dif_p1, dif_p3, dif_p10 with two additional spaces
    long sum_p[60];           // Array for storing 60 sums p. Each amount - 10,000 measurements in 10 minutes
    
    float t;                  // Current temperature in degrees C
    float sum_t6;             // The sum of the temperature measurement results in 6 seconds
    float mini_t6;            // Minimum temperature in 6 sec
    float maxi_t6;            // Maximum temperature in 6 sec
  
void setup() {
  Serial.begin(9600);
  pinMode (8, OUTPUT); // An LED is connected to D8 (11th leg) - a signaling device for the output of a new hg_P
  pinMode(rLed,OUTPUT);
  pinMode(sLed,OUTPUT);
  pinMode(fLed,OUTPUT);
  lcd.begin (16,2);
  
  for(i=0; i<60; i++)               // Zeroing the array sum_p [i]
    sum_p[i]=0;      
    
  if (!bmp.begin()) {               // Pressure sensor defective
  lcd.print("BMP-180 DAMAGED!");
  while (1) {}                      // Loop
  }
}
  
void loop() {
  sum_p[0] = 0;                     // In the for loop for j in sum_p [0] we will accumulate the sum of 10,000 measurements
  for (j=0;j<100;j++) {             // External cycle - we carry out 10,000 measurements in 600 seconds

    sum_p6=0;                       // Preparing data for the inner loop
    mini_p6=110000;                 // Knowingly more than possible
    maxi_p6= 80000;                 // Deliberately less than possible
    sum_t6=0;           
    mini_t6=100.0;                  // Knowingly more than possible
    maxi_t6=0.0;                    // Deliberately less than possible 
    
      for(i=0;i<102;i++) {          // Internal loop - we carry out 102 measurements in 6 seconds
      
        p=bmp.readPressure();
        Serial.println(p);                
        if (p<mini_p6)              // Find the max and min results to discard later
         mini_p6=p;
        if (p>maxi_p6)
         maxi_p6=p;  
        sum_p6=sum_p6 + p;

        t=bmp.readTemperature();
        if (t<mini_t6)
          mini_t6=t;
        if (t>maxi_t6)
          maxi_t6=t;  
        sum_t6=sum_t6 + t;
           
        delay(18);                  // Adjusting the duration of the inner loop to 6 seconds
      }                             // finished an internal 6-second loop on i

    sum_p[0]=sum_p[0]+sum_p6-maxi_p6-mini_p6;
    hg_p=1.0E-4 * (sum_p6-maxi_p6-mini_p6) + 77.32;  // 77.332 - Difference between Absolute, and Relative pressure for a given place        
    dif_pm=(hg_p - mid_p);
    digitalWrite (8,LOW);           // We turn on the LED - display a new result
    
    // We display the top line on the indicator - current pressure, deviation_
    // average pressure and temperature. 
        
    lcd.home();                     
    lcd.print (hg_p,1);
    lcd.print (" ");
    if (dif_pm >=0)                 // Знак "+" или "-" ставим сами
      lcd.print ("+");
    else 
      lcd.print ("-");
    lcd.print (abs (dif_pm),1);
    lcd.print (" ");
    if (abs(dif_pm)>=9.95){         // If dif_pm is long (5 familiar spaces), then t is displayed without tenths
      lcd.print (0.01*(sum_t6-maxi_t6-mini_t6),0);
      lcd.print (" ");              // Clearing the 16th digit
    }
    else                            // Otherwise, we print t with tenths
      lcd.print(0.01*(sum_t6-maxi_t6-mini_t6),1);  
    
    delay(83);                      // Adjusting the duration of the outer cycle to 10 minutes
    digitalWrite (8,HIGH);          // Turning off the LED
                  
  }                                 // finished an outer 10-minute cycle on j

    dif_p1 = (sum_p[0] - sum_p[6]) * 1.0E-6; 
    dif_p3 = (sum_p[0] - sum_p[18])* 1.0E-6 ;
    dif_p10 = (sum_p[0] - sum_p[59])* 1.0E-6 ;
    
    flag=false;                     // no spaces can be inserted into the 2nd line
    if (abs(dif_p1)<9.95 and abs(dif_p3)<9.95 and abs(dif_p10)<9.95)
      flag=true;                    // If dif_p occupy 4 familiar spaces, then spaces can be inserted
    if (sum_p[59]==0)               // If there is no data for dif_p10 yet, then spaces can be inserted
      flag=true;
       
  // We output dif_p1, dif_p3 and dif_p10 to the 2nd (bottom) line of the indicator

    lcd.setCursor (0,1);
    lcd.print ("                "); // Clearing the 2nd line
    lcd.setCursor (0,1);
    
  // Час назад...
     
    if (sum_p[6]>0) {               // If data collection started more than an hour ago
      if (dif_p1 >=0)               // We put the "+" or "-" sign ourselves
         lcd.print ("+");
      else 
         lcd.print ("-");     
      lcd.print (abs (dif_p1),1);
      lcd.print (" "); 
    }
    else                            // No data yet ...
      lcd.print ("--.- ");

    if (flag==true)
      lcd.print (" ");

      // 3 Часа назад...
         
    if (sum_p[18]>0) {              // If data collection started more than 3 hours ago
      if (dif_p3 >=0)               // We put the "+" or "-" sign ourselves
         lcd.print ("+");
      else 
         lcd.print ("-");     
      lcd.print (abs (dif_p3),1);
      lcd.print (" "); 
    }
    else                            // No data yet ...
      lcd.print ("--.- ");

    if (flag==true)
      lcd.print (" ");
      
      // 10 Часов назад... 
        
    if (sum_p[59]>0) {              // If data collection started more than 10 hours ago
      if (dif_p10>=0)               // We put the "+" or "-" sign ourselves
        lcd.print ("+");
      else 
        lcd.print ("-");     
      lcd.print (abs (dif_p10),1);
    }
    else                            // No data yet ...
      lcd.print ("--.-");
  
    // Shift the contents of the sum_p [] array one position to the right
  
  for(i=59;i>0;i--)
    sum_p[i] = sum_p[i-1];

    if (dif_p3 > 1.6) {
     digitalWrite(rLed, HIGH);
     digitalWrite(sLed, LOW);
     digitalWrite(fLed, LOW);
    }
   if (dif_p3 < -1.6) {
     digitalWrite(rLed, LOW);
     digitalWrite(sLed, LOW);
     digitalWrite(fLed, HIGH);
   }
   if (dif_p3 > -1.6 && dif_p3 < 1.6) {
     digitalWrite(rLed, LOW);
     digitalWrite(sLed, HIGH);
     digitalWrite(fLed, LOW);
   }
} 

// End of sketch

Credits

Mirko Pavleski

Mirko Pavleski

148 projects • 1275 followers

Comments