BMP180 Barometer Pressure/Temperature/Altitude Sensor, DHT22 sensor interfaced  with Arduino uno

BMP180 Barometer Pressure/Temperature/Altitude Sensor, DHT22 sensor interfaced with Arduino uno

I was going through my electronic components junks and saw this tiny module. It is BMP180 GY- 68 Barometer Sensor. It is capable of measuring Pressure, temperature and altitude so I decided to interface it together with a DHT22 temperature and humdity sensor to an Arduino Uno. I should call it a mini weather station, right?.

See also:

Lets gather the components we will be needed to make this work:

  • Arduino Board  (Arduino uno)
  • 16×2 LCD screen
  • BMP180 GY- 68 Barometer Sensor
  • DHT22 temperature and humdity sensor
  • Cables

 

Setting up

NOTE: BMP180 GY- 68 Barometer Sensor runs on 3.3volts only

  • BMP180 VCC – uno 3.3v pin
  • BMP180 GND – uno GND
  • BMP180 SDA – uno SDA
  • BMP180 SCL – uno SCL

 

To setup DHT22 sensor, this POST should help you out.

 

  • LCD VDD – uno 5volts pin
  • LCD D4 – uno D2
  • LCD D5 – uno D3
  • LCD D6 – uno D4
  • LCD D7 – uno D5
  • LCD E – uno D11
  • LCD RS – uno D12
  • LCD VSS  – uno GND

This diagram should help you out:

 

connections - steinacoz
connections – steinacoz

 

Code

Get BMP180 library from here

Open Arduino IDE and paste these lines of codes:

 

/** code from steinacoz platform at https.//steinacoz.com - for all your electronics components and tutorials
 *  gathered by Nnadi Ugwumsinachi  
 */

#include <LiquidCrystal.h>
#include "DHT.h"
#include <SFE_BMP180.h>
#include <Wire.h>

#define DHTPIN 8     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
#define led 13

// You will need to create an SFE_BMP180 object, here called "pressure":

SFE_BMP180 pressure;

#define ALTITUDE 448.0 // Altitude of my location now

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

DHT dht(DHTPIN, DHTTYPE);

void setup()
{
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("steinacoz.com");
  pinMode(led, OUTPUT);
  
  dht.begin();
  lcd.clear();
  
  Serial.begin(9600);


  // Initialize the sensor (it is important to get calibration values stored on the device).

  if (pressure.begin())
    Serial.println("BMP180 init success");
  else
  {
    // Oops, something went wrong, this is usually a connection problem,
    // see the comments at the top of this sketch for the proper connections.

    Serial.println("BMP180 init fail\n\n");
    while(1); // Pause forever.
  }
}

void loop()
{
  char status;
  double T,P,p0,a;

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' 
  float h = dht.readHumidity();
  // Read temperature as Celsius
  float t = dht.readTemperature();

  // Loop here getting pressure readings every 10 seconds.

  // If you want sea-level-compensated pressure, as used in weather reports,
  // you will need to know the altitude at which your measurements are taken.
  // We're using a constant called ALTITUDE in this sketch:
  
  Serial.println();
  Serial.print("provided altitude: ");
  Serial.print(ALTITUDE,0);
  Serial.print(" meters, ");
  Serial.print(ALTITUDE*3.28084,0);
  Serial.println(" feet");
  
  // If you want to measure altitude, and not pressure, you will instead need
  // to provide a known baseline pressure. This is shown at the end of the sketch.

  // You must first get a temperature measurement to perform a pressure reading.
  
  // Start a temperature measurement:
  // If request is successful, the number of ms to wait is returned.
  // If request is unsuccessful, 0 is returned.

  status = pressure.startTemperature();
  if (status != 0)
  {
    // Wait for the measurement to complete:
    delay(status);

    // Retrieve the completed temperature measurement:
    // Note that the measurement is stored in the variable T.
    // Function returns 1 if successful, 0 if failure.


    status = pressure.getTemperature(T);
    if (status != 0)
    {
      // Print out the measurement:
      Serial.print("temperature: ");
      Serial.print(T,2);
      Serial.print(" deg C, ");
      Serial.print((5.0/9.0)*T+32.0,2);
      Serial.println(" deg F");
      
      // Start a pressure measurement:
      // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
      // If request is successful, the number of ms to wait is returned.
      // If request is unsuccessful, 0 is returned.

      status = pressure.startPressure(3);
      if (status != 0)
      {
        // Wait for the measurement to complete:
        delay(status);

        // Retrieve the completed pressure measurement:
        // Note that the measurement is stored in the variable P.
        // Note also that the function requires the previous temperature measurement (T).
        // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
        // Function returns 1 if successful, 0 if failure.

        status = pressure.getPressure(P,T);
        if (status != 0)
        {
          // Print out the measurement:
          Serial.print("absolute pressure: ");
          Serial.print(P,2);
          Serial.print(" mb, ");
          Serial.print(P*0.0295333727,2);
          Serial.println(" inHg");

          // The pressure sensor returns abolute pressure, which varies with altitude.
          // To remove the effects of altitude, use the sealevel function and your current altitude.
          // This number is commonly used in weather reports.
          // Parameters: P = absolute pressure in mb, ALTITUDE = current altitude in m.
          // Result: p0 = sea-level compensated pressure in mb

          p0 = pressure.sealevel(P,ALTITUDE);
          Serial.print("relative (sea-level) pressure: ");
          Serial.print(p0,2);
          Serial.print(" mb, ");
          Serial.print(p0*0.0295333727,2);
          Serial.println(" inHg");

          // On the other hand, if you want to determine your altitude from the pressure reading,
          // use the altitude function along with a baseline pressure (sea-level or other).
          // Parameters: P = absolute pressure in mb, p0 = baseline pressure in mb.
          // Result: a = altitude in m.

          a = pressure.altitude(P,p0);
          Serial.print("computed altitude: ");
          Serial.print(a,0);
          Serial.print(" meters, ");
          Serial.print(a*3.28084,0);
          Serial.println(" feet");
        }
        else Serial.println("error retrieving pressure measurement\n");
      }
      else Serial.println("error starting pressure measurement\n");
    }
    else Serial.println("error retrieving temperature measurement\n");
  }
  else Serial.println("error starting temperature measurement\n");


  // t = temperature, h = humidity, p = pressure in inHg, A = altitude

   lcd.setCursor(0, 0);
  lcd.print("t:");

  lcd.setCursor(2, 0);
  lcd.print(t);

 

  lcd.setCursor(8, 0);
  lcd.print("p:");

  lcd.setCursor(10, 0);
  lcd.print(P*0.0295333727);

  

  lcd.setCursor(0, 1);
  lcd.print("H:");

  lcd.setCursor(3, 2);
  lcd.print(h);

  lcd.setCursor(7, 7);
  lcd.print("%");

  lcd.setCursor(9, 7);
  lcd.print("A:");

  lcd.setCursor(11, 8);
  lcd.print(a,0);

   lcd.setCursor(14, 13);
  lcd.print("m");

  delay(5000);  // Pause for 5 seconds.
}

 

This should be our final result in a 16×2 LCD screen

lcd display - steinacoz
lcd display – steinacoz

 

 

For more post like these, you can follow this blog and our social media channels. Feel free to drop your comments.

 

One thought on “BMP180 Barometer Pressure/Temperature/Altitude Sensor, DHT22 sensor interfaced with Arduino uno

Leave a Reply

Your email address will not be published. Required fields are marked *