Arduino Giga R1 WiFi MS5611 Pressure Sensor

Put an air pressure sensor on a table, do not touch it, and read it again and again. The last digits change all the time, although nothing in the room seems to move. This trembling is called noise, and every sensor has it. In this guide, we will learn how to use the MS5611 pressure sensor with the Arduino Giga R1 WiFi, how to see its noise as a curve in the Serial Plotter, and how to calm the curve. In detail, we will learn:

Arduino Giga R1 WiFi wired to an MS5611 GY-63 pressure sensor, with module pinout

Why are a few hundredths of a hPa important? A barometer is also an altimeter. Near sea level, the pressure falls by about 0.12 hPa for every meter up. With a noise of 0.06 hPa, the height trembles by half a meter. With 0.003 hPa, it trembles by only 2 or 3 cm. This helps in every later project with the sensor, such as a weather station or a height meter.

Hardware Preparation

1×Arduino Giga R1 WiFi
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×MS5611 Pressure Sensor Module
1×Jumper Wires
1×Recommended: Screw Terminal Block Shield for Arduino Uno/Mega/Giga
1×Recommended: Sensors/Servo Expansion Shield for Arduino Mega/Giga
1×Recommended: Breadboard Shield for Arduino Mega/Giga
1×Recommended: Enclosure for Arduino Giga
1×Recommended: Power Splitter for Arduino Giga

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

For the experiments you also need a quiet table, and a shelf or a box about 1 m above it.

Overview of MS5611 Pressure Sensor

The small metal can on the module is the sensor itself, an MS5611-01BA03 from TE Connectivity. A thin silicon membrane is inside. The air presses on it and bends it a very little, and a 24-bit converter in the chip turns the bend into a number. The higher you are, the less air is above you, so the number gets smaller.

The result is a pressure in hPa (hectopascal). 1 hPa is the same as 1 mbar, and near sea level it stands for about 8.3 m of height. The standard pressure at sea level is 1013.25 hPa.

MS5611 Module (DIYables GY-63)
Pressure resolution 0.012 hPa (about 10 cm of height)
Pressure accuracy ±1.5 hPa (25°C, 700 to 1100 hPa)
Pressure range 10 to 1200 hPa, with full accuracy from 450 to 1100 hPa
Converter 24 bit, about 9 ms for one pressure conversion at the best resolution
Temperature range and accuracy -40°C to 85°C, ±0.8°C (at 25°C)
Interface I2C up to 400 kHz (default), or SPI
I2C address 0x77 (default), or 0x76
Module supply 3.3V to 5V, with a 3.3V regulator on the board
Module size about 19 x 13 mm

Compare the first two rows: the sensor can see a change of 0.012 hPa, but the value itself may be wrong by up to 1.5 hPa. Resolution and accuracy are two different things, and we come back to this at the end.

MS5611 GY-63 pressure sensor module pinout

Four pins get a wire:

  • VCC pin: connect to 3.3V of the Arduino Giga R1 WiFi
  • GND pin: connect to GND (0V)
  • SCL pin: the I2C clock, connect to pin 21 (SCL)
  • SDA pin: the I2C data, connect to pin 20 (SDA)

Three pins stay empty:

  • CSB pin: sets the I2C address. Empty or GND means 0x77, and 3.3V means 0x76, so two modules can share one bus. With SPI, it is the chip select.
  • SDO pin: the data output for SPI, not used for I2C
  • PS pin: chooses the protocol. A resistor on the module holds it HIGH for I2C. GND would switch the module to SPI.

The pull-up resistors for SCL and SDA are already on the module, so there's no need to add them. CSB and PS belong to the 3.3V chip: if you ever connect one of them to a HIGH level, use 3.3V and never 5V.

Noise, Oversampling and Smoothing

Three words are enough for our lab:

  • Noise is a small random error that is new in each reading. One reading is a bit too high, the next one a bit too low.
  • Oversampling (OSR) fights the noise inside the chip. With a higher OSR, the converter works longer on one reading, and the reading gets better.
  • Smoothing fights the noise in the program. A new reading does not replace the old result. It only moves the result a small part of the way.

The library has five oversampling settings. The default is the first one, the one with the most noise:

Setting Name in the Library Typical Noise Seen as Height Time for One Reading
OSR 256 OSR_ULTRA_LOW 0.065 hPa 54 cm about 3 ms
OSR 512 OSR_LOW 0.042 hPa 35 cm about 4 ms
OSR 1024 OSR_STANDARD 0.027 hPa 22 cm about 6 ms
OSR 2048 OSR_HIGH 0.018 hPa 15 cm about 11 ms
OSR 4096 OSR_ULTRA_HIGH 0.012 hPa 10 cm about 20 ms

"Typical" means that about two of three readings are closer to the middle than this value.

Can we also read fast and make the average ourselves? In 20 ms there is time for six readings with OSR 256, but their average still has a noise of about 0.027 hPa. One reading with OSR 4096 has 0.012 hPa. So use OSR 256 only when speed is more important than a calm value.

Wiring Diagram

Four wires go from the module to the Giga R1 WiFi, and both I2C wires end on neighboring pins.

The wiring diagram between Arduino Giga R1 WiFi MS5611 pressure sensor

This image is created using Fritzing. Click to enlarge image

MS5611 Module Pin Arduino Giga R1 WiFi Pin
VCC 3.3V
GND GND
SCL 21 (SCL)
SDA 20 (SDA)
CSB, SDO, PS nothing

The red wire starts at the 3.3V hole of the power header, between RESET and 5V. The black wire uses the GND hole between pin 13 and AREF. Pins 20 and 21 are the last two holes at the other end of that side.

※ NOTE THAT:

  • Never connect VCC to 5V on this board. The level shifter of the module follows VCC, so with 5V the module would pull SCL and SDA up to 5V. The pins of the Giga are made for 3.3V.
  • The Giga has three I2C buses. SDA1 and SCL1 next to AREF, and pins 9 and 8 (SDA2 and SCL2), belong to the other two. The code of this guide uses the default bus, Wire, on pins 20 and 21.
  • The metal can has two small holes for the air. Do not block them and do not let them get wet. The sensor is made for air, not for water pressure or tire pressure.

How To Program For MS5611 Pressure Sensor

  • Include Wire for the I2C bus, and the library for the sensor:
#include <Wire.h> #include <MS5611.h>
  • Create one object for the sensor and give it the I2C address:
MS5611 ms5611(0x77);
  • In setup(), switch on the bus and look for the sensor. If there is no answer, or if the calibration data in the chip is empty, begin() returns false:
Wire.begin(); if (!ms5611.begin()) { Serial.println("No MS5611 on pins 20 and 21. Check the four wires"); }
  • Select OSR 4096, because the library begins with OSR 256:
ms5611.setOversampling(OSR_ULTRA_HIGH);
  • Measure, then get the two results in hPa and °C:
if (ms5611.read() == MS5611_READ_OK) { float pressure = ms5611.getPressure(); float temperature = ms5611.getTemperature(); }

The noise lab adds two things:

  • Use a one-line filter. With LEVEL = 10, the smooth value moves one tenth of the way to the raw value:
smooth += (raw - smooth) / LEVEL;
  • Print a name, a colon and a number for each curve, with a comma in between. The Serial Plotter understands this form:
Serial.print("raw:"); Serial.print(raw, 2); Serial.print(",smooth:"); Serial.println(smooth, 3);

Arduino Giga R1 WiFi Code - MS5611 Pressure Sensor

First a short test. The sketch prints the pressure and the chip temperature every second. Two digits after the point are enough to see the noise.

/* * This Arduino Giga R1 WiFi code was developed by newbiely.com * * This Arduino Giga R1 WiFi code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-giga/arduino-giga-r1-wifi-ms5611-pressure-sensor */ // Arduino Giga R1 WiFi - read the air pressure and the chip temperature from the MS5611 (GY-63) // The sensor is on the main I2C bus "Wire": SDA = pin 20, SCL = pin 21. VCC = 3.3V // Library: "MS5611" by Rob Tillaart #include <Arduino.h> #include <Wire.h> #include <MS5611.h> MS5611 ms5611(0x77); // I2C address. Write 0x76 if CSB has 3.3V void setup() { Serial.begin(9600); while (!Serial) { delay(10); // wait for the Serial Monitor, so no message gets lost } Wire.begin(); // pins 20 and 21 if (!ms5611.begin()) { Serial.println("No MS5611 on pins 20 and 21. Check the four wires"); while (true) { delay(1000); // without a sensor there is nothing to do } } ms5611.setOversampling(OSR_ULTRA_HIGH); // OSR 4096, the calm setting Serial.print("MS5611 ready at I2C address 0x"); Serial.println(ms5611.getAddress(), HEX); } void loop() { if (ms5611.read() == MS5611_READ_OK) { // measure one time Serial.print(ms5611.getPressure(), 2); // hPa, two digits after the point Serial.print(" hPa chip "); Serial.print(ms5611.getTemperature(), 2); Serial.println(" °C"); } else { Serial.println("The MS5611 does not answer"); } delay(1000); }

Detailed Instructions

Follow these instructions step by step:

  • First time with this board? Prepare the Arduino IDE with the Arduino Giga R1 WiFi getting started guide.
  • Wire the components according to the provided diagram.
  • Connect the Giga R1 WiFi and the computer with the USB Type-C cable.
  • Launch the Arduino IDE on your computer.
  • Select the appropriate Arduino Giga R1 WiFi board (e.g., Arduino Giga R1 WiFi) and COM port.
  • Open the Libraries panel on the left side and search for MS5611.
  • Several libraries come up. Find the one by Rob Tillaart that is named only MS5611 and press Install. It has no dependencies.
  • Search for MS5611 created by Rob Tillaart and click the Install button.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Giga R1
Library Manager
Type:
All
Topic:
All
MS5611 by Rob Tillaart
Experimental, GY-63, GY63, MS5607,altitude. More info
0.5.2
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
Arduino Giga R1 on COM15
1
  • Copy the sketch into the IDE and press Upload.
  • Open the Serial Monitor at 9600 baud. The sketch waits for it, so you see every line from the start.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Giga R1
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Giga R1' on 'COM15')
New Line
9600 baud
MS5611 ready at I2C address 0x77 994.35 hPa chip 24.62 °C 994.38 hPa chip 24.63 °C 994.36 hPa chip 24.65 °C 994.35 hPa chip 24.66 °C 994.37 hPa chip 24.68 °C 994.36 hPa chip 24.68 °C 994.37 hPa chip 24.70 °C 994.39 hPa chip 24.71 °C
Ln 11, Col 1
Arduino Giga R1 on COM15
2

The module lay still, but the pressure moved between 994.35 and 994.39 hPa. Near sea level, these 0.04 hPa are the same as about 33 cm of height. A third digit would not help, because the library counts in whole pascals (0.01 hPa).

The second number is the temperature of the chip itself, and it is used to correct the pressure. It goes up a little after power-on, because the board warms the chip. 1 to 3°C above the room is normal. For the real room temperature, take a DS18B20 as in the Arduino Giga R1 WiFi - Temperature Sensor guide.

Arduino Giga R1 WiFi Code - Noise Lab with the Serial Plotter

Now we draw the noise. This sketch works as follows:

  1. It starts with OSR 4096, and the first reading is the start of the smooth value.
  2. Ten times per second, it reads the raw pressure and calculates the smooth value with the one-line filter.
  3. It prints both values in one line. The smooth value gets a third digit, because it can lie between two steps of 0.01 hPa.
  4. If you send the character 2, it changes to OSR 256 (OSR_ULTRA_LOW). The character 4 brings back OSR 4096 (OSR_ULTRA_HIGH).
/* * This Arduino Giga R1 WiFi code was developed by newbiely.com * * This Arduino Giga R1 WiFi code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-giga/arduino-giga-r1-wifi-ms5611-pressure-sensor */ // Arduino Giga R1 WiFi - noise lab: raw and smoothed MS5611 pressure in the Serial Plotter // The sensor is on the main I2C bus "Wire": SDA = pin 20, SCL = pin 21. VCC = 3.3V // Send 2 or 4 to change the oversampling while the sketch runs: 2 = OSR 256, 4 = OSR 4096 // Library: "MS5611" by Rob Tillaart #include <Arduino.h> #include <Wire.h> #include <MS5611.h> const float LEVEL = 10.0; // 1 = no smoothing, a bigger level = calmer but slower const unsigned long LINE_MS = 100; // time from one line to the next MS5611 ms5611(0x77); // I2C address. Write 0x76 if CSB has 3.3V float smooth = 0; // smoothed pressure in hPa unsigned long lastLine = 0; // when the last line was printed void setup() { Serial.begin(9600); while (!Serial) { delay(10); // wait for the Serial Plotter or the Serial Monitor } Wire.begin(); // pins 20 and 21 if (!ms5611.begin()) { Serial.println("No MS5611 on pins 20 and 21. Check the four wires"); while (true) { delay(1000); } } ms5611.setOversampling(OSR_ULTRA_HIGH); // begin with the calm setting (OSR 4096) while (ms5611.read() != MS5611_READ_OK) { Serial.println("The MS5611 does not answer"); delay(1000); } smooth = ms5611.getPressure(); // the filter starts at the first reading } void loop() { // look for a command from the computer if (Serial.available() > 0) { char command = Serial.read(); if (command == '2') { ms5611.setOversampling(OSR_ULTRA_LOW); // OSR 256: fast, but noisy } else if (command == '4') { ms5611.setOversampling(OSR_ULTRA_HIGH); // OSR 4096: slower, but calm } } if (millis() - lastLine < LINE_MS) { return; // too early for the next line } lastLine = millis(); if (ms5611.read() != MS5611_READ_OK) { Serial.println("The MS5611 does not answer"); return; } float raw = ms5611.getPressure(); smooth += (raw - smooth) / LEVEL; // move a small part of the way to the raw value // two named values in one line = two curves in the Serial Plotter Serial.print("raw:"); Serial.print(raw, 2); Serial.print(",smooth:"); Serial.println(smooth, 3); }

Detailed Instructions

  • Leave the wires as they are and upload the new sketch.
  • Click the Serial Plotter icon at the top right of the Arduino IDE, beside the Serial Monitor icon. Choose 9600 baud.
  • Two curves appear. Their names, raw and smooth, come from the sketch.
  • Put the module on the table, away from a fan, an open window and direct sunlight. Wait a minute.
  • Type 2 into the message box at the bottom of the plotter and send it. After some seconds, send 4.

The Serial Monitor shows the same data as text. One second with OSR 4096:

∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Giga R1
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Giga R1' on 'COM15')
New Line
9600 baud
raw:994.36,smooth:994.370 raw:994.38,smooth:994.371 raw:994.34,smooth:994.368 raw:994.38,smooth:994.369 raw:994.38,smooth:994.370 raw:994.36,smooth:994.369 raw:994.36,smooth:994.368 raw:994.37,smooth:994.368 raw:994.37,smooth:994.369 raw:994.36,smooth:994.368
Ln 11, Col 1
Arduino Giga R1 on COM15
2

And one second with OSR 256, after sending 2:

∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Giga R1
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Giga R1' on 'COM15')
New Line
9600 baud
raw:994.43,smooth:994.372 raw:994.33,smooth:994.368 raw:994.41,smooth:994.372 raw:994.30,smooth:994.365 raw:994.28,smooth:994.357 raw:994.35,smooth:994.356 raw:994.47,smooth:994.367 raw:994.36,smooth:994.367 raw:994.26,smooth:994.356 raw:994.38,smooth:994.358
Ln 11, Col 1
Arduino Giga R1 on COM15
2

The difference between the highest and the lowest number of each column is:

Raw Moves by Smooth Moves by
OSR 4096 0.04 hPa (33 cm) 0.003 hPa (2.5 cm)
OSR 256 0.21 hPa (174 cm) 0.016 hPa (13 cm)

The average of the raw values is almost the same in both samples: 994.366 and 994.357 hPa. So a low OSR does not move the pressure up or down. It only adds more noise.

※ NOTE THAT:

Read the numbers on the left axis, not only the shape of the curve. The plotter always stretches the curves until they fill the window. So after a while, the noise of OSR 4096 looks as tall as the noise of OSR 256. In the first seconds after you send 2 or 4, both are in the same window, and you can compare them directly.

Three More Experiments

  • Lift it: send 4, then move the module from the table to the shelf, about 1 m up. The raw curve falls by about 0.12 hPa and stays there. The smooth curve needs about 2 seconds to follow. Put the module back, and both curves rise again.
  • Hide the step: send 2 and lift the module again. Now the step is only about twice the typical noise, and it is hard to see in the raw curve. In the smooth curve, you can still find it.
  • Make wind: wave a notebook over the module. The raw curve jumps. This is not noise of the sensor, because the pressure at the can really changes. A higher OSR does not help here, but a piece of open foam over the can does.

How Much Smoothing Is Right?

More smoothing makes the curve calmer, but also slower. The table counts from a sudden step of the pressure until the smooth value has made 90% of the step:

LEVEL Noise Gets Smaller Readings to Follow a Step Time at 10 Readings per Second
1 not at all 1 at once
5 3 times 11 1.1 s
10 4.4 times 22 2.2 s
20 6.2 times 45 4.5 s
50 10 times 114 11.4 s

These values are calculated for pure random noise. In a real room the air is never quite still, so your curve can be a little rougher. Try level 5 or 10 for a moving project, and 20 to 50 for a weather display.

The level counts readings, not seconds. If you read more often, the same level follows faster.

The Same Filter at Full Speed

The lab makes a pause between two lines, so the curve is easy to follow. In your own project, keep the filter line and let loop() read without any pause:

if (ms5611.read() == MS5611_READ_OK) { // in loop(), without any delay smooth += (ms5611.getPressure() - smooth) / LEVEL; }

read() waits for the sensor and returns after about 20 ms. This gives about 50 readings per second with OSR 4096, and level 10 then follows a step in less than half a second. The filter line also works with the altitude or the temperature in place of the pressure.

What Smoothing Cannot Repair

  • Accuracy: if the sensor shows 1 hPa too much, the smooth curve also shows 1 hPa too much. It is calm, but it is not more correct.
  • Weather: the air pressure itself changes during the day. A curve that moves slowly up or down for an hour is a real signal. A fast fall of 3 hPa or more in 3 hours means a strong weather change.
  • Altitude above sea level: it needs the present sea-level pressure of your area (QNH) from a weather website. Write it between the brackets after each reading:
float altitude = ms5611.getAltitude(1018.2); // hPa, the value of today Serial.println(altitude, 1); // in meters

For the 994.37 hPa of our table, this gives 199.2 m. With the standard value of 1013.25 hPa, it would be 158.3 m. So the noise is an error of about 10 cm, but the wrong sea-level pressure is an error of 41 m here. To measure a change of height, wait some seconds, save the smooth pressure (zeroPressure = smooth;), and then use ms5611.getAltitude(zeroPressure). Then you need no sea-level pressure. With the filter line for this height too, the result is good to about 10 to 20 cm, but only for a short time, because the weather also changes the pressure.

Troubleshooting

  • "No MS5611 on pins 20 and 21": check VCC on 3.3V and GND first. Then check that SCL is on 21 and SDA on 20, and not on SDA1 and SCL1. PS must be empty. Is there 3.3V on CSB? Then write 0x76 in the line MS5611 ms5611(0x77);.
  • The pressure and the temperature cannot be true: perhaps a BMP280, BME280 or BMP180 uses the same address, and the library cannot notice it. Look at the print on your module.
  • The pressure is about 500 hPa: your module has an MS5607 chip. Add ms5611.reset(1); between ms5611.begin() and setOversampling().
  • The plotter stays empty: open the Serial Monitor to see if an error message is there. Also check the COM port and 9600 baud.

What comes next? Connect a knob from the Arduino Giga R1 WiFi - Potentiometer guide and use its value for LEVEL (as a variable, not a const). Or show the smooth pressure on the Arduino Giga R1 WiFi - OLED Display, where a value without trembling digits is much easier to read.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!