Weather forecast with BMP085 pressure sensor?

I would like to predict when it will rain using a BMP085 pressure sensor on Arduino. I am using the code found here http://bildr.org/2011/06/bmp085-arduino/ which works great. Actually I am using this: http://forum.bildr.org/download/file.php?id=182&sid=fedc8ed5837ead0e92fc6bb2663a8d1a

What I need now is to calculate pressure change over time, if it drops by say, 3hPa in an hour it will probably rain.

How can I keep track of pressure readings in the past and compare to the latest reading?

Thanks

[How can I keep track of pressure readings in the past and compare to the latest reading?](http://How can I keep track of pressure readings in the past and compare to the latest reading?)

You do not need absolute time, just incremental history. Therefore a simple array of type float would work. Assuming 4 entries per hour and 6 hour span, you would need 24 elements, 0 - 23 of type integer. Keep a pointer to the last value written.
So, you will need to test [23] to see if it is ==0 and if not, your logic has been running for 6 hours or longer. Your forecast would be the the current pointer back by 23 steps. Supply the appropriate arithmetic for your weather algorithm.

There are other ways, too. If you need more than 6 hours, extend the array. If you need more than 4 datum in an hour, expand the array.

Ray

You could probably have a longer history if you used integer arithmetic, and just stored deltas.
You'd probably only need a byte per reading.

Thanks guys but I think we need to dumb it down a bit! This will be my first project after completing the sparkfun inventors kit tutorials.
I read up about arrays which sounds exactly like what I need but now my head is spinning! Especially the bit about keeping a pointer.
So, we have pressure:

float pressure = bmp085GetPressure(bmp085ReadUP());

and I have figured out how to print that to an LCD...YAY

lcd.setCursor(0, 1);
  lcd.print("Pressure:");
  lcd.print(pressure/100, 0); //whole number only.
  lcd.print("hPa");

I researched the weather station I have, it lets you configure a storm warning. If it detects a pressure drop of 5-9 hPa (user selectable) over 3 hours it will trigger the warning. This is what I would like my sketch to do. I can't find any code similar to what I am looking for. Some example code would be really helpful.

Thanks

I had a go at making some code but I think I have the wrong end of the stick regarding arrays. I doesn't give the desired result which is to record a pressure every 15 minutes then compare the current reading with the one taken 3 hours ago and calculate the change. I think I need to create a circular buffer?

#include <Wire.h>
#include <BMP085.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);

const int numReadings = 13;

int readings[numReadings];      // the readings from the analog input
int index = 0;                  // the index of the current reading
int change = 0;

void setup()
{
  
  bmp085Calibration(); 
  lcd.begin(16, 2);
  // initialize serial communication with computer:
  Serial.begin(9600);                   
  // initialize all the readings to 0: 
  for (int thisReading = 0; thisReading < numReadings; thisReading++)
    readings[thisReading] = 0;          
}

void loop() {
  
  const unsigned long fifteenMinutes = 15 * 60 * 1000UL;
  static unsigned long lastSampleTime = 0 - fifteenMinutes;  // initialize such that a reading is due the first time through loop()

  unsigned long now = millis();
  if (now - lastSampleTime >= fifteenMinutes)
  {
     lastSampleTime += fifteenMinutes;
     float temperature = bmp085GetTemperature(bmp085ReadUT()); //MUST be called first
     float pressure = bmp085GetPressure(bmp085ReadUP());
                           
// read from the sensor:  
  readings[index] = pressure; 
  // calculate the pressure change
  change = readings[index] - readings[index -12];
  // advance to the next position in the array: 
  index = index + 1;

// if we're at the end of the array...
  if (index >= numReadings)              
    // ...wrap around to the beginning: 
    index = 0;    
  
  lcd.setCursor(0, 0);
  lcd.print(change);
  Serial.println(change);   
  }  
}
change = readings[index] - readings[index -12];

What is the value of "index" during the first loop?
What is the value of "index - 12"?

During the first loop I believe index increments from 0 to 1

My intention with index -12 is to read the value taken 3 hours ago, I can see it won't work though as it will give a negative index :~

I suppose I need to wait until I have 13 readings in the array before calculating the change? Is that right?

Bit lost here..

I suppose I need to wait until I have 13 readings in the array before calculating the change? Is that right?

If you want to compare the current reading to one three hours ago, yes. You said that you were looking for a change over the last hour, so, at 4 readings per hour, that requires only 5 readings (now, and the last 4).

For anyone interested I managed to figure this out, I appreciate any feedback

#include <Wire.h>
#include <BMP085.h>

#define LED 13

float pressure;
float pressureChange;
float pressureArray[14];

void setup(){

bmp085Calibration();
Serial.begin(9600);
pinMode(13, OUTPUT);

}
void getPressure()
{
  float temperature = bmp085GetTemperature(bmp085ReadUT()); //MUST be called first
  float pressure = bmp085GetPressure(bmp085ReadUP());
  // insert the new temperature at the start of the array of past temperatures
  for (int a = 13 ; a >= 0 ; --a )
  {
    pressureArray[a] = pressureArray[a-1];
  }
  pressureArray[0] = pressure;
}
void loop()
{
  getPressure();
  pressureChange = pressureArray[13] - pressureArray[0];
  if (pressureArray[13] != 0 && pressureChange >= 3000)
  {
    digitalWrite(LED, HIGH);
  }
  else
  {
    digitalWrite(LED, LOW);
  }
  Serial.print("Pressure change: ");
  Serial.print(pressureChange, 0); //whole number only.
  Serial.println("Pa");

  for (int a = 0 ; a < 15 ; a++) // wait 15 minutes until the next reading
  {
    delay(60000); // wait 1 minute
  }
  
}

Thanks, very useful.