Arduino MicroPython MS5611 Pressure Sensor
Many mountain huts have a wooden sign beside the door, with the name of the hut and its altitude, for example 1560 m. Somebody painted this number a long time ago. In this project, the hut measures the number itself. An MS5611 pressure sensor feels the air, an Arduino Giga R1 WiFi runs a short MicroPython script, and every two seconds a new line shows the altitude in meters and in feet. No hut near you? The same script works on your desk, too. These are the steps:
- Look at the small blue MS5611 board (its other name is GY-63) and find the four pins that get a wire.
- Connect them to 3.3V, GND, D8 and D9 of the Giga.
- Save one driver file on the Giga with Thonny, and look at the first readings.
- Let the script calculate the altitude, and make the number calm with smoothing.
- Put in the sea-level pressure of the day, and find out how exact the altitude can be.

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 Pinout
People who watch the weather call it a barometer, hikers call it an altimeter, and shops often write GY-63 or altitude sensor. It is the same small blue board. The part that measures is the silver can on it, the MS5611-01BA03 from TE Connectivity. A 3.3V regulator, a level shifter and some resistors are on the board as well, so you only need wires.
A membrane of thin silicon is hidden in the can. The pressure of the air bends it, but only a tiny bit, and the chip measures this with 24 bits. The driver turns the result into hPa (hectopascal). 1 hPa is the same as 1 mbar. And why does this tell the altitude? When you walk up a mountain, some of the air stays below you. There is less air above the sensor, and the pressure drops. Near the sea, it drops by about 0.12 hPa for every meter.

Of the seven pins in the row, the altimeter needs the first four:
- VCC pin: gets its power from the 3.3V pin of the Giga. (Alone, the module would also run on 5V.)
- GND pin: goes to a GND pin, 0V.
- SCL pin: I2C clock, goes to D8.
- SDA pin: I2C data, goes to D9.
The other three stay empty:
- CSB pin: the address switch for I2C. Empty or on GND, the module answers at 0x77. On 3.3V, it answers at 0x76. SPI uses this pin as chip select.
- SDO pin: an output that only SPI uses.
- PS pin: the switch between I2C and SPI. The module pulls it HIGH by itself and works with I2C. On GND, it works with SPI.
For CSB and PS, HIGH always means 3.3V. Never put 5V on them, because they are pins of the 3.3V chip.
| What | Value |
|---|---|
| Board | about 19 x 13 mm, seven pins |
| Power for the module | 3.3V to 5V |
| Bus | I2C with up to 400 kHz, or SPI |
| I2C address | 0x77, changed to 0x76 by CSB |
| Pressure | 10 to 1200 hPa (450 to 1100 hPa with full accuracy) |
| Accuracy of the pressure | ±1.5 hPa at 25°C, between 700 and 1100 hPa |
| Finest pressure step | 0.012 hPa, which is around 10 cm of height |
| Temperature | -40°C to 85°C, accuracy ±0.8°C at 25°C |
| Converter | 24 bit, about 9 ms for a pressure value in the finest mode |
The sensor gives a temperature, too. It belongs to the chip and is used to correct the pressure. Because the board makes a little heat, it can read 1°C to 3°C more than a thermometer in the room. If the hut also needs a room thermometer, add the sensor from Arduino MicroPython DHT22 Temperature Humidity Sensor.
The Air Pressure on a Mountain Walk
This is a walk on a "standard day", when the pressure at the sea is 1013.25 hPa:
| Stop | Altitude | Air pressure | 1 hPa less means |
|---|---|---|---|
| Beach | 0 m (0 ft) | 1013.3 hPa | 8.3 m up |
| Valley station | 640 m (2100 ft) | 938.7 hPa | 8.9 m up |
| Forest inn | 1120 m (3675 ft) | 885.8 hPa | 9.3 m up |
| Our hut | 1560 m (5118 ft) | 839.4 hPa | 9.7 m up |
| Pass | 1985 m (6512 ft) | 796.5 hPa | 10.1 m up |
| Summit | 2430 m (7972 ft) | 753.5 hPa | 10.6 m up |
Look at the last column. The air gets thinner, so you have to climb a little more for the same 1 hPa.
Wiring Diagram
Four jumper wires join the two boards. The red wire comes from the power header of the Giga. The other three start on the opposite side of the board, in the header with the pins D8 to D13.

This image is created using Fritzing. Click to enlarge image
| MS5611 Module | Arduino Giga R1 WiFi |
|---|---|
| VCC | 3.3V |
| GND | GND (next to pin 13) |
| SCL | D8 |
| SDA | D9 |
| CSB, SDO, PS | no wire |
※ NOTE THAT:
- Use 3.3V for VCC, not 5V. The level shifter lifts SCL and SDA to the voltage of VCC, and the pins of the Giga are made for 3.3V only. 5V is the next hole on the power header, so check the red wire again before you plug in the USB cable.
- Pull-up resistors for SCL and SDA are already on the module. Do not add any.
- In the drawing, D8 and D9 also have the names SCL2 and SDA2. In MicroPython, these two pins are I2C(1). The pins named SDA1 and SCL1, or SDA 20 and SCL 21, belong to other I2C buses, and the scripts of this page do not look there.
Choose a place on an inside wall of the hut, far from the stove, the window and the sun. Some open foam in front of the can keeps moving air away. Do not close its two small holes, and keep them dry. Please do not use the module for water or for tires, it is only made for air.
How To Program MS5611 With MicroPython
A driver file with the name DIYables_MicroPython_MS5611.py talks to the chip and does all the calculations. You find its code in the next section. These are the parts you need:
- Open the I2C bus and create the sensor. No address is needed here, because the driver tries 0x77 and 0x76 by itself:
- Take a measurement. read() gives back two numbers, °C first and hPa second. It also stores them in sensor.temperature and sensor.pressure:
- The last reading is also there in other units:
- Ask for the altitude. The number in the brackets is the pressure at sea level at this moment, in hPa:
- Make the pressure calm. At level 20, the stored pressure goes only 1/20 of the way to a new reading each time:
Behind altitude() is this formula:
The MS5611 Driver for Arduino MicroPython
Copy this code once to the Giga. It stays there next to your scripts, and both scripts of this page import it. No line of it depends on your hut.
Arduino MicroPython Code - MS5611 Pressure and Temperature
Start with the small script. It prints the address of the sensor once, and then a line per second: the air in hPa and mmHg, and the chip in °C and °F.
Detailed Instructions
All the work is done in Thonny IDE:
- If this is your first MicroPython script for the Giga, begin with Getting Started with Arduino and MicroPython. There you install Thonny and the firmware.
- Connect the four wires while the Giga has no power. Then use the USB Type-C cable to connect it to the computer.
- Open Tools Options in Thonny. The Interpreter tab must show MicroPython (generic) and the COM port of your Giga (e.g., COM33 on Windows or /dev/ttyACM0 on Linux).
- Paste the driver into an empty editor tab. Save it with Ctrl+S on the MicroPython device, and call it DIYables_MicroPython_MS5611.py. A different name, or one wrong letter, and the import fails.
- Paste the first script into another empty editor tab. Save it with Ctrl+S on the MicroPython device under the name main.py.
- Run it with F5 or with the green Run button, and watch the Shell.
- After three lines, put the module into a small plastic bag with some air in it. Hold the bag closed around the wires with one hand, and press it softly with the other hand.
These lines come from the hut at 1560 m. Near the sea, you see around 1000 hPa. The three higher values are the hand on the bag: less room for the same air means more pressure. When the bag is open again, the old value comes back.
Arduino MicroPython Code - Altitude of the Hut
The second script has only one job, the altitude. The first constant, SEA_LEVEL_PRESSURE, is the one you change. It starts with the standard value 1013.25.
There is no time.sleep(2), because the smoothing works with many readings. The loop reads without a break, more than 80 times between two lines, and only the print() waits for its two seconds. The noise of single readings is gone, and a move to a higher place still shows up in the next line.
Detailed Instructions
- Look up the sea-level pressure of your area. Weather websites show it, and airport reports call it QNH. A value in inHg becomes hPa when you multiply it by 33.864.
- Type this number into SEA_LEVEL_PRESSURE. For the lines below, it was 1021.4.
- Stop the first script. Then store the second one on the Giga under the same name, main.py. The driver is already there.
- Click Run (F5) and leave the sensor still for some lines. Then carry it to a higher place, such as the floor above.
The sign at the door says 1560 m, and the sensor says about 1555 m. In the line with 846.46 hPa, the Giga was on the way up the ladder to the beds under the roof, about 2.5 m higher. The smoothed number is calm in both places.
※ NOTE THAT:
Because the file is named main.py, the Giga starts the altimeter at every power-up, without a computer. Remember that the sea-level pressure in the file is then the one of the day you typed it.
How Exact Is the Altitude?
The sensor knows the pressure in the hut, but it cannot know the pressure at the sea. That number changes every day with the weather. Here is the same reading, 846.60 hPa, with four different values in the script:
| SEA_LEVEL_PRESSURE | Altitude in the Shell | Compared with the sign (1560 m) |
|---|---|---|
| 1005.0 | 1423.5 m (4670 ft) | 136.5 m too low |
| 1013.25 | 1490.2 m (4889 ft) | 69.8 m too low |
| 1021.4 | 1555.5 m (5103 ft) | 4.5 m too low |
| 1030.0 | 1623.7 m (5327 ft) | 63.7 m too high |
So 1 hPa more or less in this constant moves the hut by about 8 m. Three more things have an effect:
- The sensor: ±1.5 hPa means about ±14 m at the height of the hut. This part stays nearly the same from one reading to the next. That is why small height changes are much more exact, about 10 to 20 cm with smoothing.
- The time: an altitude that was right in the morning can be many meters wrong in the evening. Use a fresh value.
- The air temperature: the formula uses the air of a standard day. On a very hot or a very cold day, a place as high as our hut can be some tens of meters off.
Teach the Altimeter With the Sign
If you know the real altitude, you can turn the calculation around and let the sensor find the matching sea-level pressure. MicroPython makes this easy, because you can talk to the sensor in the Shell. Interrupt the script with Ctrl+C in the Shell. (The red Stop button is not the same, it clears the memory.) After the lines that end with KeyboardInterrupt, type the round line:
With 1021.97 in SEA_LEVEL_PRESSURE, the script shows 1560.0 m. This one number removes the error of the sensor, of the weather report and of the air temperature at the same time. Start your walk within the next hour, and the altitudes around the hut are good, too.
When the Number Moves but the Hut Does Not
Leave the altimeter on the wall, do not change the constant, and write the altitude down from time to time. The hut cannot climb. So if its altitude goes up, the air pressure goes down, and this is a weather sign:
| Altitude on the wall | Air pressure | What it often means |
|---|---|---|
| Goes up by about 29 m or more in 3 hours | falls by 3 hPa or more | the weather changes strongly, stay near the hut |
| Goes up slowly all day | falls slowly | clouds, wind or rain can come |
| Goes down slowly, or stays low | rises, or stays high | fair weather |
This is a simple rule, not a forecast. Before a mountain tour, always read the official weather report.
If Something Goes Wrong
Words in quotes are from the red text in the Shell:
- "no module named 'DIYables_MicroPython_MS5611'": the script runs on the Giga, so the driver must be on the Giga, too. Save it again on the MicroPython device and compare the name with DIYables_MicroPython_MS5611.py.
- "MS5611 not found, check the wiring": no chip answers on the bus. Maybe SCL and SDA are swapped, or VCC has no 3.3V, or PS has a wire to GND.
- "The device at 0x77 is not a working MS5611": the wires are fine, but the board is probably a BMP180, BMP280 or BME280. They share their addresses with the MS5611. The driver compares a check code (CRC) in the chip and refuses to show wrong numbers.
- The pressure is only about half, near 500 hPa at the sea: your module has a MS5607 chip on it. Create the sensor with MS5611(i2c, ms5607=True).
- The altitude jumps when somebody opens the door: wind changes the pressure in the room for a moment. Move the sensor, add foam, or make SMOOTHING bigger.
More Ideas for the Hut
- A display beside the door: the OLED 128x64 can share D8 and D9 with the MS5611, because the two modules have different I2C addresses. Print meters and feet in big numbers.
- A round dial: let the pointer from Arduino MicroPython Stepper Motor A4988 Driver show the pressure or the altitude.
- Cellar and roof: connect CSB of a second module to 3.3V, and create it with MS5611(i2c, 0x76). The weather moves both values together, so the difference depends only on the height between them. Before you start, lay them side by side and note how much they differ.
- How high did we climb? Call sensor.zero_height(50) at the door, then print sensor.height() on the way. It starts at 0 m and needs no sea-level pressure.