1 /* SFE_BMP180 library example sketch
3 This sketch shows how to use the SFE_BMP180 library to read the
4 Bosch BMP180 barometric pressure sensor.
5 https://www.sparkfun.com/products/11824
7 Like most pressure sensors, the BMP180 measures absolute pressure.
8 This is the actual ambient pressure seen by the device, which will
9 vary with both altitude and weather.
11 Before taking a pressure reading you must take a temparture reading.
12 This is done with startTemperature() and getTemperature().
13 The result is in degrees C.
15 Once you have a temperature reading, you can take a pressure reading.
16 This is done with startPressure() and getPressure().
17 The result is in millibar (mb) aka hectopascals (hPa).
19 If you'll be monitoring weather patterns, you will probably want to
20 remove the effects of altitude. This will produce readings that can
21 be compared to the published pressure readings from other locations.
22 To do this, use the sealevel() function. You will need to provide
23 the known altitude at which the pressure was measured.
25 If you want to measure altitude, you will need to know the pressure
26 at a baseline altitude. This can be average sealevel pressure, or
27 a previous pressure reading at your altitude, in which case
28 subsequent altitude readings will be + or - the initial baseline.
29 This is done with the altitude() function.
36 (WARNING: do not connect + to 5V or the sensor will be damaged!)
38 You will also need to connect the I2C pins (SCL and SDA) to your
39 Arduino. The pins are different on different Arduinos:
41 Any Arduino pins labeled: SDA SCL
42 Uno, Redboard, Pro: A4 A5
46 Leave the IO (VDDIO) pin unconnected. This pin is for connecting
47 the BMP180 to systems with lower logic levels such as 1.8V
49 Have fun! -Your friends at SparkFun.
51 The SFE_BMP180 library uses floating-point equations developed by the
52 Weather Station Data Logger project: http://wmrx00.sourceforge.net/
54 Our example code uses the "beerware" license. You can do anything
55 you like with this code. No really, anything. If you find it useful,
56 buy me a beer someday.
58 V10 Mike Grusin, SparkFun Electronics 10/24/2013
61 // Your sketch must #include this library, and the Wire library.
62 // (Wire is a standard library included with Arduino.):
64 #include <SFE_BMP180.h>
68 // You will need to create an SFE_BMP180 object, here called "pressure":
72 // DHT object for humidity sensor
76 #define START_DELAY 20000
86 Serial1.println("START");
88 // Initialize the sensor (it is important to get calibration values stored on the device).
90 if (pressure.begin()) {
91 Serial1.println("BMP180 init success");
94 Serial1.println("BMP180 init fail\n\n");
111 byte GotTemperature,GotPressure;
113 // Loop here getting pressure readings every 60 seconds.
120 status = pressure.startTemperature();
122 // Wait for the measurement to complete:
125 // Retrieve the completed temperature measurement:
126 // Note that the measurement is stored in the variable T.
127 // Function returns 1 if successful, 0 if failure.
129 status = pressure.getTemperature(T);
134 Serial1.println("ERROR:TYPE=BMP180,MESSAGE=FAILED MEASURE TEMPERATURE\n");
137 Serial1.println("ERROR:TYPE=BMP180,MESSAGE=FAILED START TEMPERATURE MEASUREMENT\n");
140 // Start a pressure measurement:
141 // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
142 // If request is successful, the number of ms to wait is returned.
143 // If request is unsuccessful, 0 is returned.
145 status = pressure.startPressure(3);
147 // Wait for the measurement to complete:
150 // Retrieve the completed pressure measurement:
151 // Note that the measurement is stored in the variable P.
152 // Note also that the function requires the previous temperature measurement (T).
153 // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
154 // Function returns 1 if successful, 0 if failure.
156 status = pressure.getPressure(P,LastTemp);
158 // Print out the measurement:
162 Serial1.println("ERROR:TYPE=BMP180,MESSAGE=FAILED MEASURE PRESSURE\n");
165 Serial1.println("ERROR:TYPE=BMP180,MESSAGE=FAILED START PRESSURE MEASUREMENT\n");
167 if (GotPressure || GotTemperature) {
168 Serial1.print("SENSOR:TYPE=BMP180");
169 if (GotPressure) { Serial1.print(",PRESSURE="); Serial1.print(P); }
170 if (GotTemperature) { Serial1.print(",TEMPERATURE="); Serial1.print(T); }
175 delay(dht.getMinimumSamplingPeriod());
177 DHT_H = dht.getHumidity();
178 DHT_T = dht.getTemperature();
180 DHTStatus=dht.getStatus();
182 if (DHTStatus == 0) {
183 Serial1.print("SENSOR:TYPE=DHT22,TEMPERATURE=");
184 Serial1.print(DHT_T);
185 Serial1.print(",HUMIDITY=");
186 Serial1.println(DHT_H);
188 Serial1.println("ERROR:TYPE=DHT22,MESSAGE=MEASURING ERROR\n");
191 Gas = analogRead(GAS_PIN);
193 Serial1.print("SENSOR:TYPE=MQ4,VALUE=");
194 Serial1.println(Gas);
196 delay(DELAY); // Pause for 50 seconds.