Table of Contents
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)
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
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 Name | Quantity | ||
---|---|---|---|
Arduino NANO | 1 | https://amzn.to/3jVNZON | https://amzn.to/3KpUQry |
MS5611-01BA03 pressure sensor | 1 | https://amzn.to/3MuTZIR | https://amzn.to/3q6q6av |
OLED Display | 1 | https://amzn.to/34f0GNi | https://amzn.to/35HZK4E |
5V power supply (USB or External). | 1 | https://amzn.to/3s1a8g3 | https://amzn.to/364yInH |
Few Connecting Wires | https://amzn.to/3H2BV4e | https://amzn.to/3J0WVu2 |
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
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 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.
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.
Code Explaination
Let’s go through the code step by step:
- The code includes the necessary libraries:
Wire
for I2C communication,Adafruit_SSD1306
for controlling the OLED display, andMS5611
for interacting with the MS5611 sensor. - Some constants are defined:
SCREEN_WIDTH
andSCREEN_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.
- An instance of the
Adafruit_SSD1306
class is created, specifying the screen width, height, communication interface (Wire
), and reset pin. - An instance of the
MS5611
class is created to interface with the MS5611 sensor. - 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.
- The
checkSettings()
function is a helper function that prints the oversampling settings of the MS5611 sensor. - 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.
- The variable
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!