Tutorials

Interfacing MS5611 Barometer & Altimeter Sensor with Arduino

Learn how to interface MS5611-01BA03 High Precision Atmospheric Pressure Sensor Module with Arduino to measure Pressure, Temperature and Altitude

Overview:

In this detailed tutorial, we will learn how to interface the MS5611 barometer and altimeter sensor with Arduino for accurate pressure and altitude measurements. Whether you’re working on a weather monitoring system, an altitude-based project, or simply want to dive into sensor integration, this article will provide you with step-by-step instructions and the necessary code to get started.

First, we will learn what is MS5611, and what are its features and specifications and then we will explain how to connect it with Arduino using an easily understandable circuit diagram and programming Arduino to measure pressure, altitude, and temperature. and Finally, we will explain the code.

MS5611 Barometer/Altimeter Sensor (MS5611-01BA03)

ms5611-01ba03 barometric pressure and altitude sensor

When it comes to accurate altitude and pressure measurements, the MS5611-01BA stands out as a remarkable sensor developed by MEAS Switzerland. With its high-resolution capabilities and versatile interface options, this sensor is a go-to choice for engineers, researchers, and hobbyists alike. Let’s dive into the features and specifications that make the MS5611-01BA a standout performer.

MS5611 Pinout

MS5611 Module Pinout diagram

 

Flexible Interface Options: SPI and I2C

The MS5611-01BA offers the convenience of both SPI (Serial Peripheral Interface) and I2C (Inter-Integrated Circuit) bus interfaces. The Pin PS(Protocol select) is responsible for choosing I2C or SPI protocol, by default it uses I2C protocol but by pulling PS pin to Low enables SPI communication.

This flexibility allows users to seamlessly integrate the sensor into their projects, ensuring smooth communication with microcontrollers and other devices. Whether you prefer the simplicity of I2C or the speed of SPI, the MS5611-01BA accommodates your interface preference.

The CSB pin which is CHIP SELECT pin is used when our requirement is to connect 2 chip on same I2C bus. By default I2C Address is 0x77, but when we connect CSB pin to VCC(pulling High) it becomes 0x76.

On-Chip Temperature Sensor for Compensation and Calibration

One of the standout features of the MS5611-01BA is its built-in temperature sensor. This sensor plays a crucial role in compensating for changes in the environment, ensuring that the measurements obtained remain accurate and reliable. By accounting for temperature variations, the sensor calibrates its readings, taking into consideration the impact of ambient temperature on altitude and pressure values. This calibration process enhances the precision and stability of the measurements, providing users with highly accurate data.

High Linearity Pressure Sensor and Ultra-Low Power ADC

The MS5611-01BA boasts a high linearity pressure sensor and an ultra-low power 24-bit ΔΣ ADC (Analog-to-Digital Converter) with internal factory-calibrated coefficients. This combination enables the sensor to provide precise digital 24-bit pressure and temperature values. The module offers different operation modes, allowing users to optimize for conversion speed and current consumption, providing flexibility in meeting project requirements.

Impressive Pressure and Temperature Measurement Range

The MS5611-01BA offers an impressive pressure measurement range of 10mbar to 1200mbar. With an absolute accuracy of ±1.5 mbar with in the pressure range of 450-1100mbar and gives ± 2.5 mbar accuracy when outside the pressure range, the sensor delivers reliable pressure data for a wide range of applications. Additionally, the sensor is optimized for altimeters and variometers, boasting an altitude resolution of 10cm.

When it comes to temperature measurements, the MS5611-01BA covers a temperature range from -40˚C to +85˚C. With an accuracy of ±0.8˚C, the sensor ensures precise temperature readings, allowing users to capture environmental temperature variations accurately.

Seamless Integration with Microcontrollers

To simplify integration, the MS5611-01BA module comes equipped with a MIC5205 3.3V precise voltage regulator and voltage level translator. This feature enables the sensor to be used with both 3.3V and 5V microcontrollers, providing flexibility in selecting the appropriate hardware for your project.

MS5611 Features and Specifications

  • Supply voltage: 3.3 to 5 V
  • Pressure range: 10 to 1200 mbar
  • Pressure resolution: 0.012 mbar
  • Pressure Absolute Accuracy: ±1.5 mbar
  • Temperature range: -40 °C to 85 °C
  • Temperature resolution: 0.01 °C
  • Temperature Accuracy: ±0.8˚C
  • ADC Resolution: 24-bit
  • Altitude resolution: 10 cm
  • Very low current consumption: Standby max. 0.14 μA
  • I²C and SPI interface

Interfacing MS5611 Barometer/Altimeter Sensor with Arduino

Required components

Product NameQuantityamazon logoamazon logo india
Arduino NANO1https://amzn.to/3jVNZONhttps://amzn.to/3KpUQry
MS5611-01BA03 pressure sensor1https://amzn.to/3MuTZIRhttps://amzn.to/3q6q6av
OLED Display1https://amzn.to/34f0GNihttps://amzn.to/35HZK4E
5V power supply (USB or External).1https://amzn.to/3s1a8g3https://amzn.to/364yInH
Few Connecting Wireshttps://amzn.to/3H2BV4ehttps://amzn.to/3J0WVu2
You can buy the required components from the given best buy links. We choose the components according to value for money.

Circuit Diagram for interfacing MS5611 with Arduino to display results on OLED display

Connect all the required components including OLED display to display results on it. If you dont need to display the pressure, altitude and temperature on OLED display you can skip it.

For detailed explaination of OLED refer: Interfacing SSD1306 OLED display with Arduino, ESP32 and ESP8266

Circuit Diagram for interfacing MS5611 with Arduino to display results on OLED display

As you can see from the above circuit diagram, the sensor MS5611 power pins VCC and GND are connected to 5V and GND of Arduino respectively. As we are not using PS and CSB pins the sensor uses I2C protocol with default address of 0x77. So I2C pins SDA and SCL of sensor are connected to A4 and A5 pins of Arduino respectively.

The OLED display SSD1306 power pins VCC and GND are connected to 5V and GND pins of Arduino and the I2c pins SDA and SCL are connected to A4 and A5 of Arduino respectively. Thats it for connection and lets move to the coding part.

If you’re looking for a professional PCB board that lets you seamlessly plug in your Arduino, sensors, and display, check out NextPCB. This top-tier PCB manufacturing and PCB assembly company delivers high-quality, reliable solutions tailored to your needs.

Program code

After connecting all the required components, connect Arduino NANO to PC where Arduino IDE is installed. If Arduino IDE is not installed check this link to download. Next copy the below code and paste it in the Arduino IDE workspace, install required libraries listed below, choose the device as “Arduino NANO” and choose the correct port and hit Upload button.

Required Libraries:

  • MS5611 by Jarzebski : here (download manually, not found in libraries)
  • Adafruit_SSD1306 : here
/*
  MS5611 Barometric Pressure & Temperature Sensor with Altitude measurement
  This code is developed by https://www.circuitschools.com
*/
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <MS5611.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 //Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C //See datasheet for Address
 
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

MS5611 ms5611;

void setup() {
  Serial.begin(115200);
  while(!Serial);
  // Initialize MS5611 sensor
  Serial.println("Initialize MS5611 Sensor");
  if (!ms5611.begin()) {
    Serial.println("MS5611 not found, check wiring!");
    while (1);
  }
  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }
  display.clearDisplay();
  display.display();
  delay(500);

   // Check settings
  checkSettings();
  delay(2000);
}

void checkSettings()
{
  Serial.print("Oversampling: ");
  Serial.println(ms5611.getOversampling());
}

void loop() {
  // Set you real altitude
  // My location: Newyork
  double myRealAltitude = 10;
  
   uint32_t rawpressure = ms5611.readPressure();
   //converting Pascals to mbar
   uint32_t pressure = rawpressure/100;
   double temperature = ms5611.readTemperature();
    // Calculate altitude
  float absoluteAltitude = ms5611.getAltitude(pressure);
  float relativeAltitude = ms5611.getAltitude(pressure, myRealAltitude);
  Serial.println("---");
  Serial.print("Temperature: ");
  Serial.print(temperature, 2);
  Serial.println("*c");
  Serial.print("\tPressure: ");
  Serial.print(pressure, 2);
  Serial.println(" mb");
  Serial.print(" absoluteAltitude = ");
  Serial.print(absoluteAltitude);
  Serial.print(" m, relativeAltitude = ");
  Serial.print(relativeAltitude);
  Serial.println(" m");
  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  
  display.setCursor(0, 0);
  display.setTextSize(1);
  display.print("Temperature: ");
  display.print(temperature);
  display.print("*C");
 
  display.setCursor(0, 20);
  display.setTextSize(1);
  display.print("Pressure: ");
  display.print(pressure);
  display.print("mb");
 
  display.setCursor(0, 40);
  display.setTextSize(1);
  display.print("Altitude: ");
  display.print(absoluteAltitude);
  display.print("m");
  display.display();
 
  delay(2000);

}

After uploading the code, open serial monitor to check the values of Pressure, temperature, Absolute altitude and relative altitude as shown in the below serial monitor screenshot image.

MS5611 barometric pressure and altitude sensor readings on serial monitor

Also you can check on the OLED display, you an see temperature, pressure and altitude values displayed on it as shown in the below image.

ms5611-01ba03 barometric pressure and altitude sensor output values on OLED display

Code Explaination

Let’s go through the code step by step:

  1. The code includes the necessary libraries: Wire for I2C communication, Adafruit_SSD1306 for controlling the OLED display, and MS5611 for interacting with the MS5611 sensor.
  2. Some constants are defined:
    • SCREEN_WIDTH and SCREEN_HEIGHT represent the dimensions of the OLED display in pixels.
    • OLED_RESET is the reset pin for the display (-1 if sharing Arduino reset pin).
    • SCREEN_ADDRESS is the I2C address of the display.
  3. An instance of the Adafruit_SSD1306 class is created, specifying the screen width, height, communication interface (Wire), and reset pin.
  4. An instance of the MS5611 class is created to interface with the MS5611 sensor.
  5. In the setup() function:
    • Serial communication is started, and there is a check to ensure that the Serial connection is established before proceeding.
    • The MS5611 sensor is initialized. If it is not found, an error message is printed, and the program enters an infinite loop.
    • The SSD1306 OLED display is initialized. If the allocation fails, an error message is displayed, and the program enters an infinite loop.
    • The display is cleared, and a brief delay is added for stability.
    • The checkSettings() function is called to print the oversampling settings of the MS5611 sensor.
    • A delay of 2 seconds is added before entering the main loop.
  6. The checkSettings() function is a helper function that prints the oversampling settings of the MS5611 sensor.
  7. In the loop() function:
    • The variable myRealAltitude is set to represent the actual altitude at your location. You can modify this value based on your specific location.
    • The readPressure() function is called to read the raw pressure value from the MS5611 sensor, and it is converted from Pascals to millibars (mb).
    • The readTemperature() function is called to read the temperature from the sensor.
    • The getAltitude() function is used to calculate the absolute and relative altitude based on the pressure readings and the real altitude value.
    • The temperature, pressure, absolute altitude, and relative altitude are printed to the serial monitor.
    • The OLED display is updated with the temperature, pressure, and altitude values.
    • A delay of 2 seconds is added to control the refresh rate.

Be Part of Our Creative Journey: Subscribe to Circuit Schools YouTube Channel for Inspiring Projects! Join the Discussion in the Comment Section below if you have any doubts or questions!

CircuitSchools Staff

We at CircuitSchools publish on basics of electronics and electric components and everything related to evolution of electrical technology with complete analysis of development boards and modules along with latest projects with innovative ideas.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button