// Sketch to read temperature and altitude values and display them on an LCD. // // email: thomas@xief.net // projects.xief.net // BMP085 code from Adafruit: https://github.com/adafruit/Adafruit-BMP085-Library // Connect VCC of the BMP085 sensor to 3.3V (NOT 5.0V!) // Connect GND to Ground // Connect SCL to i2c clock - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 5 // Connect SDA to i2c data - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 4 #include "Wire.h" #include "BMP085.h" BMP085 bmp; #include // One-wire devices #include // DS18B20 #include // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // code for DS18B20 taken from https://gist.github.com/brooksware2000/3628594 #define DS18B20_BUS 10// Dallas DS18B20 temperature sensors //set up temp sensor OneWire oneWire(DS18B20_BUS); // Setup One-wire instance to communicate with DS18B20 sensors DallasTemperature temperatureSensors(&oneWire); // Pass oneWire reference to DallasTemperature library DeviceAddress DS18B20[3]; // Create an array for DS18B20 sensor addresses const char degree = 223; // Degree symbol byte snowflake[8] = { B00000, B10001, B01010, B00100, B11111, B00100, B01010, B10001, }; void setup() { // Initialize DS18B20 temperature sensors with precision set to 9 INIT_DS18B20(12); lcd.createChar(0, snowflake); lcd.begin(16, 2); Serial.begin(9700); bmp.begin(BMP085_HIGHRES); //ULTRAHIGHRES does not work lcd.setCursor(0,0); lcd.print("Gentlemen start"); lcd.setCursor(0,1); lcd.print("your engines."); delay(5000); lcd.clear(); } void loop() { // Read values from the sensor at address 0 float tempOUT = DS18B20_CELSIUS(0); //read data from pressure sensor float tempIN = bmp.readTemperature(); float altitude = bmp.readAltitude(); //101325 is sealevel pressure Serial.println(); Serial.println(tempOUT); Serial.println(tempIN); Serial.println(altitude); //Serial.println("C "); //Serial.setCursor(10, 2); lcd.setCursor(0, 0); lcd.print("O:"); lcd.print(tempOUT,1); lcd.print("C "); lcd.setCursor(7,0); lcd.print(" I:"); lcd.print(tempIN,1); lcd.print("C "); lcd.setCursor(0,1); lcd.print("Alt:"); lcd.print(altitude,0); lcd.print("m "); lcd.setCursor(15,1); if (tempOUT < 4) { lcd.write(byte(0)); } else { lcd.write(" "); } delay(1000); } /*----------------------------------------------------------------------------------------------- * Function: INIT_DS18B20 * Description: Initialize DS18B20 Temperature sensor(s) * Ins: Integer value for sensor precision. Can be 9, 10, 11 or 12 bits * ----------------------------------------------------------------------------------------------*/ void INIT_DS18B20(int precision) { temperatureSensors.begin(); int available = temperatureSensors.getDeviceCount(); for(int x = 0; x!= available; x++) { if(temperatureSensors.getAddress(DS18B20[x], x)) { temperatureSensors.setResolution(DS18B20[x], precision); } } } /*----------------------------------------------------------------------------------------------- * Function: DS18B20_CELSIUS * Description: Get celsius reading from DS18B20 Temperature sensor * ----------------------------------------------------------------------------------------------*/ float DS18B20_CELSIUS(int address) { if (temperatureSensors.getAddress(DS18B20[address], address)) { temperatureSensors.requestTemperatures(); return temperatureSensors.getTempC(DS18B20[address]); } else return 0; }