ESP32 C3 Super Mini - MS5611 Pressure Sensor
"How many meters are left to the top?" On a steep path, somebody in the group always asks this. A hiking map can tell you only if you know where you are, and the next sign may be an hour away. An altimeter knows it at every bend. In this project, you make one that fits in a jacket pocket. The ESP32 C3 Super Mini and the DIYables MS5611 module (its other name is GY-63) are both about as small as a postage stamp. The module feels the air pressure. The C3 turns it into two numbers: your altitude above the sea, and the meters between you and the car park.
In this tutorial, you'll learn:
- What bends inside the MS5611, and why the air pressure drops on the way up
- What each module pin does, and which three pins stay empty
- How to wire the module to GPIO8 and GPIO9, the default I2C pins of the C3, and why the board still starts normally
- How to read the pressure and the temperature with the public MS5611 library
- How one known altitude, like the number on a trail sign, becomes a complete altimeter
- Why a good hiker sets the altimeter again at every sign

Hardware Preparation
| 1 | × | ESP32 C3 Super Mini | |
| 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 | × | Breadboard | |
| 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 .
For a real hike, add a USB power bank.
Overview of MS5611 Pressure Sensor
On the blue board you see a silver can with two pinholes. This can is the sensor chip, the MS5611-01BA03 from TE Connectivity. Air gets in through the pinholes and presses on a silicon membrane, which bends only slightly. A converter with 24 bits measures the bend. The result is the air pressure, so the MS5611 is a barometer. Hikers and pilots use such a sensor as an altimeter.
Key Features:
- Resolution: 0.012 hPa, enough to notice a hand's width of height (about 10 cm)
- Range: 10 to 1200 hPa. It keeps its full accuracy from 1100 hPa down to 450 hPa, and 450 hPa is the air of a 6300 m peak
- Accuracy: ±1.5 hPa, valid for 700 to 1100 hPa at 25°C
- Speed: about 9 ms for a pressure conversion at the best resolution
- Built-in thermometer: -40°C to 85°C, with ±0.8°C at 25°C
- Wires: I2C (up to 400 kHz, the default), or SPI
- Address on I2C: 0x77, and 0x76 as a second choice
- Power and size: 3.3V to 5V, about 19 x 13 mm
Why the MS5611 Is Great for a First Altimeter:
- Four wires, and not one resistor to add
- A ready library turns the raw numbers of the chip into hPa and meters
- One flight of stairs is enough to test it, so you can start at home
※ NOTE THAT:
- This sensor is made for air. Water in a tank or air in a tire needs a different sensor.
- The MS5611 also tells a temperature, but only its own. The library uses it to correct the pressure. The warm board can add 1 to 3°C, so this is not the air of the trail. For that, see ESP32 C3 Super Mini - Temperature Sensor.
MS5611 Module Pinout

Pins that get a wire:
- VCC: power, 3.3V to 5V. On a C3 only 3.3V is right, you will see why in the wiring part
- GND: ground, 0V
- SCL: I2C clock, to GPIO9
- SDA: I2C data, to GPIO8
Pins that stay empty:
- CSB: chooses the I2C address. Empty or on GND, the address is 0x77 (a resistor on the module pulls the pin down). On 3.3V, it is 0x76. SPI uses the same pin to select the chip
- SDO: the data output of SPI, without a job on I2C
- PS: chooses the interface. HIGH means I2C, and a resistor on the module already makes it HIGH. GND means SPI
Should CSB or PS ever need a HIGH, the pin printed 3.3 is the right source. Behind these two pins is a 3.3V chip, so 5V is not allowed.
From Air Pressure to Meters
Air pressure is the weight of all the air above your head. With each meter of climb, a little of this air is left below you. Near sea level, one meter takes away about 0.12 hPa, so 1 hPa stands for about 8.3 m. Higher up, the air is thinner, and 1 hPa stands for more: about 9.2 m at an altitude of 1000 m. The unit hPa (hectopascal) is the same as the mbar of many weather maps.
The library uses this formula:
altitude = 44307.694 × (1 - (pressure / sea-level pressure) ^ 0.190284)
It needs two pressures. The sensor measures the first one. The second one belongs to the sea, far below, and it changes with the weather. The standard value is 1013.25 hPa. On the day of our hike it was 1019.2 hPa, so the standard value would give 336 m at the car park, where the sign says 385 m. That is why our altimeter takes one altitude that you know, and turns the formula around to get the sea-level pressure of the morning.
Wiring Diagram between MS5611 Pressure Sensor and ESP32 C3 Super Mini
Plug the ESP32 C3 Super Mini into the breadboard, with the middle gap under it. The MS5611 module stays beside the breadboard, on four jumper wires. Each wire starts in a free hole of the same column as the board pin (the green holes in the drawing). You need two pairs of neighbors:
- On one side: G and 3.3, the second and the third pin from the USB connector
- On the other side: 8 and 9, the fourth and the fifth pin from the USB connector

This image is created using Fritzing. Click to enlarge image
| MS5611 Module | ESP32 C3 Super Mini Pin |
|---|---|
| VCC | 3.3V (printed "3.3") |
| GND | GND (printed "G") |
| SCL | GPIO9 (printed "9") |
| SDA | GPIO8 (printed "8") |
| CSB, SDO, PS | no wire |
※ NOTE THAT:
- Never 5V on VCC. The module has pull-up resistors and a level shifter on SCL and SDA, and they follow VCC. 5V there would put 5V on GPIO8 and GPIO9, but the pins of the C3 are made for 3.3V. Be careful, 5V is the neighbor of G.
- No pin numbers in the code. On the ESP32-C3, GPIO8 (SDA) and GPIO9 (SCL) are the default I2C pins. An empty Wire.begin() takes them, so nobody has to write Wire.begin(8, 9).
- The small blue LED of the C3 is on GPIO8 too. It may flicker a little while the data runs. This is normal.
- GPIO9 is also the BOOT button, and the chip looks at GPIO8 and GPIO9 when it starts. With a LOW on GPIO9, it would wait for an upload and not run your sketch. But the pull-up resistors on the module hold both pins HIGH, so the C3 starts normally. Only leave BOOT alone while the sketch runs: it connects SCL to G, and the readings fail.
ESP32 C3 Super Mini Code - MS5611 Pressure Sensor
The first sketch checks the wires and the sensor. It shows the pure air pressure, without any meters.
What the code does:
- Starts I2C on GPIO8 and GPIO9 with Wire.begin(), because this library does not do it
- Calls begin(), which looks for the sensor at the address 0x77 of the line MS5611 altimeter(0x77), and stops if nobody is there
- Selects OSR_ULTRA_HIGH, the calmest of the five settings (the library starts with the fastest one)
- Takes one reading per second with read(), and checks for MS5611_READ_OK
- Prints the pressure in hPa, and the temperature of the chip in °C and (calculated in the sketch) in °F
Detailed Instructions
- First sketch on your C3? Begin with Getting Started with ESP32 C3 Super Mini, then come back.
- Circuit: Connect the four wires of the table. Check that VCC is on 3.3.
- USB: Join the C3 and the computer with a USB Type-C cable.
- Board and port: Choose ESP32C3 Dev Module and the COM port of the C3 in the Tools menu.
- Library: Open the Library Manager and type "MS5611". Several libraries show up. Install the one called just MS5611, written by Rob Tillaart. Nothing else has to be installed.
- Search for MS5611 created by Rob Tillaart
and click the Install button.
- Sketch: Copy the code into an empty window and press the Upload button.

- Serial Monitor: Open it and set 115200 baud.
- Walk down: Wait for four lines. Then carry everything down to the cellar or to the street, and watch the pressure.
- What to look at: Downstairs, more air is above the sensor, so the number goes up. Here it grew by 0.59 hPa. At this pressure, 1 hPa is about 8.4 m, so the way down was 0.59 x 8.4, or about 5 m.
- Pro Tip: The Serial Monitor stays empty? In the Tools menu, set USB CDC On Boot to Enabled and upload again. If only the first line is missing, press RST on the C3.
ESP32 C3 Super Mini Code - Pocket Altimeter for Hikes
Now the meters. Car parks at the trail head, passes and viewpoints often have a sign with their altitude. You give one such number to the C3, and it finds all other altitudes by itself.
What the code does:
- Reads the start altitude in meters from START_ALTITUDE
- Takes the average of 60 good readings in setup(), about 1.2 seconds, while you stand still
- Calculates the sea-level pressure of this moment with getSeaLevelPressure(startPressure, START_ALTITUDE)
- Reads the sensor all the time, and gets the altitude of each reading with getAltitude(seaLevelPressure)
- Makes the number calm: a new altitude moves the old one by a tenth only (SMOOTHING is 10)
- Prints the altitude and the difference to the start every 2 seconds
Detailed Instructions
- Circuit and library: Nothing changes.
- Find your number: Look at the sign of the trail head, or at the lines of a hiking map. Is it in feet? Multiply it by 0.3048.
- Type it in: Replace 385.0 behind START_ALTITUDE.
- Upload at home: The C3 now thinks that your home has the altitude of the trail head. For a test on the stairs, this is fine.
- At the trail head: Plug in the power bank there. The C3 starts and measures. If it already has power, press RST. In both cases, keep the board still for 5 seconds.
- Walk: Our first lines come from the 40 steps behind the car park. Each step is 18 cm high, so they are 7.2 m in total:
- Pro Tip: Nobody wants to carry a laptop up a mountain. An OLED 128x64 can show the two numbers. It uses GPIO8 and GPIO9 as well, and both parts can share these wires, because the OLED has another I2C address (0x3C).
Why You Set It Again at Every Sign
The C3 calculates the sea-level pressure only once, at the start. But the weather does not wait. If the pressure falls by 1 hPa while you eat your lunch at the lake, the sensor feels the same as after a climb of 9 m, and it cannot know the difference. This is our whole hike, on a day when the pressure falls slowly:
| Place | Sign | Sea-Level Pressure Then | Altimeter, Set Only at the Start | Altimeter, Set Again at the Lake |
|---|---|---|---|---|
| Car park | 385 m | 1019.2 hPa | 385 m | 385 m |
| Stone bridge | 506 m | 1019.0 hPa | 508 m | 508 m |
| Lake | 698 m | 1018.1 hPa | 707 m | 698 m |
| Chapel | 861 m | 1017.8 hPa | 872 m | 863 m |
| Lookout tower | 1042 m | 1017.6 hPa | 1055 m | 1046 m |
| Car park again | 385 m | 1016.4 hPa | 408 m | 399 m |
Without help, the error grows to 13 m at the tower and to 23 m at the end. The sign at the lake brings it back to zero, and at the tower only 4 m are left. With every sign on the way, it stays smaller still.
The air temperature is the second reason. The formula thinks of a standard day, with 15°C at sea level. On a hot day, the altimeter shows too few meters of climb, and on a frosty day too many. 10°C make about 4 m for every 100 m of climb. Each sign removes this error, too.
How to set it again:
- With a laptop: Type the number of the new sign behind START_ALTITUDE and upload the sketch at the sign. The difference then counts from this sign.
- Back at the car park: If START_ALTITUDE is still 385.0 in your C3, just press RST. The number is true again.
- No sign anywhere: Weather websites and airport reports publish the sea-level pressure of the hour, called QNH. Write it into the sketch, like seaLevelPressure = 1019.2;, in place of the getSeaLevelPressure() line.
- Without a laptop: Solve the last task of this page.
How to Carry It
- A pocket is a good place. It is dark and has no wind, and both sunlight and wind disturb the sensor. On a backpack, put a piece of open foam in front of the can.
- A box needs a small hole. In an airtight box, the sensor cannot feel the air outside.
- Keep rain away, and never cover the two pinholes with glue or tape.
- Some power banks switch off when the current is small. Test yours at home for one hour.
- This is a project for learning. On a real mountain, also carry a map.
※ NOTE THAT:
Would a GPS do the same? It needs no sign, but it wants a free view of the sky, and it does not see small steps as well as a pressure sensor. The two are good partners, see ESP32 C3 Super Mini - GPS.
Line-by-line Code Explanation
The above ESP32 C3 Super Mini code contains line-by-line explanation. Please read the comments in the code!
Troubleshooting
- "No sensor on the I2C wires": Are the wires on 8 and 9 in the wrong order? Swap them once. Then check that every wire is in the right column, and that PS is empty. With CSB on 3.3, the first lines of the sketch need altimeter(0x76).
- The pressure is impossible for your place: Maybe the board is no MS5611. A BMP280, a BME280 (0x76 or 0x77) or a BMP180 (0x77) lives at the same address, and begin() does not notice it. The name is printed on the board.
- About 500 hPa, half of what you expect: The can is an MS5607, a close relative. The line altimeter.reset(1); after begin() solves it: the library then calculates with the formula of that chip.
- The altitude is wrong from the first line: START_ALTITUDE must be the altitude of the place where the C3 starts, in meters. Go back to the sign and press RST.
- The board lies still, but the altitude moves: In a few seconds, this is wind or sun. In some hours, this is the weather.
- "No answer from the MS5611": A wire slipped out, or something presses the BOOT button.
Applications and Project Ideas
- Meters to the top: enter the altitude of the top and print what is left, as an answer to the question at the beginning of this page
- Break reminder: play a short tone on a piezo buzzer after every 100 m of climb
- Weather guard in the tent: a tent does not climb at night. If its altitude grows from 700 m to 727 m in 3 hours, the pressure fell by 3 hPa, and this means a strong weather change
- Hike diary: save the altitude once a minute and draw the profile of the hike at home
Video Tutorial
Challenge Yourself
- Easy: Print the altitude in feet as well: 1 m is 3.2808 feet
- Easy: Change SMOOTHING to 1, then to 30. Which one is calmer, and which one is faster?
- Medium: Print "Up", "Flat" or "Down": compare the altitude with the one a minute ago
- Advanced: Let the hiker type the number of a sign into the Serial Monitor, and set the sea-level pressure again without an upload
- Advanced: Store the signs of your route in a list, like 385, 506 and 698. Each press of a button on a free pin (not BOOT) takes the next number as the known altitude