Höhenmessung mit Hilfe des Luftdrucks

Zur Information:

http://www.chemie.de/lexikon/Barometrische_H%C3%B6henmessung.html

BMP180

Anschluß am Arduino (vergleiche):

Kennzeichnung

am Sensor 

Anschluss

Arduino

GND Ground
3.3. 3.3
SDA A4
SCL A5

I2C - Protokoll

i2C - Protokoll (1,1 MiB)

BMP180

https://developer-blog.net/hardware/raspberrypi/raspberry-pi-luftdruck-sensor-bmp180/

Beispiel_Quelltext
#include <Wire.h>
#include <BMP180.h>

// Store an instance of the BMP180 sensor.
BMP180 barometer;
// We are going to use the on board LED for an indicator.
int indicatorLed = 13; 

// Store the current sea level pressure at your location in Pascals.
float seaLevelPressure = 102200;

void setup()
{
  // We start the serial library to output our messages.
  Serial.begin(9600);
  // We start the I2C on the Arduino for communication with the BMP180 sensor.
  Wire.begin();
  // Set up the Indicator LED.
  pinMode(indicatorLed, OUTPUT);
  // We create an instance of our BMP180 sensor.
  barometer = BMP180();
  // We check to see if we can connect to the sensor.
  if(barometer.EnsureConnected())
  {
    Serial.println("Connected to BMP180."); // Output we are connected to the computer.
    digitalWrite(indicatorLed, HIGH); // Set our LED.
    
     // When we have connected, we reset the device to ensure a clean start.
    barometer.SoftReset();
    // Now we initialize the sensor and pull the calibration data.
    barometer.Initialize();
  }
  else
  { 
    Serial.println("No sensor found.");
    digitalWrite(indicatorLed, LOW); // Set our LED.
  }
}

void loop()
{
  if(barometer.IsConnected)
  {
    // Retrive the current pressure in Pascals.
    long currentPressure = barometer.GetPressure();
    
    // Print out the Pressure.
    Serial.print("Pressure: ");
    Serial.print(currentPressure);
    Serial.print(" Pa");
    
    // Retrive the current altitude (in meters). Current Sea Level Pressure is required for this.
    float altitude = barometer.GetAltitude(seaLevelPressure);
    
    // Print out the Altitude.
    Serial.print("\tAltitude: ");
    Serial.print(altitude);
    Serial.print(" m");
    
    // Retrive the current temperature in degrees celcius.
    float currentTemperature = barometer.GetTemperature();
    
    // Print out the Temperature
    Serial.print("\tTemperature: ");
    Serial.print(currentTemperature);
    Serial.write(176);
    Serial.print("C");
    
    Serial.println(); // Start a new line.
    delay(1000); // Show new results every second.
  }
}
Beispiel_Quelltext (mit SD-Karte)

BMP180 einlesen und nach SD schreiben

#include <SD.h>
#include <Wire.h>
#include <BMP180.h>

const int chipSelect = 4;  // oder 10?
BMP180 barometer;
int indicatorLed = 13; 
//1022 mbar (Stuttgart)  419 m Höhe
float seaLevelPressure = 102200;

void setup()
{
  Serial.begin(9600);

  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");

  delay(500);  // vielleicht etwas Zeit lassen
  
  // We start the I2C on the Arduino for communication with the BMP180 sensor.
  Wire.begin();
  pinMode(indicatorLed, OUTPUT);
  barometer = BMP180();
  if(barometer.EnsureConnected())
  {
    Serial.println("BMP180 gefunden."); // Output we are connected to the computer.
    digitalWrite(indicatorLed, HIGH); // Set our LED.
    
    barometer.SoftReset();
    barometer.Initialize();
  }
  else
  { 
    Serial.println("BMP180 nicht gefunden.");
    digitalWrite(indicatorLed, LOW); // Set our LED.
  }
}

void loop()
{
   String dataString = "daten einlesen!";
  if(barometer.IsConnected)
  {
    // Daten einlesen
    long currentPressure = barometer.GetPressure();
    float altitude = barometer.GetAltitude(seaLevelPressure);
    float currentTemperature = barometer.GetTemperature();
    
    File dataFile = SD.open("daten.txt", FILE_WRITE);
  if (dataFile) {
 
    dataFile.print(currentPressure);
    dataFile.print("  ");
    dataFile.print(altitude);
    dataFile.print("  ");
    dataFile.print(currentTemperature);
    dataFile.println("  ");
    dataFile.close();
    }  
  
  else {
    Serial.println("kann datei daten.txt nicht finden");
  }  
  // if the file is available, write to it:
          
    // Print out the Pressure.
    Serial.print("Pressure: ");
    Serial.print(currentPressure);
    Serial.print(" Pa");
    Serial.print("\tAltitude: ");
    Serial.print(altitude);
    Serial.print(" m");
    Serial.print("\tTemperature: ");
    Serial.print(currentTemperature);
    Serial.write(176);
    Serial.print("C");
    
    Serial.println(); // Start a new line.
    delay(1000); // Show new results every second.
  }
}