Barometer_Sensor.ino 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. Barometer_Sensor.ino
  3. Example sketch for barometer
  4. Copyright (c) 2012 seeed technology inc.
  5. Website : www.seeed.cc
  6. Author : Jim Lindblom, LG
  7. Create Time:
  8. Change Log :
  9. The MIT License (MIT)
  10. Permission is hereby granted, free of charge, to any person obtaining a copy
  11. of this software and associated documentation files (the "Software"), to deal
  12. in the Software without restriction, including without limitation the rights
  13. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. copies of the Software, and to permit persons to whom the Software is
  15. furnished to do so, subject to the following conditions:
  16. The above copyright notice and this permission notice shall be included in
  17. all copies or substantial portions of the Software.
  18. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. THE SOFTWARE.
  25. */
  26. #include "BMP085.h"
  27. #include <Wire.h>
  28. float temperature;
  29. float pressure;
  30. float atm;
  31. float altitude;
  32. BMP085 myBarometer;
  33. void setup() {
  34. Serial.begin(9600);
  35. while (!Serial);
  36. myBarometer.init();
  37. }
  38. void loop() {
  39. temperature = myBarometer.bmp085GetTemperature(
  40. myBarometer.bmp085ReadUT()); //Get the temperature, bmp085ReadUT MUST be called first
  41. pressure = myBarometer.bmp085GetPressure(myBarometer.bmp085ReadUP());//Get the temperature
  42. /*
  43. To specify a more accurate altitude, enter the correct mean sea level
  44. pressure level. For example, if the current pressure level is 1019.00 hPa
  45. enter 101900 since we include two decimal places in the integer value。
  46. */
  47. altitude = myBarometer.calcAltitude(101900);
  48. atm = pressure / 101325;
  49. Serial.print("Temperature: ");
  50. Serial.print(temperature, 2); //display 2 decimal places
  51. Serial.println(" Celsius");
  52. Serial.print("Pressure: ");
  53. Serial.print(pressure, 0); //whole number only.
  54. Serial.println(" Pa");
  55. Serial.print("Ralated Atmosphere: ");
  56. Serial.println(atm, 4); //display 4 decimal places
  57. Serial.print("Altitude: ");
  58. Serial.print(altitude, 2); //display 2 decimal places
  59. Serial.println(" m");
  60. Serial.println();
  61. delay(1000); //wait a second and get values again.
  62. }