#include <Wire.h> #include <Adafruit_BMP085.h> #include <LiquidCrystal.h> LiquidCrystal lcd(8, 9, 4, 5, 6, 7); #include "DHT.h" #define DHTPIN 2 // what pin we're connected to #define DHTTYPE DHT11 // DHT 11 DHT dht(DHTPIN, DHTTYPE); // dht float tF; float dP; float dPF; // define some values used by the panel and buttons int lcd_key = 0; int adc_key_in = 0; #define btnRIGHT 0 #define btnUP 1 #define btnDOWN 2 #define btnLEFT 3 #define btnSELECT 4 #define btnNONE 5 // read the buttons int read_LCD_buttons() { adc_key_in = analogRead(0); // read the value from the sensor // my buttons when read are centered at these valies: 0, 144, 329, 504, 741 // we add approx 50 to those values and check to see if we are close if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result if (adc_key_in < 50) return btnRIGHT; if (adc_key_in < 195) return btnUP; if (adc_key_in < 380) return btnDOWN; if (adc_key_in < 555) return btnLEFT; if (adc_key_in < 790) return btnSELECT; return btnNONE; // when all others fail, return this... } //bmp180 float Tc=0; float Tf=0; float Pa=0; float InHg=0; float Am=0; float Af=0; /*************************************************** This is an example for the BMP085 Barometric Pressure & Temp Sensor Designed specifically to work with the Adafruit BMP085 Breakout ----> https://www.adafruit.com/products/391 These displays use I2C to communicate, 2 pins are required to interface Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, all text above must be included in any redistribution ****************************************************/ //Modified by Steve Spence of http://arduinotronics.blogspot.com // Connect VIN of the BMP180/085 sensor to 5.0V // Connect GND to Ground // Connect SCL to A5 on Arduino Uno // Connect SDA to A4 on Arduino Uno Adafruit_BMP085 bmp; void setup() { dht.begin(); Serial.begin(9600); if (!bmp.begin()) { Serial.println("Could not find a valid BMP085 sensor, check wiring!"); while (1) {} } analogWrite(10, 50); // set brightness on pin 10 to 0-255 lcd.begin(16, 2); // start the library lcd.setCursor(0,0); lcd.print("Push the buttons"); // print a simple message } void loop() { Serial.print("Temperature = "); //Serial.print(bmp.readTemperature()); Tc=bmp.readTemperature(); Tf=((Tc*9)/5)+32; Serial.print(Tf); Serial.println(" *F"); Serial.print("Pressure = "); //Serial.print(bmp.readPressure()); Pa=bmp.readPressure(); InHg=Pa*0.000295333727; Serial.print(InHg); Serial.println(" In Hg"); // Calculate altitude assuming 'standard' barometric // pressure of 1013.25 millibar = 101325 Pascal Serial.print("Altitude = "); //Serial.print(bmp.readAltitude()); Am=bmp.readAltitude(101550); //adjusted for local altitude Af=Am*3.28084; Serial.print(Af); Serial.println(" feet"); // you can get a more precise measurement of altitude // if you know the current sea level pressure which will // vary with weather and such. If it is 1015 millibars // that is equal to 101500 Pascals. // Serial.print("Real altitude = "); // Serial.print(bmp.readAltitude(101500)); // Serial.println(" meters"); Serial.println(); // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float h = dht.readHumidity(); float t = dht.readTemperature(); // check if returns are valid, if they are NaN (not a number) then something went wrong! if (isnan(t) || isnan(h)) { Serial.println("Failed to read from DHT"); } else { Serial.print("Humidity: "); Serial.print(h); Serial.println(" %\t"); Serial.print("Temperature: "); // Serial.print(t); // Serial.print(" *C "); tF=((t*9)/5)+32; Serial.print(tF); Serial.print(" *F "); Serial.println(" \t"); Serial.print("Dew Point: "); // Serial.print(dewPointFast(t, h)); // Serial.print(" *C "); dP=(dewPointFast(t, h)); dPF=((dP*9)/5)+32; Serial.print(dPF); Serial.print(" *F"); Serial.println(" \t"); Serial.print("Heat Index: "); Serial.print(heatIndex(tF,h)); Serial.println(" *F"); } delay(1000); //lcd.setCursor(9,1); // move cursor to second line "1" and 9 spaces over //lcd.print(millis()/1000); // display seconds elapsed since power-up lcd.setCursor(0,1); // move to the begining of the second line lcd_key = read_LCD_buttons(); // read the buttons switch (lcd_key) // depending on which button was pushed, we perform an action { case btnRIGHT: { lcd.clear(); lcd.setCursor(0,1); lcd.print("Pressure: "); lcd.print(InHg); break; } case btnLEFT: { lcd.clear(); lcd.setCursor(0,1); lcd.print("Temp: "); lcd.print(Tf); break; } case btnUP: { lcd.clear(); lcd.setCursor(0,1); lcd.print("Humidity: "); lcd.print(h); break; } case btnDOWN: { //lcd.print("DOWN "); break; } case btnSELECT: { //lcd.print("SELECT"); break; } case btnNONE: { //lcd.print("NONE "); break; } } } // delta max = 0.6544 wrt dewPoint() // 6.9 x faster than dewPoint() // reference: http://en.wikipedia.org/wiki/Dew_point double dewPointFast(double celsius, double humidity) { double a = 17.271; double b = 237.7; double temp = (a * celsius) / (b + celsius) + log(humidity*0.01); double Td = (b * temp) / (a - temp); return Td; } double heatIndex(double tempF, double humidity) { double c1 = -42.38, c2 = 2.049, c3 = 10.14, c4 = -0.2248, c5= -6.838e-3, c6=-5.482e-2, c7=1.228e-3, c8=8.528e-4, c9=-1.99e-6 ; double T = tempF; double R = humidity; double A = (( c5 * T) + c2) * T + c1; double B = ((c7 * T) + c4) * T + c3; double C = ((c9 * T) + c8) * T + c6; double rv = (C * R + B) * R + A; return rv; }