BMP085test.ino 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <Adafruit_BMP085.h>
  2. /***************************************************
  3. This is an example for the BMP085 Barometric Pressure & Temp Sensor
  4. Designed specifically to work with the Adafruit BMP085 Breakout
  5. ----> https://www.adafruit.com/products/391
  6. These pressure and temperature sensors use I2C to communicate, 2 pins
  7. are required to interface
  8. Adafruit invests time and resources providing this open source code,
  9. please support Adafruit and open-source hardware by purchasing
  10. products from Adafruit!
  11. Written by Limor Fried/Ladyada for Adafruit Industries.
  12. BSD license, all text above must be included in any redistribution
  13. ****************************************************/
  14. // Connect VCC of the BMP085 sensor to 3.3V (NOT 5.0V!)
  15. // Connect GND to Ground
  16. // Connect SCL to i2c clock - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 5
  17. // Connect SDA to i2c data - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 4
  18. // EOC is not used, it signifies an end of conversion
  19. // XCLR is a reset pin, also not used here
  20. Adafruit_BMP085 bmp;
  21. void setup() {
  22. Serial.begin(9600);
  23. if (!bmp.begin()) {
  24. Serial.println("Could not find a valid BMP085 sensor, check wiring!");
  25. while (1) {}
  26. }
  27. }
  28. void loop() {
  29. Serial.print("Temperature = ");
  30. Serial.print(bmp.readTemperature());
  31. Serial.println(" *C");
  32. Serial.print("Pressure = ");
  33. Serial.print(bmp.readPressure());
  34. Serial.println(" Pa");
  35. // Calculate altitude assuming 'standard' barometric
  36. // pressure of 1013.25 millibar = 101325 Pascal
  37. Serial.print("Altitude = ");
  38. Serial.print(bmp.readAltitude());
  39. Serial.println(" meters");
  40. Serial.print("Pressure at sealevel (calculated) = ");
  41. Serial.print(bmp.readSealevelPressure());
  42. Serial.println(" Pa");
  43. // you can get a more precise measurement of altitude
  44. // if you know the current sea level pressure which will
  45. // vary with weather and such. If it is 1015 millibars
  46. // that is equal to 101500 Pascals.
  47. Serial.print("Real altitude = ");
  48. Serial.print(bmp.readAltitude(101500));
  49. Serial.println(" meters");
  50. Serial.println();
  51. delay(500);
  52. }