Curious Minds

Clear answers to science and history questions

GY-68 BMP180: Read Pressure & Calculate Altitude

· 5 min read · Science

This guide shows you how to read barometric pressure from a GY-68 module (which uses the BMP180 sensor) and convert that reading into an altitude estimate. You'll wire the sensor to an Arduino or similar microcontroller, run a simple sketch, and apply the standard barometric formula to get meters or feet above sea level. No advanced math is needed—the code and steps handle the calculation.

What You'll Need

  • GY-68 BMP180 module (breakout board with the BMP180 chip)
  • Arduino board (Uno, Nano, Mega, etc.) or compatible microcontroller
  • Breadboard and jumper wires (M-to-F or M-to-M)
  • USB cable to connect the board to your computer
  • Arduino IDE installed on your computer
  • BMP180 library (e.g., Adafruit BMP085 Unified, or SparkFun BMP180)

Step-by-Step

  1. Identify the pins on the GY-68 module. The board usually has 4 pins: VIN (or VCC), GND, SCL (SCK), and SDA (SDI). Some versions also expose EOC and XCLR, but you won't need those for basic use.
  2. Wire the GY-68 to your Arduino. Connect VIN to the 3.3V pin (not 5V, the BMP180 is a 3.3V device, though many modules have a regulator—check your board). Connect GND to GND. Connect SCL to the Arduino's I2C clock pin (A5 on Uno/Nano, D21 on Mega, D19 on ESP32). Connect SDA to the Arduino's I2C data pin (A4 on Uno/Nano, D20 on Mega, D18 on ESP32).
  3. Install the BMP180 library. In the Arduino IDE, go to Sketch → Include Library → Manage Libraries. Search for “BMP085” or “BMP180” and install a well-known library like “Adafruit BMP085 Unified” (it works with BMP180). Alternatively, download the SparkFun BMP180 library from GitHub and place it in your libraries folder.
  4. Open a basic example sketch. After installing the library, go to File → Examples → Adafruit BMP085 Unified → bmp085test (or similar). This sketch reads temperature and pressure and prints them to the Serial Monitor.
  5. Upload the sketch to your board. Select the correct board and port under Tools, then click Upload. Open the Serial Monitor (Tools → Serial Monitor) and set baud rate to 9600 (or match the sketch's Serial.begin value). You should see temperature and pressure readings updating every second or so.
  6. Record the current pressure at your location. Note the pressure reading in pascals (Pa) or hectopascals (hPa) from the Serial Monitor. For reference, standard sea-level pressure is 101325 Pa (1013.25 hPa).
  7. Add the altitude calculation to the sketch. In the loop() function, after reading pressure, use the barometric formula: altitude = 44330 * (1 - (pressure/seaLevelPressure)^(1/5.255)). In code, that is: float altitude = 44330 * (1 - pow(pressure/101325.0, 1/5.255)); where pressure is in pascals. If you want feet, multiply by 3.28084.
  8. Print the altitude. Add a line like Serial.print("Altitude: "); Serial.print(altitude); Serial.println(" m"); after the calculation.
  9. Upload the modified sketch and test. The Serial Monitor should now show altitude in meters. If you are near sea level, it should be close to 0 m. If you are in a building, it may show a few meters (due to indoor pressure differences).
  10. Calibrate for better accuracy. If you know your exact altitude (e.g., from a GPS or topo map), adjust the sea-level pressure constant in the formula until the reading matches. This compensates for local weather pressure variations.

Common Mistakes

  • Using 5V power. The BMP180 chip is 3.3V; feeding 5V can damage it. Use the 3.3V pin unless your module clearly has a regulator.
  • Wrong I2C pins. On some boards, I2C is not on A4/A5. Check your board's pinout.
  • Forgetting pull-up resistors. Most GY-68 modules have pull-ups, but if you are using a bare BMP180, you need 4.7kΩ resistors on SDA and SCL to VCC.
  • Using pressure in hPa in the formula. The formula expects pascals. If your library returns hPa, multiply by 100.
  • Not accounting for weather. Altitude from pressure is only accurate if you use the current sea-level pressure. A high-pressure system can make your altitude read lower than actual.

Tips

  • Read pressure multiple times and average them to reduce noise.
  • Place the sensor away from heat sources (like the Arduino board) to avoid temperature-induced pressure errors.
  • Use the library's built-in sea-level pressure function if available; it often uses the current pressure at your location to compute relative altitude.
  • For absolute altitude, you need to know the current sea-level pressure from a weather station or an online source.
  • Calibrate the sensor at a known altitude (e.g., your home's elevation) and store the offset in EEPROM so it persists.

Troubleshooting

  • No readings on Serial Monitor: Check wiring, especially SDA/SCL. Ensure the library is installed correctly. Try a different I2C address (0x77 vs 0x76) by modifying the library or using an I2C scanner sketch.
  • Readings are stuck at 0 or -1: This usually means the sensor is not communicating. Check power and ground, and verify the I2C pins are correct.
  • Altitude is negative: This happens when the local sea-level pressure is lower than the standard 101325 Pa (e.g., during a storm). Use the actual sea-level pressure for your area.
  • Altitude fluctuates wildly: The sensor is sensitive to drafts and temperature changes. Move it to a stable environment and apply averaging.
  • Library not compiling: Make sure you have the correct board selected and that the library is compatible with your Arduino core (e.g., ESP32 may need a different library).

Frequently Asked Questions

What is the difference between GY-68 and BMP180?

GY-68 is a breakout board that contains the BMP180 sensor chip, along with pull-up resistors and a voltage regulator (on some versions). The BMP180 is the actual pressure sensor.

Can I use the BMP180 to measure altitude for a drone?

Yes, but it's not ideal for precise altitude hold because it's sensitive to air pressure changes and lacks a built-in filter. For hobbyist use, it works, but you'll need to fuse it with accelerometer data.

Why does my altitude change when the weather changes?

Because the BMP180 measures absolute pressure, not altitude directly. A change in weather (high/low pressure system) changes the pressure at your location, making the altitude calculation shift. This is why you need to update the sea-level pressure reference.

What is the maximum altitude I can measure?

The BMP180 can measure pressure down to 300 hPa, which corresponds to about 9 km (30,000 ft) altitude. Above that, the sensor may not be accurate.

How precise is the altitude reading?

With proper calibration and a stable sea-level reference, you can get accuracy within ±1 meter. Without calibration, expect ±10 meters or more due to weather variations.

Can I use the BMP180 with a Raspberry Pi?

Yes, you can connect it via I2C and use Python with the smbus library. The wiring is similar, but use 3.3V on the Pi's GPIO.

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions