Arduino MKR WiFi 1010 - MS5611 Pressure Sensor
You switch on a new pressure sensor, and the Serial Monitor shows 978 hPa. Then you open a weather website, and it gives 1018 hPa for your town. A gap of 40 hPa looks like a broken sensor, but nothing is broken. The sensor measures the air in your room, and the weather report gives the pressure at sea level. Arduino MKR WiFi 1010 can turn the first number into the second one. All it has to know is how high your home is. In this tutorial, we are going to learn:
- What the MS5611 sensor measures, and which of its seven pins we need
- How to connect the GY-63 module to pins 12 and 11 of Arduino MKR WiFi 1010, with 3.3V on VCC
- How to program Arduino MKR WiFi 1010 to print the air pressure and the chip temperature
- What the words "station pressure" and "sea-level pressure" mean
- How to program Arduino MKR WiFi 1010 to print the same kind of number as the weather report

Hardware Preparation
| 1 | × | Arduino MKR WiFi 1010 | |
| 1 | × | Micro USB Cable | |
| 1 | × | MS5611 Pressure Sensor Module | |
| 1 | × | Jumper Wires |
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of MS5611 Pressure Sensor
The MS5611-01BA03 is an air pressure chip from TE Connectivity. DIYables puts it on a blue board called GY-63, together with a voltage regulator and a row of seven pins. You may also find this kind of module under the names barometer, altimeter or altitude sensor, because air pressure can tell us about the weather and about the height.
On the board you see a small metal can with two holes. Outside air comes in through the holes and presses on a thin silicon membrane, so the membrane bends by a tiny amount. The chip changes this bend into a 24-bit number, and from this number the library calculates the pressure in hPa (hectopascal). Some weather pages write mbar instead. The number is the same.
| MS5611 Module (GY-63) | |
|---|---|
| Power for the Module | 3.3V to 5V (on this page 3.3V) |
| Interface | I2C (default, up to 400 kHz), SPI also possible |
| I2C Address | 0x77 (default), or 0x76 |
| Measures Pressure | from 10 to 1200 hPa, full accuracy from 450 to 1100 hPa |
| Pressure Accuracy | ±1.5 hPa (25°C, 700 to 1100 hPa) |
| Pressure Resolution | 0.012 hPa, or about 10 cm of height |
| Temperature | from -40°C to 85°C, accuracy ±0.8°C at 25°C |
| Time for One Pressure Value | about 9 ms at the best resolution |
| Size | about 19 x 13 mm |
Pinout

Pins with a wire:
- VCC pin: needs to be connected to the MKR pin named VCC, which gives 3.3V
- GND pin: needs to be connected to GND (0V)
- SCL pin: the clock signal of I2C, needs to be connected to pin 12 (SCL)
- SDA pin: the data signal of I2C, needs to be connected to pin 11 (SDA)
Pins without a wire:
- CSB pin: decides the I2C address. A resistor on the module pulls it down, and this gives 0x77. With 3.3V on CSB, the address is 0x76, so two modules can work on the same two I2C pins. (In SPI mode, CSB is the chip select.)
- SDO pin: the data output for SPI. I2C has no use for it.
- PS pin: decides between I2C and SPI. A resistor on the module keeps it HIGH, which means I2C. GND on this pin means SPI.
Wiring Diagram
All four wires start at one header of the MKR, the one that begins with 5V at the USB end. Count the holes from there: the third is VCC, the fourth is GND, the eighth is pin 12 (SCL) and the ninth is pin 11 (SDA). The tags in the picture call them 3V3, GND, D12 and D11.

This image is created using Fritzing. Click to enlarge image
| MS5611 Module Pin | Arduino MKR WiFi 1010 Pin |
|---|---|
| VCC | VCC (3.3V) |
| GND | GND |
| SCL | 12 (SCL) |
| SDA | 11 (SDA) |
| CSB, SDO, PS | no wire |
※ NOTE THAT:
Never use the 5V pin of the MKR here. The module itself accepts 5V, but its pull-up resistors and its level shifter follow VCC. With 5V on VCC, the pins 12 and 11 would be pulled up to 5V, and the pins of the MKR are only made for 3.3V. Also, CSB and PS must never get 5V.
Three more things about the wiring:
- No extra resistors are needed. The pull-ups for SCL and SDA are on the module.
- The MKR has two chips of its own on the same I2C bus. An I2C scanner shows them as 0x60 (crypto chip) and 0x6B (battery charger). They do not disturb the MS5611 at 0x77.
- Put the module where the air is calm, and not in direct sunlight. Wind and sun both change the reading. You may cover the metal can with a small piece of open foam, but do not block the two holes, and do not let them get wet. The sensor is for air only, not for water and not for tires.
How To Program For MS5611
- Include the sensor library and the I2C library of the board: #include <MS5611.h> and #include <Wire.h>.
- Declare an object with the address of the module: MS5611 ms5611(0x77);. Only if CSB has 3.3V, it is MS5611 ms5611(0x76);.
- Let the Serial Monitor connect first: while (!Serial && millis() < 3000); comes after Serial.begin(9600);, because the MKR has native USB.
- Initialize I2C and the sensor in setup(): first Wire.begin(), then ms5611.begin(). The result of the second one is false if no chip is there.
- Ask for the best resolution: ms5611.setOversampling(OSR_ULTRA_HIGH);. The library alone would use the fastest and roughest setting.
- Read the sensor in loop(): ms5611.read(). One reading takes about 20 ms, and MS5611_READ_OK means that it worked.
- Get the values of this reading: ms5611.getPressure() in hPa and ms5611.getTemperature() in °C. The sketch calculates °F with celsius * 1.8 + 32.
- Get the pressure at sea level: ms5611.getSeaLevelPressure(stationPressure, MY_ALTITUDE). It takes the measured pressure in hPa and the altitude of the sensor in meters. We need it in the second sketch.
Arduino Code - Read the MS5611 Every Second
The first sketch prints what the sensor really measures, without any correction: the air pressure in your room and the temperature of the chip.
Detailed Instructions
- Connect Arduino MKR WiFi 1010 to PC via Micro USB cable.
- Connect the four wires as in the wiring diagram, and check that the red one is on VCC and not on 5V.
- Navigate to the Arduino IDE, then select the Arduino MKR WiFi 1010 board and its port. If the board is new for you, do the Getting Started with Arduino MKR WiFi 1010 tutorial first.
- Click the Libraries icon, search "MS5611", and click Install at the library by Rob Tillaart with exactly this name (not MS5611_SPI or MS5xxx). There is nothing else to install.
- Search for MS5611 created by Rob Tillaart
and click the Install button.
- Copy the above code and paste it into the Arduino IDE.
- Click the Upload button.

- Open the Serial Monitor, choose 9600 baud, and let the module lie still.
The last digit of the pressure moves a little, and this is normal. Is your number between 1000 and 1030? Then your home is not far above the sea. Is it 950, 900 or even less? Then you live higher up. Write your number down, we need it soon.
The temperature goes up slowly in the first minutes, because the board warms the chip. It can end 1 to 3°C above the room. The chip needs this temperature to correct the pressure. To measure the air of the room, take a DHT22 sensor or a DS18B20 sensor.
Why the Weather Report Shows Another Number
There are two kinds of air pressure, and both are written in hPa:
- Station pressure is the real pressure at the place of the sensor. The MS5611 gives you this one.
- Sea-level pressure is the pressure the same place would have now if it were at the height of the sea. Weather maps and weather websites show this one. In airport reports, its name is QNH.
The reason for the second kind is the height. The higher a place is, the less air is above it, and the lower its pressure. Near the sea, it is about 0.12 hPa less for each meter up. So a village on a hill always has a lower station pressure than a harbor, in good weather and in bad weather. A weather map made of station pressures would only show where the hills are. The sea-level pressure removes the effect of the hill, so we can compare the weather of two places.
Let us take a standard day, when the sea-level pressure is 1013.25 hPa everywhere. A sensor then shows:
| Altitude of the Place | Station Pressure on the Sensor | Gap to the Weather Report |
|---|---|---|
| 0 m | 1013.25 hPa | 0 hPa |
| 100 m | 1001.29 hPa | 11.96 hPa |
| 300 m | 977.71 hPa | 35.54 hPa |
| 500 m | 954.58 hPa | 58.67 hPa |
| 1000 m | 898.70 hPa | 114.55 hPa |
| 1500 m | 845.50 hPa | 167.75 hPa |
See the line with 300 m: almost 978 hPa, without any storm. The last column also shows that we cannot simply add 0.12 hPa for every meter. The first 100 m take away 11.96 hPa, but from 1000 m to 1500 m it is only 53.20 hPa, less than 11 hPa per 100 m. So the library uses this formula:
sea-level pressure = station pressure / (1 - altitude / 44307.7) ^ 5.2553
Here it is with our own numbers, 978.10 hPa at an altitude of 333 m:
- 333 / 44307.7 = 0.007516
- 1 - 0.007516 = 0.992484
- 0.992484 ^ 5.2553 = 0.96113
- 978.10 / 0.96113 = 1017.7 hPa
The weather website said 1018 hPa, so the gap of 40 hPa is gone.
Arduino Code - Sea-Level Pressure Like in the Weather Report
Now the MKR does this calculation. Every 2 seconds, the sketch prints the station pressure and, next to it, the sea-level pressure. Only one line has to be changed for your home, the line with MY_ALTITUDE.
Detailed Instructions
- Find your home on a map that shows the altitude (elevation) in meters. Many online maps and phone apps can do it. It tells you how high the ground is.
- If you live on an upper floor, you are higher than the ground. In our example, the street is at 326 m and the sensor is 7 m above the street, so the altitude is 333 m.
- Does your map use feet? Multiply by 0.3048 to get meters.
- Keep the wires as they are. Copy the above code, paste it into the Arduino IDE, and write your altitude behind MY_ALTITUDE.
- Click the Upload button.
- Open the Serial Monitor at 9600 baud, and open the weather website in your browser at the same time.
The left number is your own air, the right number can be compared with the report. Reports in the USA use inHg (inches of mercury). To get inHg, divide the hPa value by 33.864: 1017.7 hPa is 30.05 inHg.
How Much Does a Wrong Altitude Change?
We keep the same reading (978.10 hPa) and change only the number behind MY_ALTITUDE:
| MY_ALTITUDE | What Happened | Result |
|---|---|---|
| 333.0 | the right altitude | 1017.66 hPa |
| 334.0 | 1 m too high | 1017.78 hPa |
| 323.0 | 10 m too low | 1016.44 hPa |
| 343.0 | 10 m too high | 1018.87 hPa |
| 0.0 | the altitude was forgotten | 978.10 hPa |
| 1092.5 | feet instead of meters | 1115.23 hPa |
A mistake of 1 m is only 0.12 hPa, and 10 m are 1.2 hPa. So the map does not have to be perfect. Only the last two lines are real mistakes, and you see them at once.
Still 1 or 2 hPa Away from the Report?
That is a good result. These are the usual reasons:
- The sensor may be wrong by up to 1.5 hPa. This error stays about the same from day to day.
- The report comes from a weather station that is perhaps 30 km away, and it may be an hour old.
- Many reports give a whole number. Our 1017.7 hPa and a reported 1018 hPa fit together.
- The formula uses a standard air temperature. Some weather maps use the real temperature of the day. High in the mountains, this can make a difference of several hPa, so compare with an airport report (QNH) there.
What the Number Says about the Weather
- It falls: clouds, wind or rain are likely.
- It falls by 3 hPa or more within 3 hours: a strong change of the weather.
- It rises steadily, or it stays high: fair weather.
Watch it for some hours, always at the same place. To see both numbers without a PC, connect an OLED display. It also runs at 3.3V and shares the pins 12 and 11 with the MS5611, because it has another I2C address.
Troubleshooting
- The Serial Monitor prints "No MS5611 found": see if SCL is on pin 12 and SDA is on pin 11. They are easy to mix up. Then check VCC and GND, and make sure that nothing touches the PS pin. A module with 3.3V on CSB needs 0x76 in the line with MS5611 ms5611.
- The values are nonsense from the first line on: the module may be a BMP180, BMP280 or BME280. Their I2C address can be the same, and the library does not check which chip it is. Read the name that is printed on the module.
- The station pressure is about 500 hPa: your module has an MS5607 chip, which needs other math. Add ms5611.reset(1); at the end of setup().
- The sea-level pressure is far above 1050 hPa: the altitude is too big. Very often it is the value in feet.
- The sea-level pressure is as low as the station pressure: MY_ALTITUDE is still 0, or the sketch was not uploaded again after the change.
- The numbers jump: a fan, an open window or an air conditioner moves the air. Find a calm corner, or put open foam over the can.