zurück

Luftdruck-Sensor BMP-180

27.03.2018
Luftdruck-Sensor BMP-180

Merkmale

Anschlüsse

Pin Pin-Funktion Arduino Uno
VCC Stromversorgung 3,3V
GND Masse/Ground GND
SCL (CL) I²C clock A5
SDA (DA) I²C data A4
3.3 Stromversorgung 3,3V

Verwendete Bauteile

Aufbau

Aufbau der Schaltung
Abb.: Aufbau der Schaltung

Hinweis: 1hPa (Hektopascal) = 100Pa = 1mbar = 0,001bar

Sketch #1

Im ersten Versuch habe ich die Library SFE_BMP180 von LowPowerLab verwendet und dies ist die Ausgabe auf der seriellen Konsole:

Ausgabe auf der seriellen Konsole
// change this to your altitude (float value)
#define ALTITUDE 482.0

#include <Wire.h>
#include <SFE_BMP180.h>

SFE_BMP180 pressure; //Creating an object

void setup()
{
  Serial.begin(9600);
  if (!pressure.begin()) {
    Serial.println("BMP-180 init failed!");
    while(true);
  }

  Serial.print("Provided altitude: ");
  Serial.print(ALTITUDE, 0);
  Serial.println(" meters");
}

void loop()
{
  char status;
  double T, P, p0; //Creating variables for temp, pressure and relative pressure

  status = pressure.startTemperature();
  if (status != 0) {
    delay(status);

    status = pressure.getTemperature(T);
    if (status != 0) {
      Serial.print("Temperature: ");
      Serial.print(T, 1);
      Serial.println(" °C");

      status = pressure.startPressure(3);

      if (status != 0) {
        delay(status);

        status = pressure.getPressure(P, T);
        if (status != 0) {
          Serial.println("Pressure measurement: " + String(P) + " hPa (Pressure measured using temperature)");

          p0 = pressure.sealevel(P, ALTITUDE);
          Serial.println("Relative (sea-level) pressure: " + String(p0) + " hPa");
        }
      }
    }
  }
  delay(5000);
}

Sketch #2

Hier wurden neben "Wire.h" noch die beiden Bilbiotheken Adafruit_Sensor und Adafruit_BMP085_Unified verwendet, die ein recht brauchbares Ergebnis liefern, wie die seriellen Konsole zeigt:

Ausgabe auf der seriellen Konsole
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>

/* This driver uses the Adafruit unified sensor library (Adafruit_Sensor),
   which provides a common 'type' for sensor data and some helper functions.

   To use this driver you will also need to download the Adafruit_Sensor
   library and include it in your libraries folder.
   You should also assign a unique ID to this sensor for use with
   the Adafruit Sensor API so that you can identify this particular
   sensor in any data logs, etc.  To assign a unique ID, simply
   provide an appropriate value in the constructor below (12345
   is used by default in this example).
*/

Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

void setup(void)
{
  Serial.begin(9600);
  Serial.println("Pressure Sensor Test");

  if(!bmp.begin()) {
    Serial.print("No BMP-085/BMP-180 detected");
    while(true);
  }

  displaySensorDetails();
}

void loop(void)
{
  /* Get a new sensor event */
  sensors_event_t event;
  bmp.getEvent(&event);

  /* Display the results (barometric pressure is measure in hPa) */
  if (event.pressure)
  {
    /* Display atmospheric pressue in hPa */
    Serial.print("Pressure:    ");
    Serial.print(event.pressure);
    Serial.println(" hPa");

    /* Calculating altitude with reasonable accuracy requires pressure    *
     * sea level pressure for your position at the moment the data is     *
     * converted, as well as the ambient temperature in degress           *
     * celcius.  If you don't have these values, a 'generic' value of     *
     * 1013.25 hPa can be used (defined as SENSORS_PRESSURE_SEALEVELHPA   *
     * in sensors.h), but this isn't ideal and will give variable         *
     * results from one day to the next.                                  *
     *                                                                    *
     * You can usually find the current SLP value by looking at weather   *
     * websites or from environmental information centers near any major  *
     * airport.                                                           *
     *                                                                    *
     * For example, for Paris, France you can check the current mean      *
     * pressure and sea level at: http://bit.ly/16Au8ol                   */

    /* First we get the current temperature from the BMP085 */
    float temperature;
    bmp.getTemperature(&temperature);
    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" C");

    /* Then convert the atmospheric pressure, and SLP to altitude         */
    /* Update this next line with the current SLP for better results      */
    float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
    Serial.print("Altitude:    ");
    Serial.print(bmp.pressureToAltitude(seaLevelPressure, event.pressure));
    Serial.println(" m\n");
  } else {
    Serial.println("Sensor error");
  }
  delay(5000);
}

/**
 * Displays some basic information on this sensor from the unified
 * sensor API sensor_t type (see Adafruit_Sensor for more information)
 */
void displaySensorDetails(void)
{
  sensor_t sensor;
  bmp.getSensor(&sensor);
  Serial.println("------------------------------------");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" hPa");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" hPa");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" hPa");
  Serial.println("------------------------------------");
  Serial.println("");
  delay(1000);
}