# MS5837 30 Bar Malfunction?

**URL:** <https://discuss.bluerobotics.com/t/ms5837-30-bar-malfunction/17552>\
**Category:** Blue Robotics Products\
**Created:** [July 25, 2024, 6:48pm UTC](https://discuss.bluerobotics.com/t/ms5837-30-bar-malfunction/17552 "2024-07-25T18:48:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dwcs](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/dwcs/32/13702_2.png) [@dwcs](https://discuss.bluerobotics.com/u/dwcs)\
**Post date:** [July 25, 2024, 6:48pm UTC](https://discuss.bluerobotics.com/t/ms5837-30-bar-malfunction/17552/1 "2024-07-25T18:48:08Z")

</div>

I am running into a situation with the MS5837 30 bar sensor where the depth, pressure, and temp does not seem to work. The pressure is always 0, the depth is always -33.99, and the temp is alway 20.

I have tried three different sensors (same model). Once I had the same issue. The other time I got wonky readouts.

This is the wiring:

 ![unnamed (1)](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/2/22df1c10bbd3bb516502bc869c7453159eaf97fd.jpeg)

The sensor is connected though I2C with a Sparkfun Mux board to allow other I2C connections from other sensors. VIN is 3.3V.

This is the code:

```auto
#include <Wire.h>
#include <SparkFun_I2C_Mux_Arduino_Library.h> //Click here to get the library: http://librarymanager/All#SparkFun_I2C_Mux
#include "MS5837.h"
#include <DFRobot_OxygenSensor.h>
#include <SparkFun_SCD4x_Arduino_Library.h>
#include <SparkFunBME280.h>

#define COLLECT_NUMBER 10
#define Oxygen_IICAddress ADDRESS_3

MS5837 sensor;
QWIICMUX myMux;
DFRobot_OxygenSensor oxygen;
SCD4x mySensorSCD;
BME280 mySensorBME;

const int OXYGEN = 2;
const int NITROGEN = 3;
const int BLEED = 4;
float water_level_pressure;
float uw_water_level_pressure;

void setup() {
  Serial.begin(115200);
  Serial.println();
  Serial.println("Qwiic Mux Shield Read Example");

  Wire.begin();

  if (myMux.begin() == false)
  {
    Serial.println("Mux not detected. Freezing...");
    while (1)
      ;
  }
  Serial.println("Mux detected");

  // Initialize SCD4x sensor
  while (!mySensorSCD.begin()) {
    Serial.println("SCD4x sensor initialization failed.");
    delay(1000);
  }
  while (!oxygen.begin(Oxygen_IICAddress)) {
    Serial.println("Oxygen sensor initialization failed.");
    delay(1000);
  }
  // Initialize BME280 sensor
  while (!mySensorBME.beginI2C()) {
    Serial.println("BME280 sensor initialization failed.");
    delay(1000);
  }
  sensor.setModel(MS5837::MS5837_30BA);
  sensor.setFluidDensity(997); // kg/m^3 (freshwater, 1029 for seawater)
  
  pinMode(OXYGEN, OUTPUT);
  pinMode(NITROGEN, OUTPUT);
  pinMode(BLEED, OUTPUT);
  
  // Initially turn off all relays
  digitalWrite(OXYGEN, LOW);
  digitalWrite(NITROGEN, LOW);
  digitalWrite(BLEED, LOW);
  
  delay(100); // wait for co2 levels to stabilize

  water_level_pressure = mySensorBME.readFloatPressure() / 100.0; // Read circuit pressure and convert pressure to hPa
  uw_water_level_pressure = sensor.pressure(); // mbar
  uw_water_level_pressure = uw_water_level_pressure * 100; // convert to hPa
}

void loop()
{
  myMux.setPort(0); // underwater sensor
 
  sensor.read();
float uw_pressure = sensor.pressure(); // mbar
  uw_pressure = uw_pressure * 100; // convert to hPa
  float uw_temp = sensor.temperature(); // celsius
  float uw_depth = sensor.depth(); // meters
  uw_depth = uw_depth * 3.28084; // convert to feet
  float o2 = oxygen.getOxygenData(COLLECT_NUMBER); // percent
  int co2 = mySensorSCD.getCO2(); // ppm
  float temp = mySensorBME.readTempC(); // celsius
  float humidity = mySensorBME.readFloatHumidity(); // RH (percent)
  float pressure = mySensorBME.readFloatPressure() / 100.0; // Read circuit pressure and convert pressure to hPa
  float ata = pressure / water_level_pressure;
  float uw_ata = uw_pressure / uw_water_level_pressure;
  float ppo2 = (o2 / 100) * (pressure * 0.75006375541921); // pressure in mmhg
  float ppco2 = (co2 / 1000000) * (pressure * 0.75006375541921); // pressure in mmhg
  int bleed_time = 0;
  int o2_time = 0;
  int n2_time = 0;
Serial.print("UW pressure: ");
  Serial.print(uw_pressure); // 0
  Serial.print(",");
  Serial.print("UW temp: ");
  Serial.print(uw_temp); // 1
  Serial.print(",");
  Serial.print("UW depth: ");
  Serial.print(uw_depth); // 2
  Serial.print(",");
  Serial.print("O2: ");
  Serial.print(o2); // 3
  Serial.print(",");
  Serial.print("CO2: ");
  Serial.print(co2); // 4
  Serial.print(",");
  Serial.print("Temp: ");
  Serial.print(temp); // 5
  Serial.print(",");
  Serial.print("Humidity: ");
  Serial.print(humidity); // 6
  Serial.print(",");
  Serial.print("Pressure: ");
  Serial.print(pressure); // 7
  Serial.print(",");
  Serial.print("O2 time: ");
  Serial.print(o2_time); // 8
  Serial.print(",");
  Serial.print("N2 time: ");
  Serial.print(n2_time); // 9
  Serial.print(",");
  Serial.print("Bleed time: ");
  Serial.print(bleed_time); // 10
  Serial.print(",");
  Serial.print("UW ata: ");
  Serial.print(uw_ata); // 11
  Serial.print(",");
  Serial.print("ata: ");
  Serial.print(ata); // 12
  Serial.print(",");
  Serial.print("PPO2: ");
  Serial.print(ppo2); // 13
  Serial.print(",");
  Serial.print("PPCO2: ");
  Serial.print(ppco2); // 14
  Serial.print("\n\n");

  delay(2500);
}

```

Readout over serial is:

```auto
UW pressure: 0.00,UW temp: 20.00,UW depth: -33.99,O2: 20.07,CO2: 527,Temp: 26.34,Humidity: 62.58,Pressure: 1001.22,O2 time: 0,N2 time: 0,Bleed time: 0,UW ata: nan,ata: 1.04,PPO2: 150.69,PPCO2: 0.00

```

My soldering skills suck, so maybe that’s the reason? Did I fry the sensor?

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [August 5, 2024, 7:15pm UTC](https://discuss.bluerobotics.com/t/ms5837-30-bar-malfunction/17552/2 "2024-08-05T19:15:15Z")

</div>

Hi @dwcs, welcome to the Blue Robotics forum 🙂

> [@dwcs](#):
>
> The pressure is always 0, the depth is always -33.99, and the temp is alway 20.
> 
> I have tried three different sensors (same model). Once I had the same issue. The other time I got wonky readouts.

That’s not an issue I’ve come across before, but it’s also hard to provide much advice for a board/package we haven’t manufactured and don’t have experience with. Contacting the manufacturer of the actual sensor is more likely to be helpful on that front (we just [sell a packaged version of it](https://bluerobotics.com/store/sensors-cameras/sensors/bar30-sensor-r1/), and provide some libraries to help people integrate that).

As a general principle I would recommend testing any new device/integration independently first, and preferably without permanent fixture or conditions that could cause damage/interference, just to make sure it’s working as expected. That also applies to avoiding extra hardware attached to the same communication and/or power lines, and doing the initial software testing with only code for the device being tested.

> [@dwcs](#):
>
> My soldering skills suck, so maybe that’s the reason? Did I fry the sensor?

Electronics (and sensors in particular) are sensitive to a variety of different external factors. The [sensor datasheet](https://www.te.com/commerce/DocumentDelivery/DDEController?Action=showdoc&DocId=Data+Sheet%7FMS5837-30BA%7FB1%7Fpdf%7FEnglish%7FENG_DS_MS5837-30BA_B1.pdf%7FCAT-BLPS0017) provides some maximum ratings from the manufacturer, for things like temperature, pressure, and electrostatic discharge, and mentions [this soldering guidance document](https://www.amsys.de/downloads/notes/Soldering-sensors-in-regard-to-the-RoHS-directive-AMSYS-an808e.pdf) as well, although that’s largely focused on soldering the sensor itself to a board, rather than soldering wires to that board.

Unchanging values from a sensor in variable conditions would generally indicate some kind of hardware failure, but the specific cause may be tricky to determine 🤷‍♂️
