Barometer with advanced functions. The simplest barometric altimeter based on Arduino

BMP085 is a sensor for monitoring barometric pressure (in addition, it also monitors temperature).

The sensor is used in many projects, including those using Arduino, since it has practically no analogues. In addition, it is also inexpensive. The first question that arises is: why would anyone measure atmospheric pressure? There are two reasons for this. The first is to control the altitude above sea level. As altitude increases, pressure drops. Very convenient when hiking, as an alternative to GPS navigators. In addition, atmospheric pressure is used to forecast weather.

The BMP085 was once replaced by the BMP180 sensor, which connects to Arduino and other microcontrollers in the same way as its predecessor, but is smaller and costs less.

Technical characteristics of BMP085

  • Sensitivity range: 300-1100 hPa (9000 m - 500 m above sea level);
  • Resolution: 0.03 hPa / 0.25 m;
  • Working temperature-40 to +85°C, temperature measurement accuracy +-2°C;
  • Connection via i2c;
  • V1 on the module uses 3.3V supply and logic power;
  • V2 on the module uses 3.3-5V power and logic power;

After restarting the Arduino IDE, you can run the first example sketch, the code of which is given below:

#include <Wire.h>

#include <Adafruit_Sensor.h>

#include <Adafruit_BMP085_U.h>

Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

void setup(void)

Serial.begin(9600);

Serial.println("Pressure Sensor Test"); Serial.println("");

/* Initialize the sensor */

if(!bmp.begin())

/* If the message appears: "There was a problem detecting the BMP085 ...",

Check that the sensor is connected correctly */

Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!");

sensors_event_t event;

bmp.getEvent(&event);

/* display the results (barometric pressure is measured in hPa) */

if (event.pressure)

/* Display atmospheric pressure in hPa */

Serial.print("Pressure: "); Serial.print(event.pressure); Serial.println("hPa");

Open the serial monitor window (data transfer rate - 9600). Our sketch should output pressure data in hPa (hectopascals). You can check the functionality of the sensor by pressing your finger on the sensor. The figure shows the pressure values ​​after pressing with a finger.


Measuring altitude above sea level

You probably know that pressure drops with increasing altitude. That is, we can calculate the height knowing the pressure and temperature. Again, we will leave mathematics behind the scenes. If you're interested in the calculations, you can check them out on this Wikipedia page.

In the example below, the additional Arduino library will be used. To calculate height using the BMP085 sensor, update the "void loop()" function. Necessary changes sketches are given in the sketch below. As a result, you will get the temperature value based on the pressure level and the temperature value.

/* create a new event for the sensor */

sensors_event_t event;

bmp.getEvent(&event);

/* display results (barometric pressure in hPa) */

if (event.pressure)

/* display atmospheric pressure in hPa */

Serial.print("Pressure: ");

Serial.print(event.pressure);

Serial.println("hPa");

/* to calculate the height with a certain accuracy, you need to know *

* average pressure and ambient temperature

*in degrees Celsius at the time the readings were taken*

* if you do not have this data, you can use the "default value"

* which is equal to 1013.25 hPa (this value is defined as

*SENSORS_PRESSURE_SEALEVELHPA*

* in the sensors.h file). But the results will not be accurate*

*required values ​​can be found on websites with temperature forecasts*

* or on resources information centers at large airports*

*for example, for Paris, France, you can find the current average pressure value*

* via website: http://bit.ly/16Au8ol */

/* get the current temperature value from the BMP085 sensor */

float temperature;

bmp.getTemperature(&temperature);

Serial.print("Temperature: ");

Serial.print(temperature);

Serial.println("C");

/* convert the received data to height */

/* update next line, displaying the current values ​​*/

float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;

Serial.print("Altitude: ");

Serial.print(bmp.pressureToAltitude(seaLevelPressure,

Serial.println("m");

Serial.println("");

Serial.println("Sensor error");

We run the sketch and see the calculated altitude above sea level.

The accuracy of the BMP085 readings can be significantly increased by specifying the average pressure value, which varies depending on the weather. Every 1 hPa of pressure that we did not take into account leads to an error of 8.5 meters!

The figure below shows pressure values ​​from one of the information resources of a European airport. Yellow the pressure value is highlighted, which we can use to clarify the results.


Let's change the following line in our sketch, writing in it the current value (1009 hPa):

float seaLevelPressure = 1009;

As a result, we will get slightly different results:

Tip: when you specify the pressure, do not forget to convert the data used to hPa.

Using BMP085 (API v1)

Let us repeat once again: in order to find out the pressure and altitude above sea level, we need to carry out some calculations. But all of them are already included in the Adafruit_BMP085 Arduino Library (API v1), which can be downloaded from the link.

After installing the libraries, you need to restart the Arduino IDE

After the reboot, you can run the first example sketch:

#include <Wire.h>

Adafruit_BMP085 bmp;

Serial.begin(9600);

Serial.println(" *C");

Serial.print("Pressure = ");

Serial.println("Pa");

Serial.println();

After flashing your Arduino, open the serial monitor. Set the baud rate to 9600. The sketch will output the temperature in degrees Celsius and the pressure in pascals. If you place your finger on the sensing element of the sensor, the temperature and pressure will increase:


Altitude measurement (API v1)

To control the altitude above sea level, simply run the sketch below:

#include <Wire.h>

#include <Adafruit_BMP085.h>

Adafruit_BMP085 bmp;

Serial.begin(9600);

Serial.print("Temperature = ");

Serial.print(bmp.readTemperature());

Serial.println(" *C");

Serial.print("Pressure = ");

Serial.print(bmp.readPressure());

Serial.println("Pa");

// calculate the altitude above sea level based on the values

//"standard" barometric pressure equal to 1013.25 millibars = 101325 Pascal

Serial.print("Altitude = ");

Serial.print(bmp.readAltitude());

Serial.println(" meters");

Serial.println();

Run the sketch to display the results:


Judging by the readings above, we are at an altitude of -21.5 meters relative to sea level. But we know that we are above the sea! We recall the same problem as with using the API V2. We must take the weather into account! OK. Let's say we find a good weather website and the pressure is 101.964 Pa. Open the example Examples->BMP085test in the Arduino IDE and edit the line that is highlighted in the figure below:


In this line you need to enter the current pressure data. After a new launch, you will find that the data has changed dramatically and we got 29.58 meters with a plus sign, which is much more similar to the truth.


Leave your comments, questions and share personal experience below. New ideas and projects are often born in discussions!

A barometer is a device that measures atmospheric pressure. That is, air pressure that presses on us from all sides. Since school, we know that the first barometer was a plate with mercury and an inverted test tube in it. The author of this device was Evangelista Torricelli, an Italian physicist and mathematician. Taking readings from a mercury barometer can be taken as simply as readings from an alcohol thermometer: the greater the pressure outside the flask, the higher the column of mercury inside it. Mercury vapor is known to be highly toxic.

Later, a safer device appeared - an aneroid barometer. In this barometer, mercury was replaced by a corrugated box made of thin tin, in which a vacuum was created. Under the influence of the atmosphere, the box contracts and, through a system of levers, turns the arrow on the dial. This is what these two barometers look like. On the left is an aneroid, on the right is Torricelli’s barometer.

Why might we need a barometer? Most often, this device is used on aircraft to determine flight altitude. The higher the craft rises above sea level, the less pressure the onboard barometer experiences. Knowing this dependence, it is easy to determine the height.

Another common use case is a homemade weather station. In this case, we can use the known dependences of future weather on atmospheric pressure. In addition to the barometer, such stations are equipped with humidity and temperature sensors.

1. Electronic barometer

We cannot use such bulky barometers in robotics. We need a miniature and energy-efficient device that can easily be connected to the same Arduino Uno. Most modern barometers are made using MEMS technology, as are gyrotachometers and accelerometers. MEMS barometers are based on a piezoresistive or strain gauge method, which uses the effect of changing the resistance of a material under the influence of deforming forces.

If you open the MEMS barometer housing, you can see the sensing element (right), which is located directly under the hole in the protective housing of the device, and the control board (left), which performs the primary filtering and conversion of measurements.

2. Sensors BMP085 and BMP180

To the most affordable pressure sensors, which are often used in flight controllers and in various types of homemade electronic devices, sensors from BOSH can be attributed: BMP085 and BMP180. The second barometer is newer, but fully compatible with the old version.

A few important characteristics of the BMP180:

  • range of measured values: from 300 hPa to 1100 hPa (from -500m to +9000m above sea level);
  • supply voltage: from 3.3 to 5 Volts;
    current: 5 µA at polling speed - 1 Hertz;
  • noise level: 0.06 hPa (0.5m) in ultra low power mode and 0.02 hPa (0.17m) in a mode maximum resolution(advanced resolution mode).

Now let's connect this sensor to the controller and try to estimate the atmospheric pressure.

3. BMP180 connection

Both sensors have an I2C interface, so they can be easily connected to any platform from the Arduino family. This is what the Arduino Uno connection table looks like.

BMP 180 GND VCC S.D.A. SCL
Arduino Uno GND +5V A4 A5

Schematic diagram

Layout appearance

4. Program

To work with the sensor we need a library: BMP180_Breakout_Arduino_Library

Download it from the repository and install it in the Arduino IDE. Now everything is ready to write your first program. Let's try to get raw data from the sensor and output it to the COM port monitor.

#include #include SFE_BMP180 pressure; void setup())( Serial.begin(9600); pressure.begin(); ) void loop())( double P; P = getPressure(); Serial.println(P, 4); delay(100); ) double getPressure ()( char status; double T,P,p0,a; status = pressure.startTemperature(); if (status != 0)( // waiting for temperature measurement delay(status); status = pressure.getTemperature(T); if (status != 0)( status = pressure.startPressure(3); if (status != 0)( // waiting for pressure measurement delay(status); status = pressure.getPressure(P,T); if (status ! = 0)( return(P); ) ) ) ) )

The procedure for obtaining the desired pressure from the sensor is not so trivial and consists of several stages. In a simplified form, the algorithm looks like this:

  1. we ask the barometer for readings from the built-in temperature sensor;
  2. wait time A while the sensor evaluates the temperature;
  3. we get the temperature;
  4. we ask the barometer for pressure;
  5. wait time B while the sensor evaluates the pressure;
  6. get the pressure value;
  7. return the pressure value from the function.

Time B depends on the measurement accuracy, which is specified in the function startPressure. The single argument to this function can take values ​​from 0 to 3, where 0 is the coarsest and most quick assessment, 3 is the most accurate pressure estimate.

We load the program onto the Arduino Uno and observe the stream of atmospheric pressure measurements. Let's try to raise the sensor above your head and lower it to floor level. The readings will vary slightly. All that remains is to figure out how we can convert these strange numbers into altitude above sea level.

5. Convert pressure to altitude

The BMP180 sensor returns the pressure value in hectopascals (hPa). It is in these units that atmospheric pressure is usually measured. 1 hPa = 100 Pascals. It is known that at sea level the pressure is on average 1013 hPa, and each additional meter above sea level will reduce this pressure by only 0.11 hPa (approximately).

Thus, if we subtract from the function result getPressure the number is 1013, and divide the remaining difference by 0.11, then we get the height above sea level in meters. This is how our program will change:

Void loop())( double P, Alt; P = getPressure(); Alt = (P - 1013)/0.11; Serial.println(Alt, 2); delay(100); )

In fact, pressure depends nonlinearly on altitude above sea level, and our formula is only suitable for the altitudes at which we usually live. Fortunately, humanity knows a more accurate dependence of pressure on height, which we can apply to obtain more accurate results.

Here p is the pressure measured at a given point, p0 is the pressure relative to which the height is measured.

The SFE_BMP180 library already has a function that uses the specified one. formula to get exact height. We use it in our program.

#include #include SFE_BMP180 pressure; double P0 = 0; void setup())( Serial.begin(9600); pressure.begin(); P0 = pressure.getPressure(); ) void loop())( double P, Alt; P = getPressure(); Alt = pressure.altitude(P ,P0) Serial.println(Alt, 2); delay(100); double getPressure() ( ... )

I didn't completely copy the getPressure function to keep the text readable.

Another variable P0 has appeared in the program - this is the pressure that we will measure at the start of the program. In the case of an aircraft, P0 will be the pressure at the take-off site relative to which we will begin to climb.

6. Visualization

Now let's try to display pressure readings in the program SFMonitor, and let’s see how the pressure changes when the sensor moves to a height of 2 meters.

Static const byte PACKET_SIZE = 1; static const byte VALUE_SIZE = 2; static const boolean SEPARATE_VALUES = true; #include #include #include SFE_BMP180 pressure; SerialFlow rd(&Serial); double P0 = 0; void setup())( rd.setPacketFormat(VALUE_SIZE, PACKET_SIZE, SEPARATE_VALUES); rd.begin(9600); pressure.begin(); P0 = getPressure(); ) void loop())( double P; P = getPressure(); rd.setPacketValue(100+int((P - P0)*100)); rd.sendPacket(); delay(100) double getPressure( ... )

As a result of the program, we obtain a pressure graph in Pascals:

7. Conclusion

As we learned from the lesson, the definition of altitude above sea level is not the same trivial task. Not only does pressure depend nonlinearly on altitude, but the picture is also spoiled by various external factors. For example, the pressure in our home constantly changes over time. Even in a few minutes, the height measured by our device can vary in the range of 0.5 - 1 meter. Temperature also greatly affects the quality of measurements, so we have to take it into account when calculating pressure.

For aircraft It is recommended to use sensors increased accuracy, such as MS5611. This barometer's measurement accuracy can reach 0.012 hPa, which is 5 times better than BMP180. Also, GPS coordinates are used to clarify the flight barometric altitude.

Good luck observing the atmosphere! 🙂

Never before has there been a passion for electrical engineering, robotics, automatic systems response and control were not so easy to implement.

If previously there were specialized constructors with limited sets functions and strictly given parameters, then today’s variety of designers is simply amazing: real microprocessor systems, assembled on the knee, have almost unlimited functionality. Rich imagination, wide element base, large communities of fans and engineers and manufacturer support are the main ones distinctive features such market-demand robotics kits.

One of them and the most popular, naturally, is Arduino. Constructor for instant electronic assembly automatic devices any degree of difficulty: high, medium and low. This platform is otherwise called “physical computing” for its close interaction with environment. Printed circuit board with microprocessor, open program code, standard interfaces and connecting sensors to Arduino are the components of its popularity.

The system is the board that brings everything together necessary components, providing a full development cycle. The heart of this board is microcontroller. It provides control of all peripherals. Sensors connected to the system allow the system to “communicate” and interact with the environment: analyze, mark, change.

Connecting a digital humidity, temperature sensor

Two popular sensors - DHT11, DHT22 - are designed to measure humidity and temperature (we'll talk about connecting a temperature sensor); inexpensive solution, great for simple circuits and training. Thermistor, capacitive sensor - the basis of DHT11 and DHT22. The internal chip performs the ADC, giving the output a “digit” that any microcontroller will understand.

DHT11 differs from DHT22 in the measurement range and sampling frequency: humidity - 20-80% for DHT11 and 0-100% for DHT22; temperature - 0°C to +50°C for DHT11 and -40°C to +125°C for DHT22; polling - every second for DHT11 and once every two seconds for DHT22.

Both DHT sensors have standard 4 pins:

  1. Power supply for sensors.
  2. Data bus.
  3. Not involved.
  4. Earth.

The data and power pins require a 10k ohm resistor between them.

Designed for DHT sensors library DHT.h(can be viewed at the link). When loading the sketch into the controller, the port monitor should display the current values ​​of humidity and temperature. It’s easy to check its functionality - just breathe on the sensor and pick it up: the temperature and humidity should change.

It is possible to display values ​​on the screen LCD 1602 I2C, if you include it in the system.

Using these sensors you can build automated system watering the soil outdoors, in a greenhouse and even on a windowsill. Or organize a system for drying berries - the latter are blown or heated depending on the moisture content of the berries.

Also, some aquaterrariums require special conditions humidity, which can be easily controlled with DHT1 and DHT22.

Often, in predicting the weather or determining the altitude above sea level, it is necessary to solve the problem of measuring pressure. This is where electronic barometers based on MEMS technology come to the rescue: a strain gauge or piezoresistive method associated with the variability of the device resistance when forces deforming the material are applied.

Most Popular sensor BMP085; In addition to barometric pressure, it also records temperature. It was replaced by the BMP180, which has the same characteristics:

  • Sensitivity in the range: 300-1100 hPa (if in meters - 9000 - 500 m above sea level);
  • Resolution: 0.03 hPa or 0.25 m;
  • Operating temperature of the sensor -40 +85°C, measurement accuracy in the specified range - ±2°C;
  • Connection via i2c standard;
  • V1 uses 3.3V for power and logic;
  • V2 uses 3.3-5V for power and logic.

Connecting sensors to Arduino in this case is standard:

Will need Unified Sensor Driver- its updated version provides higher accuracy of readings; In addition, it allows you to work with several different connected pressure sensors simultaneously. You must also install the Adafrut_Sensor library.

Without of this sensor no serious security system can do this. Infrared sensor - base element detecting the presence of warm-blooded animals.

Also, using PIR sensors, it is extremely convenient to control lighting depending on the presence of a person nearby. Infrared or pyroelectric sensors are simple in internal structure and inexpensive. They are extremely reliable and rarely fail.

Sensor base- a pyroelectric or dielectric capable of creating a field when temperature changes. They are installed in pairs, and are closed on top with a dome with segments in the form of ordinary lenses or a Fresnel lens. This allows the beams to be focused from different penetration points.

In the absence of heat-emitting bodies in the room, each element has the same incoming radiation dose and, accordingly, the same voltage at the outputs. When a living warm-blooded animal enters the “viewing” zone of the sensors, the balance is disturbed and impulses appear, which are recorded.

HC-SR501- the most common and popular sensor. It has two trimmers resistor variables: one is for adjusting the sensitivity and size of the detected object, the second is for adjusting the response time (the time of pulse generation after detection).

The connection diagram is standard and will not cause any difficulties.

Although many sensors have a temperature measurement function, it is better to use a separate, specialized sensor. For example, DS18B20. This is an integrated sensor with a digital serial interface.

His strengths:

  • preliminary factory calibration;
  • error less than 0.5°C;
  • software-defined resolution of 0.0625°C at 12-bit resolution;
  • extremely wide range of measured temperatures: from -55°C to +125°C;
  • the sensor has a built-in ADC;
  • Several sensors can be included in one communication line.

TO-92 body- the most common for these sensors. There are two main schemes for connecting the DS18B20 temperature sensor to a microprocessor or controller:

To work with the sensor, it must be initialized. This is followed by writing a byte and reading a byte.

These three operations demonstrate how the sensor works and the OneWire library supports them perfectly. Install the OneWire Library. After that, we upload the sketch - and software environment ready.

It is possible to connect several DS18B20 sensors - in this case they must be connected in parallel. The OneWire library will allow you to read readings from all of them at once. With simultaneous a large number To connect sensors, you must add additional 100 or 120 Ohm resistors between the data leg of the DS18B20 sensor and the data bus on the Arduino.

conclusions

Connecting sensors to Arduino is the transformation of an algorithmic robot controlled automatically or manual mode, into a full-fledged environment for the interaction of devices and circuits with the environment. Do not forget - this is not a panacea for all ills. And not the final high-tech product or the final application. Arduino is a complex of hardware and software solutions which will help:

  • master algorithmization systems for novice engineers;
  • master basic design skills;
  • learn to program.

Regardless of your level of training, your knowledge, you can always choose tasks within your capabilities. You can put together a simple solution to automate any simple task without soldering together with a schoolchild; Or you can set a global task, which requires, in addition to knowledge and logic, the ability to solder efficiently and correctly draw and read drawings. And active communities, forums and knowledge bases on the Arduino system will help solve almost any issue.

Introduction

What can be displayed on a two-line screen other than “Hello world!”? Why not display temperature humidity and pressure?

The sensors offered as a tutorial for arduino (DHT11, DHT22) show air temperature and humidity. For educational purposes (for the university), it was also necessary to monitor pressure. Naturally, the department has a barometer, but why not build your own? In addition, you can further accumulate readings in automatic mode, and this is a good experience in learning arduino.

One way or another, components were ordered from China and this device was assembled.

Required components

USB-UART was used to send the sketch to arduino. You could also use a Raspberry Pi or a computer with a COM port.

Connection diagram for firmware and program code

USB-UART came from China with a set of wiring:

There were quite enough of them. I left the jumper at 3.3 volts, despite the fact that my arduino version Powered by 5 volts.

UART - Arduino
5v - VCC
TXD - RXD
RXD - TXD
GND - GND
CTS - DTR (optional, did not work for me, perhaps because the signal voltage remained 3.3V)

If you do not connect DTR, then after sending the firmware, the arduino needs to be rebooted using the built-in button, active data exchange will begin in both directions (as evidenced by the LEDs on the USB-UART), after the firmware has been successfully loaded, it will reboot itself.

Required third party libraries:

The code itself, with comments from the examples (in case someone needs to change something).

Code

#include #include "SparkFunBME280.h" #include "Wire.h" #include "SPI.h" #include //Global sensor object BME280 mySensor; LiquidCrystal_I2C lcd(0x3F,16,2); //Display address, in my case 0x3F void setup() ( lcd.init(); lcd.backlight(); //***Driver settings***************** ***************// //commInterface can be I2C_MODE or SPI_MODE //specify chipSelectPin using arduino pin names //specify I2C address. Can be 0x77(default) or 0x76 //For I2C, enable the following and disable the SPI section mySensor.settings.commInterface = I2C_MODE; mySensor.settings.I2CAddress = 0x76; //Sensor address, in my case not standard //For SPI enable the following and dissable the I2C section // mySensor.settings.commInterface = SPI_MODE; //mySensor.settings.chipSelectPin = 10; //***Operation settings************************* ****// //renMode can be: // 0, Sleep mode// 1 or 2, Forced mode // 3, Normal mode mySensor.settings.runMode = 3; //In the example they suggest using Forced mode, but when updating once a second, Normal mode //tStandby can be: // 0, 0.5ms // 1, 62.5ms // 2, 125ms // 3, 250ms // 4, 500ms // 5, 1000ms // 6, 10ms // 7, 20ms mySensor.settings.tStandby = 5; //Obviously, more often it is not necessary //filter can be off or number of FIR coefficients to use: // 0, filter off // 1, coefficients = 2 // 2, coefficients = 4 // 3, coefficients = 8 // 4 , coefficients = 16 mySensor.settings.filter = 0; //tempOverSample can be: // 0, skipped // 1 through 5, oversampling *1, *2, *4, *8, *16 respectively mySensor.settings.tempOverSample = 1; //pressOverSample can be: // 0, skipped // 1 through 5, oversampling *1, *2, *4, *8, *16 respectively mySensor.settings.pressOverSample = 1; //humidOverSample can be: // 0, skipped // 1 through 5, oversampling *1, *2, *4, *8, *16 respectively mySensor.settings.humidOverSample = 1; //Calling .begin() causes the settings to be loaded mySensor.begin(); ) void loop() ( //Letters can be displayed once, and then the readings can be changed, but the readings can shift the line when changing the number of significant digits. lcd.setCursor(0,0); lcd.print("H="); lcd .print((uint8_t)mySensor.readFloatHumidity()); lcd.print("%"); lcd.print(" T="); lcd.print(mySensor.readTempC()); ); lcd.print(" P:"); int mmH=mySensor.readFloatPressure()/133; lcd.print("mmH "); print(mySensor.readFloatPressure()); lcd.setCursor(14,1); lcd.print("Pa");


The sensor address can be guessed; there are only two of them.

You can see how to find out the address of your display. Depending on the microcircuit, there are two labels.

IN in this case:


And the address will be 0x3F because A0 - A2 open:

The LED that is circled in an oval can be better desoldered.

Connection diagram

The resistor was chosen as half of the sensor resistance (between VVC and GND) so that the voltage drop across it was 1.7 volts. The circuit can also be powered from the RAW input, with a different voltage (for example, from the crown).

The photo shows that, for compactness, you can take power to the sensor and display from another pin. You can also see a branch of an orange-yellow pair of wires; a 100 Ohm resistor hangs on them to reduce the brightness of the backlight (you can leave the jumper, but it will hurt your eyes).

In my case, everything is powered by the old one computer unit nutrition. Can be powered by USB. All components were glued with Moment glue that was on hand.

Bottom line

1602 appeared at the workplace, screwed to the table, which shows pressure, humidity, temperature. Arduino can be reflashed without removing it (maybe it will become a creeping line).

Atmospheric pressure sensors bmp180, bmp280, bme280 are frequent guests in engineering projects. They can be used to predict the weather or measure altitude above sea level. Today, this particular line can be called the most popular and inexpensive sensors for Arduino. In this article we will describe the principle of operation of the sensors, the connection diagram to various boards Arduino and give examples of programming sketches.

A barometer is a device that measures atmospheric pressure. Electronic barometers are used in robotics and various electronic devices. The most common and affordable pressure sensors are from BOSH: BMP085, BMP180, BMP280 and others. The first two are very similar to each other, the BMP280 is a newer and more improved sensor.

Pressure sensors work by converting pressure into movement of a mechanical part. The pressure sensor consists of a transducer with a sensitive element, a housing, mechanical elements (diaphragms, springs) and an electronic circuit.

The BMP280 sensor is designed specifically for applications where small size and reduced power consumption are required. Such applications include navigation systems, weather forecast, vertical speed indication and others. The sensor has high accuracy, good stability and linearity. Technical characteristics of the BMP280 sensor:

  • Dimensions 2 x 2.5 x 0.95 mm.
  • Pressure 300-1100 hPa;
  • Temperatures from 0C to 65C;
  • Support for I2C and SPI interfaces;
  • Supply voltage 1.7V – 3.6V;
  • Average current 2.7 µA;
  • 3 operating modes - sleep mode, FORCED mode (taking measurements, reading the value, going into sleep mode), NORMAL mode (switching the sensor into cyclic operation - that is, the device automatically exits sleep mode after a set time, takes measurements, reads readings, saves measured values ​​and goes back to sleep mode).

The BMP180 sensor is cheap and easy to use touch sensor, which measures atmospheric pressure and temperature. Usually used to determine altitude and in weather stations. The device consists of a piezo-resistive sensor, a temperature sensor, an ADC, non-volatile memory, RAM and microcontroller.

Technical characteristics of the BMP180 sensor:

  • The limits of measured pressure are 225-825 mm Hg. Art.
  • Supply voltage 3.3 – 5V;
  • Current 0.5mA;
  • I2C interface support;
  • Response time 4.5ms;
  • Dimensions 15 x 14 mm.

The bme280 sensor contains 3 devices - for measuring pressure, humidity and temperature. Designed for low current consumption, high reliability and long-term stable work.

Technical characteristics of the bme280 sensor:

  • Dimensions 2.5 x 2.5 x 0.93 mm;
  • Metal LGA case equipped with 8 outputs;
  • Supply voltage 1.7 – 3.6V;
  • Availability of I2C and SPI interfaces;
  • Standby current consumption 0.1 µA.

If you compare all the devices with each other, the sensors are very similar. Compared to its predecessor, which includes the BMP180, more new sensor BMP280 is noticeably smaller in size. Its eight pin miniature case requires care during installation. The device also supports I2C and SPI interfaces, unlike its predecessors, which only supported I2C. There are practically no changes in the operating logic of the sensor; only the temperature stability has been improved and the resolution of the ADC has been increased. The BME280 sensor, which measures temperature, humidity and pressure, is also similar to the BMP280. The difference between them is in the size of the case, since the BME280 has a humidity sensor, which slightly increases the dimensions. The number of contacts and their location on the body are the same.

Connection options for Arduino

Connecting the BMP180 sensor to Arduino. To connect you will need the BMP180 sensor itself, the Arduino UNO board, and connecting wires. The connection diagram is shown in the figure below.

The ground from the Arduino needs to be connected to the ground on the sensor, the voltage is 3.3 V, SDA is to pin A4, SCL is to pin A5. Pins A4 and A5 are selected based on their support for the I2C interface. The sensor itself operates on a voltage of 3.3 V, and the Arduino operates on 5 V, so a voltage stabilizer is installed on the module with the sensor.

Connecting BMP 280 to Arduino. The pinout and top view of the board are shown in the figure.

The pressure sensor module itself looks like this:

To connect to Arduino, you need to connect the outputs as follows: connect ground to Arduino and on the sensor, VCC - to 3.3V, SCL / SCK - to analog pin A5, SDA / SDI - to A4.

Connecting the BME280 sensor. The location of the contacts and pinout of the BME280 sensor is the same as that of the BMP280.

Since the sensor can operate via I2C and SPI, the connection can be implemented using two methods.

When connecting via I2C, you need to connect the SDA and SCL pins.

When connecting via SPI, you need to connect SCL from the module and SCK (13th pin on Arduino), SDO from the module to pin 12 of Arduino, SDA to pin 11, CSB (CS) to any digital pin, in this case to pin 10 on Arduino . In both cases, the voltage is connected to 3.3V on the Arduino.

Description of the library for working with the sensor. Sketch example

To work with the BMP180 sensor, there are various libraries that simplify the work. These include SFE_BMP180, Adafruit_BMP085. The same libraries are suitable for working with the BMP080 sensor. The bmp280 sensor uses a similar library, Adafruit_BMP280.

The first test sketch will make the sensor read pressure and temperature. The code is suitable for both the BMP180 and BMP280 sensors, you just need to connect the correct library and specify the correct contacts to which the module is connected. First of all, you need to connect all the libraries in the code and initialize the operation of the sensor. To determine pressure, you must first know the temperature. For this purpose it is used next element code.

Status = pressure.startTemperature(); // Reading temperature data from the sensor if(status!=0)( delay(status); // Waiting status = pressure.getTemperature(T); // Saving received temperature data if( status!=0)( Serial.print("Temperature: "); // Displays the word "Temperature" Serial.print(T,2); // Displays the temperature value. Serial.println("deg C, "); //Print the Celsius symbol.

Then you need to obtain information about atmospheric pressure.

Status = pressure.startPressure(3); // pressure is read if(status!=0)( delay(status); // Waiting status = pressure.getPressure(P,T); // pressure is received, saved if(status!=0)( Serial.print( "Absolute pressure: "); // Displays the words "Atmospheric pressure" Serial.print(P,2); // Displays the value of the variable mBar Serial.print(" mbar, "); "mBar" Serial.print(P*0.7500637554192,2); // display the value in mmHg (mmHg) Serial.println(" mmHg");) // display the pressure unit "mmHg" " (mmHg.).

After loading the sketch, data on temperature and atmospheric pressure will appear in the port monitoring window.

The BME280 sensor also shows pressure and temperature, in addition it can read humidity readings, which is turned off by default. If necessary, you can adjust the sensor and start reading humidity readings. Measuring range from 0 to 100%. The library that is needed to work with the sensor is called Adafruit_BME280.

The code is similar to that described above, only lines are added to it to determine humidity.

Void printValues() ( Serial.print("Temperature = "); Serial.print(bme.readTemperature()); Serial.println(" C"); //determining the temperature, displaying it on the screen in degrees Celsius. Serial. print("Pressure = "); Serial.print(bme.readPressure() / 100.0F); Serial.println(" hPa"); //determining the pressure, displaying it on the screen Serial.print("Humidity = "); Serial.print(bme.readHumidity()); Serial.println(" %"); //determining the humidity as a percentage, displaying the measured value Serial.println();

Possible connection errors and their elimination

The most common error is incorrect data on pressure and temperature, which differ by several orders of magnitude from real value. The reason for this most often is incorrect connection– for example, the library states that it needs to be connected via I2C, but the sensor is connected via SPI.

Also, when using “Chinese” sensors, you may encounter non-standard I2C or SPI addresses. In this case, it is recommended to scan all connected devices using one of the popular sketches and find out which address your pressure sensor responds to.

Another problem may be a discrepancy between the operating voltage of the module and the base voltage of the controller used. So, to work with a 3.3 V sensor, you will need to create a voltage divider or use one of the existing ready-made level matching modules. By the way, such modules are quite cheap and beginners are recommended to use them.

Small deviations from the actual value may be due to sensor calibration. For example, for the BMP180 sensor, all data is calculated and specified in a sketch. To obtain a more accurate altitude value, you need to know the current pressure above sea level for these coordinates.

Conclusion

Atmospheric pressure sensors bmp180, bmp280 are not the cheapest types of sensors, but in many cases there is practically no alternative to such sensors. In the weather station project, the sensor records important parameter– atmospheric pressure, which makes it possible to predict the weather. In projects related to the creation of flying vehicles, the barometer is used as a sensor of real altitude above sea level.

Connecting sensors does not present any difficulty, because a standard i2C or SPI connection is used. For programming, you can use one of the ready-made ones.