Lacybad
Published © MPL-2.0

Arduino Barometer with BMP180

This is a simple barometer with BMP180, a Nokia 5110 display, and an Arduino Mega.

BeginnerWork in progress1,749
Arduino Barometer with BMP180

Things used in this project

Story

Read more

Code

U8GLIB5110LCDBMP180.ino

Arduino
A simple sketch to measure barometric pressure.
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include "U8glib.h"

Adafruit_BMP085 bmp;

U8GLIB_PCD8544 u8g(8, 4, 7, 5, 6);  // CLK=8, DIN=4, CE=7, DC=5, RST=6

float pressure = 0.0;
float tempC = 0.0;
float altitude = 0.0;
void BmpSensorRead(float* pressure, float* tempC, float* altitude);
void DisplayPresTemp(float* pressure, float* tempC, float* altitude);

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

  for (int a = 0; a < 30; a++)
  {
    u8g.firstPage();

    do
    {
      u8g.setFont(u8g_font_5x8);
      u8g.setFontRefHeightExtendedText();
      u8g.setDefaultForegroundColor();
      u8g.setFontPosTop();
      u8g.drawStr(4, a, "BMP180 Sensor");
    }
    while (u8g.nextPage());
  }

  delay(3000);

  if (!bmp.begin())
  {
    u8g.firstPage();

    do
    {
      u8g.setFont(u8g_font_5x8);
      u8g.setFontRefHeightExtendedText();
      u8g.setDefaultForegroundColor();
      u8g.setFontPosTop();
      u8g.drawStr(4, 0, "BMP085 Sensor");
      u8g.drawStr(4, 20, " ERROR!");
    }
    while (u8g.nextPage());

    Serial.println("BMP085 sensor, ERROR!");

    while (1) {}
  }
}
void loop(void)
{
  BmpSensorRead(&pressure, &tempC, &altitude);
  DisplayPresTemp(&pressure, &tempC, &altitude);
  delay(1000);
}
void DisplayPresTemp(float* pressure, float* tempC, float* altitude)
{
  u8g.firstPage();

  do
  {
    u8g.setFont(u8g_font_6x10);
    u8g.setFontRefHeightExtendedText();
    u8g.setDefaultForegroundColor();
    u8g.setFontPosTop();
    u8g.drawStr(2, 0, "Pressure");
    u8g.setPrintPos(20, 9);
    u8g.print(*pressure);
    u8g.drawStr(0, 20, "Temp C");
    u8g.setPrintPos(45, 20);
    u8g.print(*tempC);
    u8g.drawStr(0, 31, "Altitude");
    u8g.setPrintPos( 45, 40);
    u8g.print(*altitude);
  }
  while (u8g.nextPage());
}
void BmpSensorRead(float* pressure, float* tempC, float* altitude)
{
  *tempC = bmp.readTemperature();
  Serial.print("Temperature = ");
  Serial.print(*tempC);
  Serial.println(" *C");

  *pressure = bmp.readPressure() / 98.5;
  Serial.print("Pressure = ");
  Serial.print(*pressure / 100.0);
  Serial.println(" hPa");

  // Calculate altitude assuming 'standard' barometric
  // pressure of 1013.25 millibar = 101325 Pascal
  *altitude = bmp.readAltitude();
  Serial.print("Altitude = ");
  Serial.print(*altitude);
  Serial.println(" meters");
}

Credits

Lacybad

Lacybad

2 projects • 0 followers

Comments