Light, location, temperature… What’s next? Well, how about Barometric pressure? You know.. that thing that determines so much of our weather. Well the BMP085 Barometric Pressure sensor, available at SparkFun is a great little sensor capable of sensing such small changes in barometric pressure it can be used as a pretty precise altimeter as well. And, because no Barometric pressure sensor would be complete without a temperature reading, the BMP085 has an imbedded thermometer. It also looks cool!
For this example, the way we will be calculating altitude is imprecise and does not compensate for temperature or many other things that can contribute to differences. But, if you use it as a comparison against itself during a hour long period (barometric pressure also fluctuates throughout the day), you can get a pretty accurate difference reading.
The reading differs from my weather report
Im not going to get into why this is, but to make comparisons easier, your weather report uses a sea-level compensated reading, not an actual reading. This is an actual reading.
Hooking it up
Hooking it up to your Arduino is pretty simple, the BMP085 is an I2C device. I2C is a 2-wire serial connection, so you just need to connect the BMP085 to power (3.3v) and ground, then the SDA (Data) and SCL (Clock) lines to your Arduino for communication. On your Arduino (everything but the mega) SDA is on analog pin 4, and SCL is on analog pin 5. On an Arduino Mega, SDA is digital 20, and SCL is digital 21.
Code
The code for this is largely copied and based off of Jim Lindblom’s example from SparkFun (Thanks Jim!). I changed a few things so it is just easier for you to use the readings in calculations, and I added the altitude reading as well. If you know of a better way to calculate altitude, please let us know so we can include it!
The code simply outputs the temperature, pressure, and altitude in the serial terminal.
/*Based largely on code by Jim Lindblom Get pressure, altitude, and temperature from the BMP085. Serial.print it out at 9600 baud to serial monitor. */ #include <Wire.h> #define BMP085_ADDRESS 0x77 // I2C address of BMP085 const unsigned char OSS = 0; // Oversampling Setting // Calibration values int ac1; int ac2; int ac3; unsigned int ac4; unsigned int ac5; unsigned int ac6; int b1; int b2; int mb; int mc; int md; // b5 is calculated in bmp085GetTemperature(...), this variable is also used in bmp085GetPressure(...) // so ...Temperature(...) must be called before ...Pressure(...). long b5; void setup(){ Serial.begin(9600); Wire.begin(); bmp085Calibration(); }