ESP32 UNO - MS5611 Pressure Sensor
Rain is bad news for a day at the lake, and also for fresh paint on the garden fence. The air often gives a hint some hours before: its pressure starts to go down. With the ESP32 Uno form board and a DIYables MS5611 module, also known as GY-63, you can watch for this hint at home, in the garden or at the water. Four wires and one library are enough. The finished sketch remembers the last three hours and ends every line with one word: Rising, Steady or Falling.
Step by step to your barometer:
- See what the seven pins of the MS5611 do, and why only four of them get a wire
- Connect the module to the SDA and SCL header holes and to 3.3V
- Read the air pressure in hPa and the temperature of the chip
- Store one averaged value every 10 minutes and compare it with the oldest one
- Test the trend in a few minutes, without waiting for rain

Components You Need
| 1 | × | ESP32 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 |
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 .
The MS5611 Module
Read this part once, and you know what the number on the screen is made of.
The blue board is about 19 x 13 mm. Shops and hobby pages call it GY-63, barometric pressure sensor, barometer, altimeter or altitude sensor. The important part is the silver can with two tiny holes: the MS5611-01BA03 chip from TE Connectivity.
Think of the can as a tiny drum. Its skin is a silicon membrane, and the weight of the air pushes this skin in, only a very little. The chip measures the push with a 24-bit converter. Carry the drum up a hill, and part of the air is now below you, so the push gets weaker. Near sea level you lose about 0.12 hPa per metre, which is 1 hPa for roughly 8.3 m. The weather changes the push as well, even when the module never moves. That second effect is the one for this page.
The result comes in hPa (hectopascal), the unit of the weather maps. Some maps write mbar, and the number is the same. 1013.25 hPa counts as the standard value at sea level.

| Pin | What It Is For | Wire on This Page |
|---|---|---|
| VCC | Power input, 3.3V up to 5V | 3.3V |
| GND | Ground, 0V | GND |
| SCL | I2C clock | SCL |
| SDA | I2C data | SDA |
| CSB | I2C address, no wire or GND = 0x77, 3.3V = 0x76 (for SPI it is the chip select) | none |
| SDO | Data out in SPI mode | none |
| PS | Bus selection, HIGH = I2C (a small resistor on the board takes care of that), GND = SPI | none |
Be careful with CSB and PS: they lead straight to the chip, and the chip runs at 3.3V. HIGH for these two pins means 3.3V, never 5V.
| Feature | Value |
|---|---|
| Supply voltage | 3.3V to 5V, with a 3.3V regulator of its own |
| Bus | I2C with up to 400 kHz, SPI is possible too |
| Address on I2C | 0x77, or 0x76 with CSB on 3.3V |
| What it can measure | 10 hPa to 1200 hPa, with full accuracy between 450 and 1100 hPa |
| Resolution | 0.012 hPa, the same as about 10 cm up or down |
| Accuracy of the pressure | ±1.5 hPa between 700 and 1100 hPa, at 25°C |
| Accuracy of the temperature | ±0.8°C at 25°C |
| Works in | -40°C to 85°C |
| Converter | 24 bit, one pressure conversion takes about 9 ms at the best resolution |
Good to know: an accuracy of ±1.5 hPa looks poor for a trend of 1 hPa. It is not a problem. The error of your own module stays almost the same from hour to hour, and the sketch subtracts two values of the same module. So the error nearly disappears.
ESP32 Uno Pinout
Two holes are important today, and the board prints their names: SDA and SCL. They are the last two holes of the digital header, after GND and RST. Behind them are GPIO21 (SDA) and GPIO22 (SCL).

How to Connect
Four wires and no resistor: SCL and SDA need pull-up resistors, and the module brings its own. CSB, SDO and PS stay empty.

This image is created using Fritzing. Click to enlarge image
| MS5611 Pin | ESP32 Uno Pin |
|---|---|
| VCC | 3.3V |
| GND | GND |
| SCL | SCL (GPIO22) |
| SDA | SDA (GPIO21) |
WARNING
On this board VCC gets 3.3V, never 5V. The module pulls SCL and SDA up to the voltage of VCC. With 5V there, GPIO21 and GPIO22 would get 5V too, and the pins of the ESP32 work at 3.3V: they are not 5V tolerant.
A barometer runs day and night, maybe in a shed or a boat house where nobody checks the wires. Screws are a safer choice than loose jumper ends. You can use a Screw Shield V2 for that, or also a Proto Screw Terminal Block Shield. Both sit on top of the ESP32 Uno, and the four pins stay the same:

This image is created using Fritzing. Click to enlarge image
Only two of the four wires sit under a screw here: 3.3V and GND. SDA and SCL have no screw terminal on the Screw Shield V2. The diagram shows where they go: into the SDA and SCL holes of the shield's own header.
Good to know: do not move SDA and SCL to A4 and A5. On this board A4 is GPIO36 and A5 is GPIO39. Both are input-only analog holes and carry no I2C.
A Good Place for the Sensor
- Shade and calm air: sunlight and gusts of wind make the value jump. Cover the metal can with a bit of open foam.
- Dry, but not airtight: a box with a small opening is fine. The two holes of the can must stay free and dry.
- Always the same height: a move of 8.3 m up or down looks like 1 hPa of weather.
ESP32 Uno Code - Air Pressure and Chip Temperature
The first sketch shows that the wiring works. It prints one line every two seconds. Before that, it prints the I2C address of the sensor, or a message when no sensor answers.
Upload and Test
- No ESP32 core in your Arduino IDE yet? Add it with ESP32 Uno - Getting Started.
- Connect the four wires and look at VCC once more: it must be on 3.3V.
- Join the board and the computer with the USB Type-C cable. The board in the IDE is ESP32 Dev Module, the port is the one of the CH340.
- Find the library: click the Libraries icon, then type "MS5611" into the search box.
- Install the result called MS5611, by Rob Tillaart, with the Install button. Some neighbours in the list have a longer name, so read twice. One library is all you need here.
- Search for MS5611 created by Rob Tillaart
and click the Install button.
- Put the sketch into the IDE and press Upload.
- Look at the Serial Monitor (9600 baud) and tap the reset (EN) button. Some strange signs before the first line are normal on an ESP32:
- Pro tip: hold the module near the floor, then high above your head. With 2 m between the two places, the pressure up there is about 0.24 hPa lower. You can see it in the digits after the point.
Why is there a temperature at all? The library uses it to correct the pressure. It belongs to the chip itself, and the parts around it add some heat, so 1 to 3°C above the room is normal. For the air in the garden or the greenhouse, take a DHT22 or a DS18B20.
ESP32 Uno Code - Is the Weather Going Up or Down?
One pressure value says little. The change over some hours says much more. This sketch takes 50 readings in about 5 seconds, stores their average, and does it again every 10 minutes. The array has room for 19 values. They have 18 gaps of 10 minutes between them, and that makes 3 hours. The newest value minus the oldest one is the change, and two limits turn it into a word:
| Word | Change against the Oldest Value | What It Often Means |
|---|---|---|
| Rising | +1.0 hPa or more | fair weather is likely |
| Steady | between the two limits | no clear sign of a change |
| Falling | -1.0 hPa or lower | clouds, wind or rain are likely |
Watch out for -3.0 hPa or lower. Such a fast fall within 3 hours points to a strong change of the weather, so it is better to pack up the rods and close the greenhouse. All this is a rule of thumb, so read the official forecast as well. And it is about the weather only: the sketch knows nothing about the fish.
Upload and Test
- Keep the circuit and the library. Nothing changes there.
- Upload the second sketch and press the reset (EN) button. The first value comes after about 5 seconds, then one line every 10 minutes:
- Leave it alone for the afternoon. On this day the pressure goes down, slowly at first. The word changes after a bit more than two hours:
- Look at the time in each line. From the 19th value on, it stays at 180.0 min. Each new value then pushes out the oldest one:
- Pro tip: in the first three hours the sketch looks back over a shorter time. Do not trust the word Steady too early.
Quick Test without Waiting for Rain
Make the time short and the limits small. Change three lines at the top of the sketch:
Leave the module on the floor for three lines. Then put it on a shelf about 2 m higher:
Wait six minutes on the shelf, and the word goes back to Steady, because all the floor values have left the array. Back on the floor, you get Rising. When the test is done, set the three lines to 600000UL, 1.0 and -1.0 again.
Video Tutorial
Code Explanation
| Code Part | What It Does |
|---|---|
| Wire.begin() | Starts the I2C bus on GPIO21 and GPIO22, the sensor cannot answer before this line |
| barometer.begin() | Looks for the sensor at MS5611_ADDRESS and loads its factory calibration, gives false when one of the two fails |
| setOversampling(OSR_ULTRA_HIGH) | Lowers the noise from 0.065 hPa (the setting after the start) to 0.012 hPa |
| barometer.read() | Takes one reading in about 20 ms, gives MS5611_READ_OK when all went well |
| getPressure() | Pressure of the last reading in hPa |
| getTemperature() | Chip temperature in °C, for °F the sketch takes it x 1.8 + 32 |
| readAverage() | Averages 50 readings, with 80 ms between them |
| storeValue() | Puts the new value at the end, and moves all values one place forward when the array is full |
| history[0] | The oldest value, at most 3 hours old |
| millis() - last_sample | Time since the last value, loop() ends at once while it is too early |
| trendWord() | Compares the change with the two limits |
Wire.h is part of the ESP32 core, so there is nothing to install for it.
Compare with the Weather Report
The report says 1016 hPa, but the barometer in your hill garden says 978 hPa. Both can be right. Reports show the pressure at sea level (QNH), so that all towns can be compared. If you know the height of your garden from a map, the library does the same math with the last reading and this height:
With 978.30 hPa at 320 m it prints 1016.29. It also works the other way: barometer.getAltitude(1016.29), with today's sea-level pressure between the brackets, returns the metres above sea level. Take a fresh value from a weather website or an airport report, because 1 hPa wrong means about 8.3 m wrong.
ESP32 Uno vs UNO R4 for This Project
The two boards have the same shape, but the module is wired in a different way.
| Item | Arduino UNO R4 | ESP32 Uno |
|---|---|---|
| VCC of the module | 5V | 3.3V only |
| I2C data | A4 or the SDA hole | SDA hole only (GPIO21) |
| I2C clock | A5 or the SCL hole | SCL hole only (GPIO22) |
| Arduino code | works as it is | works as it is |
Try These Next
- Screen in the shed: show the pressure and the word on an OLED 128x64. It shares the SDA and SCL holes with the MS5611 (0x3C and 0x77) and also runs from 3.3V.
- Curve on the phone: send the value to the Bluetooth Plotter. You see a bend in the curve before the word changes.
- Storm line: print one extra line when the change is -3.0 hPa or lower.
- Longer memory: set HISTORY_SIZE to 73, and the array looks back 12 hours.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| "No MS5611 on the I2C bus" | A loose wire, SDA and SCL are on A4 and A5, or CSB is on 3.3V | Use the SDA and SCL holes, check 3.3V and GND, then press reset. With CSB on 3.3V, set MS5611_ADDRESS to 0x76 |
| Numbers that no weather can make | There is a BMP280, BME280 or BMP180 on the bus, with the address of the MS5611 | The sketch cannot see the difference. Read the print on the module and take the wrong one off |
| Only half of the real pressure, about 500 hPa | The chip on the module is a MS5607 | Put barometer.reset(1); into setup(), after barometer.begin() |
| Values jump by some tenths of a hPa | Wind or a slamming door | Find a calmer place, use the foam |
| Rising or Falling right after a walk | You changed the height, not the weather | Press reset at the new place and start with fresh values |
| No COM port | CH340 driver missing, or a charge-only cable | Install the driver and use a USB cable with data wires |
FAQ
Does the trend need my altitude?
No. The module stays in one place, so its height is the same in the newest and in the oldest value. Only the weather is left in the difference. At the lake, set it up first and press reset there: a lake 20 m below the car park adds about 2.4 hPa.
What happens after a reset or an empty battery?
The array is in RAM, so it starts empty. You get a full 3 hour trend again after 3 hours.
Is 1.0 hPa the right limit everywhere?
It is a good start. Near the equator the pressure goes up and down twice a day by itself, and 1 to 2 hPa in 3 hours is normal there on a dry day. Try 2.0 and -2.0 in such a place.
Can the MS5611 measure the depth of the lake?
No. It is made for air, not for water or tyre pressure. Keep the can dry.
Can I connect two MS5611 modules?
Yes. Connect CSB of the second module to 3.3V. It then answers at 0x76, while the first one stays at 0x77, and both share SDA and SCL. In the sketch, give the second one its own object: MS5611 barometer2(0x76);.