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:

ESP32 C3 Super Mini on a breadboard with MS5611 pressure sensor and pinout

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)
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 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

MS5611 GY-63 module pinout showing power, I2C and SPI pins

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
The wiring diagram between ESP32 C3 Super Mini MS5611 pressure sensor

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
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-ms5611-pressure-sensor */ /* * ESP32 C3 Super Mini - MS5611 Pressure Sensor (GY-63 module) * * Prints the air pressure and the temperature of the sensor chip once a second. * * Library: MS5611 by Rob Tillaart * * Wires (the board stands on a breadboard, the module is beside it): * 3.3 -> VCC of the module (never the 5V pin) * G -> GND of the module * 9 -> SCL of the module (GPIO9) * 8 -> SDA of the module (GPIO8) * CSB, SDO and PS of the module stay empty */ #include <Wire.h> // I2C #include <MS5611.h> // the sensor #define READ_INTERVAL 1000 // time between two readings, in milliseconds MS5611 altimeter(0x77); // the sensor object and its I2C address (0x76 when CSB is on 3.3) void setup() { Serial.begin(115200); // start the Serial Monitor at 115200 baud (enable "USB CDC On Boot" in Arduino IDE) delay(2000); // short wait, so the USB serial port is ready before the first text Wire.begin(); // start I2C on the default pins of the C3 (SDA = GPIO8, SCL = GPIO9) // begin() asks for an answer at the address and loads the calibration numbers of the sensor if (!altimeter.begin()) { Serial.println("No sensor on the I2C wires. Check 3.3, G, 9 (SCL) and 8 (SDA)"); while (true) delay(1000); // stop here, there is nothing to read } altimeter.setOversampling(OSR_ULTRA_HIGH); // the calmest of the 5 settings Serial.print("Hello MS5611, your I2C address is 0x"); Serial.println(altimeter.getAddress(), HEX); // 77 or 76 } void loop() { // read() measures pressure and temperature, it takes about 20 milliseconds if (altimeter.read() == MS5611_READ_OK) { float celsius = altimeter.getTemperature(); // temperature of the chip in °C float fahrenheit = celsius * 1.8 + 32; // the same temperature in °F Serial.print("Pressure "); Serial.print(altimeter.getPressure(), 2); // pressure in hPa, 2 digits after the dot Serial.print(" hPa, chip "); Serial.print(celsius, 1); Serial.print(" °C ("); Serial.print(fahrenheit, 1); Serial.println(" °F)"); } else { // the sensor was there at the start, but it does not answer now Serial.println("No answer from the MS5611. Is a wire loose, or is BOOT pressed?"); } delay(READ_INTERVAL); // wait 1 second before the next reading }

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.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
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
ESP32C3 Dev Module on COM15
1
  • Sketch: Copy the code into an empty window and press the Upload button.
How to upload ESP32 C3 Super Mini code on Arduino IDE
  • 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.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
Hello MS5611, your I2C address is 0x77 Pressure 993.74 hPa, chip 19.4 °C (67.0 °F) Pressure 993.77 hPa, chip 19.5 °C (67.0 °F) Pressure 993.75 hPa, chip 19.5 °C (67.1 °F) Pressure 993.75 hPa, chip 19.5 °C (67.1 °F) Pressure 993.82 hPa, chip 19.5 °C (67.0 °F) Pressure 993.94 hPa, chip 19.4 °C (66.9 °F) Pressure 994.09 hPa, chip 19.4 °C (66.8 °F) Pressure 994.22 hPa, chip 19.3 °C (66.8 °F) Pressure 994.31 hPa, chip 19.3 °C (66.7 °F) Pressure 994.33 hPa, chip 19.2 °C (66.6 °F) Pressure 994.34 hPa, chip 19.2 °C (66.5 °F)
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2
  • 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
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-ms5611-pressure-sensor */ /* * ESP32 C3 Super Mini - MS5611 Pressure Sensor - Pocket Altimeter for Hikes * * You type in the altitude of the place where the hike starts (from a sign or a map). * At power-up, the C3 measures the air pressure there and calculates the sea-level * pressure of this moment. From then on, it knows the altitude of every other place. * * Library: MS5611 by Rob Tillaart * * Wires: 3.3 -> VCC, G -> GND, 9 -> SCL, 8 -> SDA */ #include <Wire.h> #include <MS5611.h> #define START_ALTITUDE 385.0 // CHANGE THIS: meters above the sea at the place where you switch the board on #define START_READINGS 60 // how many good readings are taken at the start (about 1.2 seconds) #define SMOOTHING 10 // each new value moves the altitude by 1/10 only: a calm number, without much waiting #define PRINT_INTERVAL 2000 // time between two lines, in milliseconds MS5611 altimeter(0x77); // the sensor object and its I2C address (0x76 when CSB is on 3.3) float seaLevelPressure = 0; // the air pressure at the sea, calculated at the start, in hPa float altitude = START_ALTITUDE; // the smoothed altitude in meters, it begins at the known number unsigned long lastPrintTime = 0; // when the last line was printed void setup() { Serial.begin(115200); // start the Serial Monitor at 115200 baud (enable "USB CDC On Boot" in Arduino IDE) delay(3000); // time for the USB serial port, and for the sensor to warm up a little Serial.println("ESP32 C3 Super Mini pocket altimeter"); Wire.begin(); // start I2C on the default pins of the C3 (SDA = GPIO8, SCL = GPIO9) if (!altimeter.begin()) { Serial.println("No working MS5611 found. Check 3.3, G, 9 (SCL) and 8 (SDA)"); while (true) delay(1000); // stop here, there is nothing to read } altimeter.setOversampling(OSR_ULTRA_HIGH); // the calmest of the 5 settings // 1) Take some readings at the start and make their average Serial.println("Do not move, measuring the start..."); float sum = 0; int goodReadings = 0; while (goodReadings < START_READINGS) { if (altimeter.read() == MS5611_READ_OK) { sum += altimeter.getPressure(); goodReadings++; // one more good reading } else { Serial.println("No answer from the MS5611. Is a wire loose, or is BOOT pressed?"); delay(1000); // wait a moment, then try again } } float startPressure = sum / START_READINGS; // 2) The pressure here and the altitude here are known: calculate the pressure at sea level seaLevelPressure = altimeter.getSeaLevelPressure(startPressure, START_ALTITUDE); Serial.print("Start: "); Serial.print(START_ALTITUDE, 1); Serial.print(" m, "); Serial.print(startPressure, 2); Serial.print(" hPa -> sea level: "); Serial.print(seaLevelPressure, 1); Serial.println(" hPa"); } void loop() { // Read without a pause: the smoothing needs many readings (about 50 per second) if (altimeter.read() != MS5611_READ_OK) { Serial.println("No answer from the MS5611. Is a wire loose, or is BOOT pressed?"); delay(1000); return; // try again } float newAltitude = altimeter.getAltitude(seaLevelPressure); // meters above the sea, from this reading altitude += (newAltitude - altitude) / SMOOTHING; // the calm number that we print // Print a line every 2 seconds if (millis() - lastPrintTime >= PRINT_INTERVAL) { lastPrintTime = millis(); float difference = altitude - START_ALTITUDE; // meters above (+) or below (-) the start Serial.print("Altitude: "); Serial.print(altitude, 1); Serial.print(" m from start: "); if (difference >= 0) Serial.print("+"); // print() writes the minus sign by itself, but not the plus sign Serial.print(difference, 1); Serial.println(" m"); } }

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:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
ESP32 C3 Super Mini pocket altimeter Do not move, measuring the start... Start: 385.0 m, 973.54 hPa -> sea level: 1019.2 hPa Altitude: 385.0 m from start: +0.0 m Altitude: 385.0 m from start: +0.0 m Altitude: 385.8 m from start: +0.8 m Altitude: 386.5 m from start: +1.5 m Altitude: 387.4 m from start: +2.4 m Altitude: 388.2 m from start: +3.2 m Altitude: 389.0 m from start: +4.0 m Altitude: 389.8 m from start: +4.8 m Altitude: 390.6 m from start: +5.6 m Altitude: 391.5 m from start: +6.5 m Altitude: 392.2 m from start: +7.2 m Altitude: 392.2 m from start: +7.2 m
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2
  • 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

※ 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!