Arduino Mega - MS5611 Pressure Sensor
A thermometer knows only the weather of this moment. The air pressure often changes before the weather does, so a barometer is a very good first part for a home weather station. This tutorial instructs you how to use the Arduino Mega 2560 with the MS5611 pressure sensor, a small module that shops also sell under the name GY-63. The Mega becomes the base of the station, and the Serial Monitor is its first display. In detail, we will learn:
- How the MS5611 feels the air, and which four of its seven pins the Arduino Mega needs
- How to connect the module to the I2C pins 20 and 21
- How to program the Arduino Mega for a first reading, to see that the sensor works
- How to print a station report with four pressure units, the altitude in m and ft, and the temperature in °C and °F
- Who uses which pressure unit, and why the station shows another number than the weather website

We suggest:
- Utilizing a DHT22 sensor if you only need the temperature and the humidity of a room. The MS5611 measures the temperature of its own chip.
- Utilizing an SCD40 CO2 sensor if you want to know how fresh the air in the room is. The MS5611 tells you how hard the air presses, not what is in it.
Hardware Preparation
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 and Its Pinout

Look for the small metal can on the blue board. This is the sensor itself, the MS5611-01BA03 from TE Connectivity. Under its lid there is a thin membrane of silicon, similar to the skin of a tiny drum. The air pushes on this skin, and it bends by a very small amount. A 24-bit converter in the same chip measures this bend, and the Mega calculates the pressure from the result. On a hill, less air is above us, so the push is weaker: close to sea level, every meter up takes away about 0.12 hPa. That is why one sensor can work as a barometer and as an altimeter.
| DIYables GY-63 MS5611 Module | |
|---|---|
| Measures | air pressure, and the temperature of its own chip |
| Working range | 10 to 1200 hPa (full accuracy between 450 and 1100 hPa) |
| Accuracy of the pressure | ±1.5 hPa at 25°C, in the range 700 to 1100 hPa |
| Smallest step | 0.012 hPa, which is a height of about 10 cm |
| Temperature | -40°C to 85°C, accuracy ±0.8°C at 25°C |
| Time for one pressure value | about 9 ms at the finest setting |
| Connection | I2C (up to 400 kHz) as delivered, SPI is possible |
| I2C address | 0x77, can be changed to 0x76 |
| Power on VCC | 3.3V to 5V, the board has its own 3.3V regulator |
| Size | 19 x 13 mm, roughly |
Four pins get a wire:
- VCC pin: must be connected to the 5V pin of the Arduino Mega.
- GND pin: must be connected to GND (0V).
- SCL pin: the I2C clock. It must be connected to pin 21 (SCL) of the Arduino Mega.
- SDA pin: the I2C data. It must be connected to pin 20 (SDA) of the Arduino Mega.
Three pins can be disregarded in this tutorial:
- CSB pin: makes the choice between the two I2C addresses. Empty, or wired to GND, it gives 0x77 (the module has a pull-down resistor here). Wired to 3.3V, it gives 0x76. SPI users need it as chip select.
- SDO pin: the data output for SPI. It has no job in I2C.
- PS pin: makes the choice between I2C and SPI. The module pulls it HIGH for I2C, so we leave it alone. Wired to GND, it would switch to SPI.
※ NOTE THAT:
The pins are not all equal. SCL and SDA go through a level shifter and already have pull-up resistors on the module, so the 5V signals of the Mega are fine and no extra part is needed. CSB and PS go straight to the chip, and the chip runs at 3.3V. A HIGH for these two must come from the 3.3V pin of the Mega, never from 5V.
Wiring Diagram
The module is wired to the I2C pins of the Mega, which are in the COMMUNICATION corner of the board: pin 20 (SDA) and pin 21 (SCL). The drawing takes the GND pin beside pin 13, but every GND pin of the Mega is fine.

This image is created using Fritzing. Click to enlarge image
| MS5611 Module | Arduino Mega |
|---|---|
| VCC | 5V |
| GND | GND |
| SCL | 21 (SCL) |
| SDA | 20 (SDA) |
| CSB, SDO, PS | not connected |
Are pins 20 and 21 hard to reach? The Mega also has SDA and SCL holes next to the AREF pin. These two holes carry the same two signals, so use the pair that you like better. But do not use A4 and A5: on the Mega they are normal analog inputs, not I2C pins.
Indoors or Outdoors?
The air pressure in a house is practically the same as outside, because the air finds its way through small gaps. So this part of the weather station does not need a place in the rain. It can stay next to the Mega on a shelf, with short wires, if you follow these rules:
- Choose a place in the shade, away from the window and from any fan. Sun and moving air make the value jump. Some open foam over the metal can calms the air.
- Never cover the two small holes of the can with tape or glue, and never let water get in.
- Think of it as a sensor for the air around you. It cannot measure water pressure or the pressure in a tire.
How To Program For MS5611 Pressure Sensor
- The first step is to include two libraries. Wire.h belongs to the Arduino IDE and runs the I2C bus, MS5611.h knows the sensor:
- A sensor object is declared. The number is its I2C address, so change it to 0x76 if your CSB pin is wired to 3.3V:
- In setup(), start the bus and the sensor, in this order. begin() returns false if nothing answers at the address, or if the calibration data of the chip is empty:
- Give the sensor the time for a fine measurement. The noise is then 0.012 hPa. Without this line, it is 0.065 hPa:
- The altitude needs one number that the sensor cannot know, the present pressure at sea level in your area. Write it at the top of the sketch:
- In loop(), take one measurement with read(). All values after that come from this one measurement, so you can ask for as many units as you like. The library has no mmHg, inHg and °F, but one multiplication is enough for each:
Arduino Mega Code for MS5611 Pressure Sensor
Before we build the report, we check the sensor with a short sketch. It prints one line per second: the pressure in hPa and the temperature of the chip.
Detailed Instructions
- If the Arduino IDE is not on your computer yet, download it from the Arduino website and install it. The Mega is already in its board list.
- Wire the components as shown in the diagram.
- Connect the Arduino Mega board to your computer using a USB cable.
- Open the Arduino IDE, select the Arduino Mega or Mega 2560 board and the correct COM port.
- Click the Libraries icon on the left side of the Arduino IDE.
- Type MS5611 in the search box, then find the MS5611 library by Rob Tillaart. Names with something more, such as MS5611_SPI, are different libraries.
- Click the Install button.
- 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 to upload the code to the Arduino Mega.
- Open the Serial Monitor and set the baud rate to 9600.
- Leave the board and the module on the table for some lines. Then put both on the floor, without pulling on the wires:
The last three lines were printed on the floor, 75 cm lower. A little more air is above the sensor there, and the pressure goes up by about 0.09 hPa. If you see this small step, your sensor works well.
Do not worry if your own number is far from 1013 hPa. Our test house is 432 m above the sea, so 970 hPa is normal there.
Arduino Mega Code for a Weather Station Report
Now the Serial Monitor becomes the display of a real station. Every 5 seconds, the Mega prints a block with the pressure in hPa, Pa, mmHg and inHg, the altitude in meters and feet, and the temperature in °C and °F.
Who Uses Which Pressure Unit?
All four numbers describe the same air. Which one looks familiar depends on where you live and on your job:
| Unit | Who uses it | Standard pressure at sea level | 1 hPa is |
|---|---|---|---|
| hPa (the same number as mbar) | weather reports in most countries, airports in most countries | 1013.25 | 1 |
| Pa | science, the SI unit of pressure | 101325 | 100 |
| mmHg | medicine (blood pressure), weather reports in Eastern Europe | 760.0 | 0.750 |
| inHg | weather reports and aviation in the USA | 29.92 | 0.0295 |
It is the same with the height. Pilots in most countries speak of feet, while a hiking map in Europe uses meters.
The Complete Report Sketch
The sketch does not wait with a long delay(). It compares millis() with the time of the last report. Between two reports, the Mega is free, and you can add the code of more sensors at the end of loop().
Detailed Instructions
- Open the website of your weather service, or the report of the nearest airport, and look for the pressure at sea level. Airports call it QNH.
- Put the number into this line. Our weather website showed 1021.4 hPa:
- Does your website use inHg? Multiply by 33.864 to get hPa. For mmHg, multiply by 1.3332.
- Upload the second sketch to the Arduino Mega. The wiring and the library stay the same.
- Keep the Serial Monitor at 9600 baud. The first report comes after 5 seconds:
The map says 432 m for this house, and the report says 432.8 m. That is very close. With the default value 1013.25, the same air pressure gives 365.9 m, which is 66 m too low. So the sea-level pressure is worth the short visit to the website: 1 hPa of error moves the altitude by about 8.2 m.
We let the station run. About three hours later, it printed this block:
Of course, the house did not climb 28 m. The weather changed: the pressure fell by 3.2 hPa, but the sketch still used the sea-level value of the morning. Read such a block in this way:
- The house does not move, so a change in the altitude line is really a change of the weather.
- Falling pressure often brings clouds, wind or rain. A fall of 3 hPa or more within 3 hours, like here, is a sign of a strong weather change.
- Pressure that rises steadily, or stays high, often means fair weather.
These rules are only a rule of thumb, not a forecast.
Let the Station Grow
The Arduino Mega has 54 digital pins and 16 analog inputs, and the MS5611 takes only two of them. Good next parts, with the pins that their tutorials use:
- DHT22 on pin 2: the humidity, and the real temperature of the air.
- Rain sensor on pin 3 and A0: tells you when the first drops fall.
- UV sensor on A0: the strength of the sun. If the rain sensor is on A0 already, take A1 and change the pin in the code.
- LCD 20x4 on pins 20 and 21: a display without the PC. It shares the I2C wires with the MS5611, because its address (0x27 or 0x3F) is a different one.
- Micro SD card on pins 50 to 53: a file with all the reports.
One more hint for a wind meter that gives pulses: pins 20 and 21 can normally be interrupt pins, but not while I2C uses them. Take pin 18 or 19.
Troubleshooting
| What you see | Where to look |
|---|---|
| "No MS5611 at this I2C address" | SDA must be on 20 and SCL on 21. Often the two are swapped, or a wire sits on A4 / A5. If CSB is wired to 3.3V, the code needs 0x76 |
| The numbers are nonsense | Another chip has the same address, for example a BMP280, BME280 or BMP180. Read the print on your module |
| The pressure is about 500 hPa | Your module carries a MS5607 chip. Add ms5611.reset(1); after the begin() block |
| The altitude is wrong by 10 m or more | SEA_LEVEL_PRESSURE is old. Look up the present value again |
| The last digits jump around | Moving air from a window, a fan or a door. Put open foam on the metal can |
| The temperature is 1 to 3°C too high | This is normal. The board warms the chip a little |
Additional Knowledge
Station Pressure and Sea-Level Pressure
Weather stations in a shop often show two pressure values, ABS and REL. ABS (absolute) is the pressure at the place of the sensor. This is what our report shows. REL (relative) is the pressure that you would have at sea level. Weather websites and weather maps show this one, so that towns in the mountains and towns at the sea can be compared.
If you know the height of your home from a map, the library can also calculate the REL value. Add these lines to the printReport() function, with your own height in place of 432.0:
For Report 1, this gives 1021.3 hPa, only 0.1 hPa away from the website. For Report 2161 it gives 1017.9 hPa. This line does not need SEA_LEVEL_PRESSURE at all.
How Many Digits Are Useful?
The report prints one digit after the point for hPa and mmHg, two for inHg, and none for Pa. More digits would look exact, but the accuracy of the sensor is ±1.5 hPa. Small steps are still real: if the value moves by 0.1 hPa, the air pressure has really changed, also when the total is off by 1 hPa. This is why a weather station is so good at showing a trend.
MS5611 and DHT22 in One Station
| MS5611 | DHT22 | |
|---|---|---|
| Air pressure | yes | no |
| Altitude | yes | no |
| Humidity | no | yes |
| Temperature | of the chip, used to correct the pressure | of the air |
| Connection to the Mega | I2C, pins 20 and 21 | one digital pin |
| Best place in the station | indoors, next to the Mega | outdoors, in the shade and dry |
It is evident that the two sensors do different jobs. The MS5611 is the more precise tool for changes of the weather and of the height, the DHT22 is the right one for warm, cold, humid or dry. A complete weather station has both.