ESP32 S3 UNO - MS5611 Pressure Sensor

In many old houses, a round brass barometer hangs beside the front door. People tap on its glass before they go out, and a needle points to one of five words: Stormy, Rain, Change, Fair or Very Dry. Its old name is weather glass, and here you build a modern one. A DIYables MS5611 pressure sensor (the module is also sold as GY-63) feels the air, the ESP32 S3 Uno does the math, and the Serial Monitor becomes the dial.

How the new weather glass takes shape:

  1. Look at the seven pins of the small blue module and find the four that get a wire
  2. Connect them to 3.3V, GND, A4 and A5, and move the I2C bus there with one line of code
  3. Print the air pressure in hPa, and see it drop when you climb the stairs
  4. Work out the pressure at sea level, in hPa, inHg and mmHg
  5. Let the sketch choose the word of the old dial, and learn how far you can trust it
The wiring diagram between ESP32 S3 Uno and MS5611 barometric pressure sensor with  and module pinout

Both sketches need one library, and no resistor or other extra part.

Hardware Preparation

1×ESP32 S3 Uno-form Board
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×Jumper Wires
1×Recommended: Screw Terminal Block Shield for ESP32 S3 Uno
1×Recommended: Sensors/Servo Expansion Shield for ESP32 S3 Uno
1×Recommended: Breadboard Shield for ESP32 S3 Uno
1×Recommended: Enclosure for ESP32 S3 Uno
1×Recommended: Power Splitter for ESP32 S3 Uno
1×Recommended: Prototyping Base Plate & Breadboard Kit for ESP32 S3 Uno

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 .

Overview of MS5611 Pressure Sensor

Behind the old dial there is a flat metal box with almost no air in it. When the air pressure rises, the box is pressed together, and small levers carry this tiny move to the needle. The MS5611 works in a similar way, but without levers. In its small metal can, the air pushes on a thin silicon membrane and bends it a tiny bit. The chip measures this bend with a 24-bit converter, and the ESP32 S3 Uno gets the result over I2C.

Air pressure comes from the weight of the air above us. Higher up there is less air, so the pressure gets lower: near sea level it falls by about 0.12 hPa per meter (1 hPa = about 8.3 m). This is why the same sensor is also called an altimeter or an altitude sensor. Pressure is given in hPa (hectopascal), and mbar is another name with the same numbers. The standard value for sea level, 1013.25 hPa, is 29.92 inches or 760 millimeters of mercury on an old dial.

MS5611 GY-63 pressure sensor module pinout - VCC, GND, SCL, SDA, CSB, SDO and PS

DIYables puts the chip (MS5611-01BA03 from TE Connectivity) on a blue board together with a 3.3V regulator, a level shifter and the pull-up resistors for I2C.

Four of its seven pins get a wire:

  • VCC: the power input, here 3.3V from the ESP32 S3 Uno.
  • GND: the ground, 0V.
  • SCL: the I2C clock, here on A5 (GPIO4).
  • SDA: the I2C data, here on A4 (GPIO5).

The other three stay empty:

  • CSB: the address pin of I2C. Left empty it stays LOW (the module has a pull-down resistor for it) and the address is 0x77, the same as on GND. Tied to 3.3V it makes the address 0x76, so two modules can share the same two I2C wires. For SPI, this is the chip select.
  • SDO: only has work in SPI mode, as the data output.
  • PS: the protocol pin. The module ties it HIGH through a resistor, so I2C is already chosen. Connected to GND, it would switch the chip to SPI.

CSB and PS belong to the 3.3V chip. Never connect them to 5V.

DIYables MS5611 Pressure Sensor Module
Module supply 3.3V to 5V, on this board 3.3V
Bus I2C up to 400 kHz (default), SPI is possible too
Address on the I2C bus 0x77, or 0x76 with CSB on 3.3V
Pressure it can measure 10 to 1200 hPa, with full accuracy between 450 and 1100 hPa
Accuracy of the pressure ±1.5 hPa (at 25°C, between 700 and 1100 hPa)
Finest pressure step 0.012 hPa, the same as about 10 cm of height
Converter 24 bit, about 9 ms per pressure conversion at the best resolution
Temperature -40°C to 85°C, ±0.8°C at 25°C
Size of the board about 19 x 13 mm

Is this good enough for a wall barometer? Yes. The fields on the dial are 15 to 20 hPa wide, so an error of 1.5 hPa can only change the word near the border of two fields.

ESP32 S3 Uno Pinout

You need four holes of the header. 3.3V and GND give the power, A4 and A5 carry the two I2C lines. Inside the ESP32-S3 chip, A4 is GPIO5 and A5 is GPIO4. The default I2C pins of the board are the SDA (GPIO8) and SCL (GPIO9) holes at the end of the digital header.

ESP32 S3 Uno pinout diagram

Wiring Diagram

The header labels in the drawing show the GPIO numbers, so look for IO5 and IO4. The tags on the wires show the Uno names of the same holes, A4 and A5.

The wiring diagram between ESP32 S3 Uno MS5611 pressure sensor

This image is created using Fritzing. Click to enlarge image

MS5611 Module ESP32 S3 Uno Pin
VCC 3.3V
GND GND
SCL A5 (GPIO4)
SDA A4 (GPIO5)
CSB, SDO, PS not connected

A wall barometer hangs in its place for years, but a jumper wire can slip out much earlier. Screws hold longer. The Screw Shield V2 and the Proto Screw Terminal Block Shield both fit on top of the ESP32 S3 Uno, and the same four wires then go under the screws 3V3, GND, A4 and A5:

The wiring diagram between ESP32 S3 Uno MS5611 pressure sensor Screw Shield

This image is created using Fritzing. Click to enlarge image

WARNING

  • VCC gets 3.3V, not 5V. The module pulls SCL and SDA up to the voltage on VCC. With 5V there, A4 and A5 would get 5V too. The ESP32 S3 Uno is a 3.3V board, and its pins are NOT 5V tolerant. The 3V3 hole has a 5V hole right beside it, so check this wire twice.
  • A4 and A5 need one line of code. They are not the default I2C pins of this board, so both sketches call Wire.begin(5, 4);. Why these two? The Screw Shield V2 has terminals for A4 and A5, but none for the SDA and SCL holes.

How To Program For MS5611 Pressure Sensor

The library reads the factory calibration from the chip and corrects the pressure with the temperature. Your sketch only needs these steps.

  1. Include both header files and create the sensor. The number is its I2C address (0x76 with CSB on 3.3V):
#include <Wire.h> #include <MS5611.h> MS5611 ms5611(0x77);
  1. Start the I2C bus and tell the board where the wires are. The first number is SDA, the second one is SCL:
Wire.begin(5, 4); // SDA = GPIO5 (A4), SCL = GPIO4 (A5)

Write this line before ms5611.begin(). The library never starts the bus by itself, and without the two numbers the board would use GPIO8 and GPIO9.

  1. Start the sensor. begin() is false when the address stays silent, or when the calibration cannot be read:
if (!ms5611.begin()) { Serial.println("No MS5611 found"); while (true) delay(1000); }
  1. Ask for the best resolution, because the library starts with the lowest one:
ms5611.setOversampling(OSR_ULTRA_HIGH);
  1. Take one reading, which needs about 20 ms. The library speaks hPa, and one division turns it into the units of the old dials:
if (ms5611.read() == MS5611_READ_OK) { float hpa = ms5611.getPressure(); // hPa, the same number as mbar float inhg = hpa / 33.86389; // inches of mercury float mmhg = hpa / 1.333224; // millimeters of mercury }
  1. Ask for the pressure at sea level. Between the brackets stand the pressure in your home and the height of your home in meters:
float sea_level = ms5611.getSeaLevelPressure(ms5611.getPressure(), 184.0);

ESP32 S3 Uno Code - MS5611 Pressure Sensor

Before there is a dial, make sure that the sensor works. Every two seconds, this sketch prints the air pressure at the sensor and the temperature of the chip.

/* * This ESP32 S3 Uno code was developed by newbiely.com * * This ESP32 S3 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3-uno/esp32-s3-uno-ms5611-pressure-sensor */ #include <Wire.h> #include <MS5611.h> MS5611 ms5611(0x77); // the I2C address, 0x76 if CSB is tied to 3.3V void setup() { Serial.begin(9600); Wire.begin(5, 4); // SDA = GPIO5 (A4), SCL = GPIO4 (A5) if (!ms5611.begin()) { // Wire.begin() must come first Serial.println("No MS5611 found. Check the wires on 3.3V, GND, A4 and A5"); while (true) delay(1000); // stop here } ms5611.setOversampling(OSR_ULTRA_HIGH); // best resolution Serial.print("MS5611 found at address 0x"); Serial.println(ms5611.getAddress(), HEX); } void loop() { if (ms5611.read() == MS5611_READ_OK) { // one reading takes about 20 milliseconds float temp_c = ms5611.getTemperature(); float temp_f = temp_c * 1.8 + 32; Serial.print("Air pressure: "); Serial.print(ms5611.getPressure(), 2); Serial.print(" hPa | Chip temperature: "); Serial.print(temp_c, 1); Serial.print("°C ("); Serial.print(temp_f, 1); Serial.println("°F)"); } else { Serial.println("The MS5611 does not answer. Check the wires"); } delay(2000); }

Detailed Instructions

  1. Is the ESP32 core missing in your Arduino IDE? Add it with the help of ESP32 S3 Uno - Getting Started.
  2. Connect the module with the four wires of the table, then plug in the USB Type-C cable.
  3. In Arduino IDE, choose ESP32S3 Dev Module and the COM port of your board.
  4. Click the Libraries icon on the left side and type "MS5611" into the search box.
  5. Click Install at the entry where the name is only MS5611 and the author is Rob Tillaart. It needs no other library:
  • Search for MS5611 created by Rob Tillaart and click the Install button.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 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
ESP32S3 Dev Module on COM15
1
  1. Paste the code into an empty sketch and click Upload.
Arduino IDE - How to Upload Code
  1. Open the Serial Monitor at 9600 baud and press RESET once, so you also see the first line.
  2. Climb one floor with the board and the laptop, about 3 m up. Here are some readings from the ground floor, then some from the floor above:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
MS5611 found at address 0x77 Air pressure: 987.61 hPa | Chip temperature: 24.8°C (76.6°F) Air pressure: 987.63 hPa | Chip temperature: 24.8°C (76.6°F) Air pressure: 987.64 hPa | Chip temperature: 24.9°C (76.8°F) Air pressure: 987.29 hPa | Chip temperature: 25.0°C (77.0°F) Air pressure: 987.28 hPa | Chip temperature: 25.0°C (77.0°F) Air pressure: 987.29 hPa | Chip temperature: 25.0°C (77.0°F)
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2
  1. Compare the two floors. The pressure is about 0.35 hPa lower upstairs, and 3 m x 0.12 hPa makes nearly the same.

ESP32 S3 Uno Code - Weather Glass

Why a barometer must know where it hangs

A house on a hill always has a lower pressure than a house at the beach. Without a correction, the hill house would have bad weather every day. This table is for one fine day, with 1020 hPa at sea level:

Height of the house Pressure in the house Word without correction Word with correction
0 m 1020.0 hPa Fair Fair
150 m 1002.0 hPa Change Fair
300 m 984.2 hPa Rain Fair
500 m 960.9 hPa Stormy Fair

So the sketch calculates the pressure that you would have if your home stood at sea level. Weather maps do this too. All you have to add is MY_ALTITUDE, the height of your home in meters.

The five fields of the dial

Old dials have a scale in inches of mercury (inHg) or in millimeters of mercury (mmHg), so the sketch prints both next to hPa. For the words, it uses these limits:

Word on the dial hPa at sea level inHg mmHg
Stormy below 980 below 28.94 below 735
Rain 980 to 1000 28.94 to 29.53 735 to 750
Change 1000 to 1015 29.53 to 29.97 750 to 761
Fair 1015 to 1035 29.97 to 30.56 761 to 776
Very Dry above 1035 above 30.56 above 776
/* * This ESP32 S3 Uno code was developed by newbiely.com * * This ESP32 S3 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3-uno/esp32-s3-uno-ms5611-pressure-sensor */ #include <Wire.h> #include <MS5611.h> #define MY_ALTITUDE 184.0 // height of your home above sea level in meters (take it from a map) #define READ_EVERY 10000 // milliseconds between two readings #define HPA_PER_INHG 33.86389 // 1 inch of mercury is this many hPa #define HPA_PER_MMHG 1.333224 // 1 millimeter of mercury is this many hPa MS5611 ms5611(0x77); // the I2C address, 0x76 if CSB is tied to 3.3V // find the word of the old dial for a sea-level pressure in hPa const char* dialWord(float hpa) { if (hpa < 980.0) return "Stormy"; if (hpa < 1000.0) return "Rain"; if (hpa < 1015.0) return "Change"; if (hpa <= 1035.0) return "Fair"; return "Very Dry"; } void setup() { Serial.begin(9600); Wire.begin(5, 4); // SDA = GPIO5 (A4), SCL = GPIO4 (A5) if (!ms5611.begin()) { // Wire.begin() must come first Serial.println("MS5611 not ready. Run the first sketch to find the reason"); while (true) delay(1000); // stop here } ms5611.setOversampling(OSR_ULTRA_HIGH); // best resolution Serial.print("Weather glass for a home at "); Serial.print(MY_ALTITUDE, 0); Serial.println(" m above sea level"); } void loop() { if (ms5611.read() == MS5611_READ_OK) { float pressure = ms5611.getPressure(); // hPa, here at the sensor // the pressure we would have here if our home stood at sea level float sea_level = ms5611.getSeaLevelPressure(pressure, MY_ALTITUDE); Serial.print("Here: "); Serial.print(pressure, 1); Serial.print(" hPa | Sea level: "); Serial.print(sea_level, 1); Serial.print(" hPa = "); Serial.print(sea_level / HPA_PER_INHG, 2); Serial.print(" inHg = "); Serial.print(sea_level / HPA_PER_MMHG, 1); Serial.print(" mmHg | Dial: "); Serial.println(dialWord(sea_level)); } else { Serial.println("The MS5611 does not answer. Check the wires"); } delay(READ_EVERY); }

Detailed Instructions

  1. Find your height above sea level on a map that shows heights. Do you live upstairs? Add about 3 m per floor.
  2. Write it into the sketch, in the line #define MY_ALTITUDE, in place of 184.0.
  3. Upload the sketch. The wiring and the library are the same as before.
  4. Read the dial in the Serial Monitor at 9600 baud. Every ten seconds a new line appears:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
Weather glass for a home at 184 m above sea level Here: 987.6 hPa | Sea level: 1009.4 hPa = 29.81 inHg = 757.1 mmHg | Dial: Change Here: 987.6 hPa | Sea level: 1009.4 hPa = 29.81 inHg = 757.1 mmHg | Dial: Change
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2
  1. Compare the sea-level number with the weather website of your area. If they are far apart, check MY_ALTITUDE first: 10 m too much or too little make an error of about 1.2 hPa.
  2. Move the needle on purpose. Weather is slow, so enter a wrong height for a moment. With 284.0 in place of 184.0, our result became 1021.5 hPa and the word jumped to Fair.
  3. Let it run. The same weather glass two days later, when rain came in:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
Here: 976.3 hPa | Sea level: 997.9 hPa = 29.47 inHg = 748.5 mmHg | Dial: Rain Here: 976.2 hPa | Sea level: 997.8 hPa = 29.46 inHg = 748.4 mmHg | Dial: Rain
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

※ NOTE THAT:

The word is only a rule of thumb. In winter, high pressure can bring fog, and a short shower can fall while the dial says Fair. Near the equator the pressure changes so little that the word may stay the same for weeks. A fast change of the number tells you more than the word.

Video Tutorial

Additional Knowledge

Read the change, not only the word

Many old barometers have an extra hand, the set hand. It does not move by itself: you turn it with a knob until it lies over the needle. A few hours later, the gap between the two hands shows what the air has done. With the ESP32 S3 Uno, a pencil does the same job. Write down the sea-level number, and look again three hours later:

Since your pencil note What often follows
It rises steadily, or it stays high fair weather
It falls clouds, wind or rain are likely
It falls fast, 3 hPa or even more a strong weather change

An example: your note says 1009.4 hPa, and three hours later you read 1006.0 hPa. The dial says Change both times, but the number fell by 3.4 hPa, and that is the real message.

Make the glass more like the original

  1. The set hand: store one sea-level value in a variable and print sea_level - stored_value on every line. A push button can renew the stored value, like the knob on the old dial.
  2. A real needle: turn a paper hand with the motor of ESP32 S3 Uno - Servo Motor. If 960 hPa is 180 degrees and 1050 hPa is 0 degrees, each hPa is 2 degrees wide.
  3. A dial that shines: print the word in big letters on an OLED, see ESP32 S3 Uno - OLED 128x64. That page uses the same A4 and A5 wires, and both parts can stay on them: the OLED listens to 0x3C, the MS5611 to 0x77.
  4. The thermometer below the dial: for the room temperature, add the sensor of ESP32 S3 Uno - DHT22.

Function References

FAQ

Can I use the SDA and SCL holes and not A4 and A5?

Yes. Put the SDA wire into SDA (GPIO8) and the SCL wire into SCL (GPIO9), then delete the two numbers in both sketches, so that the line is Wire.begin();.

Does the weather glass have to hang outside?

No. A normal house is not airtight, so the pressure inside and outside is practically the same. Direct sun and wind make the reading worse, so stay away from sunny walls, fans and open windows. Some open foam on the metal can keeps moving air away. The two small holes of the can must stay open and dry.

My grandfather's barometer shows another number. Which one is right?

Ask a third one: weather websites and airport reports tell the sea-level pressure (QNH) of your area. If the old one is wrong, look at its back. Many of them have a small screw there to move the needle.

Is the temperature the temperature of my room?

Not exactly. The number belongs to the chip, and the chip sits on a board that gets a little warm. Expect 1 to 3°C more than a room thermometer shows. For the pressure math, the chip temperature is the right one.

Can it measure water pressure or the pressure in a tire?

No. The MS5611 is made for the air around us, from 10 to 1200 hPa, and water in the two small holes can damage it.

Troubleshooting

Problem Possible Cause Solution
Message "No MS5611 found" A loose wire, SCL and SDA exchanged, Wire.begin(5, 4) missing, or the address is 0x76 SDA goes to A4 (GPIO5), SCL to A5 (GPIO4). Keep the Wire.begin() line before ms5611.begin(). If CSB is on 3.3V, the sketch needs 0x76
The pressure or the temperature is far from anything possible A BMP280, BME280 or BMP180 is on the same bus or sold under the wrong name. They use the same addresses, and begin() may not notice it Unplug other I2C modules and look at the name of the chip on the board
The pressure is about 500 hPa, half of the real value The module carries an MS5607 chip Add ms5611.reset(1); after ms5611.begin()
The dial is always on Stormy, or always on Very Dry MY_ALTITUDE is far too low, or far too high Take the height of your home from a map, in meters and not in feet
The last digits jump Wind from a fan or a window Move the module, or cover the can with open foam
No text or only symbols in the Serial Monitor Wrong baud rate, or the board sent the text before the monitor was open Choose 9600 baud and press RESET

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