Kutluhan Aktar
Published © CC BY

The Vibrating Pressure Temperature Altitude Tilt Detector

Get the highest accuracy and efficiency when measuring altitude with BMP180 Pressure Sensors by using a tilt sensor and a vibration motor.

IntermediateFull instructions provided2 hours1,284
The Vibrating Pressure Temperature Altitude Tilt Detector

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Adafruit BMP180 Barometric Pressure Sensor
×1
Adafruit Tilt Sensor(Mercury Sensor)
×1
SparkFun Vibration Motor
×1
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Green
5 mm LED: Green
×1
SparkFun Rotary Potentiometer
×1
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
SparkFun Solder-able Breadboard - Mini
SparkFun Solder-able Breadboard - Mini
×1
Resistor 221 ohm
Resistor 221 ohm
×2
Resistor 10k ohm
Resistor 10k ohm
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Male/Male Jumper Wires
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering Iron
Hot Glue Gun

Story

Read more

Custom parts and enclosures

Fritzing File

Schematics

Schematics

Code

Source Code

Arduino
         /////////////////////////////////////////////  
        //    The Vibrating Pressure, Altitude     //
       //      Temperature and Tilt Detector      //
      //       ----------------------------      //
     //             (Arduino Nano)              //           
    //             by Kutluhan Aktar           // 
   //                                         //
  /////////////////////////////////////////////

// Get pressure, temperature and altitude values from a BMP180 sensor with regard to a baseline pressure in mb.
// Detect a tilted plain with the data produced by a tilt sensor digitally as 0 and 1, or LOW and HIGH.
// Also, if this sensor and Arduino Nano are not balanced on a flat plain, get notified by the vibration generated by a vibration motor, and FALSE and OK led.
//
// On a flat plain;
// Tilt sensor is HIGH,
// OK is HIGH,
// FALSE is LOW,
// Vibration motor is LOW,
// Pressure, temperature and altitude values are displayed.
//
// On a tilted plain;
// Tilt sensor is LOW,
// OK is LOW,
// FALSE is HIGH,
// Vibration motor is HIGH,
// Error message is displayed - "Please balance on a flat plain!".
//
// Connections
// Arduino Nano(CH340) :           
//                                BMP180 Pressure Sensor
// A4 --------------------------- SDA
// A5 --------------------------- SCL
//                                LCD Screen (16, 2)
// D7 --------------------------- rs
// D6 --------------------------- en
// D5 --------------------------- d4
// D4 --------------------------- d5
// D3 --------------------------- d6
// D2 --------------------------- d7
//                                Tilt Sensor(Mercury Sensor)
// GND + 10K + D8 --------------- Leg(1)
// 5V --------------------------- Leg(2)
//                                OK Led
// D9 --------------------------- +
//                                FALSE Led
// D10 -------------------------- +
//                                Vibration Motor
// D11 -------------------------- +
// GND -------------------------- -


// Include the LiquidCrystal library.
#include <LiquidCrystal.h>

// Initialize the library by associating any needed LCD interface pin with the arduino pin number it is connected to.
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);


// Celcius sign.
byte celcius[8] = {
0b01111,
0b01001,
0b01001,
0b01001,
0b01111,
0b00000,
0b00000,
0b00000
};
// Meter sign.
byte meter[8] = {
0b00000,
0b00000,
0b00000,
0b10001,
0b11011,
0b10101,
0b10001,
0b10001
};

// Your sketch must #include this library, and the Wire library.
// (Wire is a standard library included with Arduino.):

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

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

SFE_BMP180 pressure;

// Connect BMP180 SDA and SCL pins to the labeled pins below.
// Any Arduino pins labeled: SDA  SCL
// Nano, Uno, Pro:            A4   A5
// Mega2560, Due:             20   21
// Leonardo:                   2    3

// Define a baseline pressure (sea-level or other) in mb to predict altitude. 
#define p0 1013

// Define temperature, pressure, and baseline pressure variables.
char status;
double T,P,a;

// Define Tilt Sensor digital pin.
#define tilt 8
// Define OK and FALSE led.
#define OK 9
#define FALSE 10
// Define vibration motor digital pin.
#define vibration 11

void setup() {
// Initialize LCD screen.
lcd.begin(16, 2);
// Create celcius sign.
lcd.createChar(1, celcius);
// Create meter sign.
lcd.createChar(2, meter);

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

pinMode(tilt, INPUT);
pinMode(OK, OUTPUT);
pinMode(FALSE, OUTPUT);
pinMode(vibration, OUTPUT);

}

void loop() {
if(digitalRead(tilt) == HIGH){
  lcd.clear();
  // If the system on a flat plain.
  while(digitalRead(tilt) == HIGH){
  digitalWrite(OK, HIGH);
  digitalWrite(FALSE, LOW);
  // Deactivate vibration motor.
  digitalWrite(vibration, LOW);
  // Get data from BMP180 Pressure Sensor.
  get_temperature_and_pressure();

  digitalRead(tilt);
  }
}else if(digitalRead(tilt) == LOW){
  lcd.clear();
  // If tilt sensor is activated.
  while(digitalRead(tilt) == LOW){
  digitalWrite(OK, LOW);
  digitalWrite(FALSE, HIGH);
  // Activate vibration motor.
  digitalWrite(vibration, HIGH);
  // Display error message.
  lcd.setCursor(0,0);
  lcd.print("Please balance");
  lcd.setCursor(0,1);
  lcd.print("on a flat plain!");

  digitalRead(tilt);
  }
}



}

void get_temperature_and_pressure(){
// 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){
      lcd.setCursor(0,0);
      lcd.print(T);
      lcd.write(1);
      lcd.print("C");
      // 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(0);
        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){
              lcd.setCursor(3, 1);
              lcd.print(P);
              lcd.print(" mb");
              // 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);
              lcd.setCursor(9, 0);
              lcd.print(a);
              lcd.print(" ");
              lcd.write(2);
              }
          }
      }
  
   }

   delay(1000);
   
 }
 

Credits

Kutluhan Aktar

Kutluhan Aktar

17 projects • 31 followers
Self-Taught Full Stack Developer | Programmer | Maker | Physics Entusiast

Comments