I have set up a BMP180 and a DHT11 to display data on an HD44780 20x4 LCD.
I want to be able to toggle the altitude from meters to feet, the temperature from Celsius to Fahrenheit, and the pressure from absolute to sea level pressure using a tactile push button.
Here is the software code I have:
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#include <SFE_BMP180.h>
#include<dht.h>
dht DHT;
#define DHT11_PIN 8 // Second pin, leave 3rd pin unconnected 4th is ground
#include <SFE_BMP180.h>
#include <Wire.h>
// You will need to create an SFE_BMP180 object, here called "pressure":
SFE_BMP180 pressure;
#define ALTITUDE 237.0 // Altitude of Phillaur in Punjab, India. in meters
void setup() {
lcd.begin(20, 4);
lcd.setCursor(0, 0); // Zeroth Row
lcd.print("hello, world!");
lcd.clear();
int chk = DHT.read11(DHT11_PIN);
// Initialize the sensor (it is important to get calibration values stored on the device).
if (pressure.begin()) {
lcd.print("BMP180 init Success");
delay(300);
} else {
lcd.print("BMP180 init fail");
while (1); // Pause forever.
}
}
void loop() {
char status;
double T, P, p0, a;
lcd.clear();
lcd.setCursor(0,0);
//TODO Display in Feet as well using toggle
lcd.print("Altitude: ");
lcd.print(ALTITUDE, 0);
lcd.print(" mtrs ");
status = pressure.startTemperature();
if (status != 0) {
// Wait for the measurement to complete:
delay(status);
status = pressure.getTemperature(T);
if (status != 0) {
// Print out the measurement:
Serial.print("temperature in deg C, From BMP180: ");
lcd.setCursor(0, 1);
lcd.print("Tmpratre: ");
lcd.print(T, 2);
lcd.print("'C");
lcd.setCursor(0, 2);
lcd.print("Humidity: ");
lcd.print(DHT.humidity, 1);
lcd.print("%");
status = pressure.startPressure(3);
if (status != 0) {
// Wait for the measurement to complete:
delay(status);
status = pressure.getPressure(P, T);
if (status != 0) {
lcd.setCursor(0,3);
// Print out the measurement:
lcd.print("Pressure: ");
lcd.print(P * 0.0295333727, 2);
lcd.print(" mb");
p0 = pressure.sealevel(P, ALTITUDE);
// we're at 234 meters (Phillaur, Pb)
// TODO: toggle to sea level to absolute pressure
Serial.print("relative (sea-level) pressure: ");
Serial.print(p0, 2);
Serial.print(" mb, ");
Serial.print(p0 * 0.0295333727, 2);
Serial.println(" inHg");
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");
delay(5000); // Pause for 5 seconds.
}