# MS5837 result is going crazy

**URL:** <https://discuss.bluerobotics.com/t/ms5837-result-is-going-crazy/2553>\
**Category:** Sensors\
**Created:** [April 24, 2018, 6:40pm UTC](https://discuss.bluerobotics.com/t/ms5837-result-is-going-crazy/2553 "2018-04-24T18:40:03Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![PAStesla](https://avatars.discourse-cdn.com/v4/letter/p/a88e4f/32.png) [@PAStesla](https://discuss.bluerobotics.com/u/PAStesla)\
**Post date:** [April 24, 2018, 6:40pm UTC](https://discuss.bluerobotics.com/t/ms5837-result-is-going-crazy/2553/1 "2018-04-24T18:40:03Z")

</div>

Hello all,

I am using a MS5837 pressure sensor with the Arduino code modified to use with a Particle Electron. For some reason, the pressure readings are consistently drifting downwards by 2-6 every time it logs to the console. Having reached -5000, I am at a loss for a solution. The sensor is not floating, as I have a pull-up connected. My code is linked here: [Particle Web IDE](https://go.particle.io/shared_apps/5adf622fcdc59c2b5d00051a)

Please help!

---

<div class="post-metadata">

**Author:** ![jwalser](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/jwalser/32/2234_2.png) [@jwalser](https://discuss.bluerobotics.com/u/jwalser)\
**Post date:** [April 24, 2018, 6:41pm UTC](https://discuss.bluerobotics.com/t/ms5837-result-is-going-crazy/2553/2 "2018-04-24T18:41:01Z")

</div>

Can you please provide a picture of how you have everything connected?

---

<div class="post-metadata">

**Author:** ![PAStesla](https://avatars.discourse-cdn.com/v4/letter/p/a88e4f/32.png) [@PAStesla](https://discuss.bluerobotics.com/u/PAStesla)\
**Post date:** [April 24, 2018, 6:45pm UTC](https://discuss.bluerobotics.com/t/ms5837-result-is-going-crazy/2553/3 "2018-04-24T18:45:33Z")

</div>

Of course:

 ![IMG_0351](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/b/b0f4ab361bf82995766a7931d37ea6cb4de96079.jpg)

Is this picture at a bad angle? Everything above is soldered in. Thanks a bunch for the quick response.

---

<div class="post-metadata">

**Author:** ![jwalser](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/jwalser/32/2234_2.png) [@jwalser](https://discuss.bluerobotics.com/u/jwalser)\
**Post date:** [April 24, 2018, 6:46pm UTC](https://discuss.bluerobotics.com/t/ms5837-result-is-going-crazy/2553/4 "2018-04-24T18:46:41Z")

</div>

Please capture the entire electronics. What is the name of this board?  
Are you using a logic level shifter?

---

<div class="post-metadata">

**Author:** ![jwalser](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/jwalser/32/2234_2.png) [@jwalser](https://discuss.bluerobotics.com/u/jwalser)\
**Post date:** [April 24, 2018, 6:48pm UTC](https://discuss.bluerobotics.com/t/ms5837-result-is-going-crazy/2553/5 "2018-04-24T18:48:11Z")

</div>

> [@PAStesla](#):
>
> Particle Electron.

I see.

---

<div class="post-metadata">

**Author:** ![jwalser](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/jwalser/32/2234_2.png) [@jwalser](https://discuss.bluerobotics.com/u/jwalser)\
**Post date:** [April 24, 2018, 6:54pm UTC](https://discuss.bluerobotics.com/t/ms5837-result-is-going-crazy/2553/6 "2018-04-24T18:54:15Z")

</div>

Also, can’t see the code without an account.

---

<div class="post-metadata">

**Author:** ![PAStesla](https://avatars.discourse-cdn.com/v4/letter/p/a88e4f/32.png) [@PAStesla](https://discuss.bluerobotics.com/u/PAStesla)\
**Post date:** [April 24, 2018, 7:10pm UTC](https://discuss.bluerobotics.com/t/ms5837-result-is-going-crazy/2553/7 "2018-04-24T19:10:12Z")

</div>

Ah, sorry. I’m new to posting on the forums. Ubidots is a program that allows you to track and plot data. Do you need the .h and .cpp files as well? They are basically the same as the ones Blue Robotics posted on GitHub but with D1 and D2 changed to P1 and P2.

```
#include "MS5837.h"
#include "Particle.h"

MS5837 sensor;

#include <Ubidots.h>
#define TOKEN "A1E-nKhZbeFhtLLp7VGOhbnK3WaXvCsaa8"
#define DATA_SOURCE_NAME "tessa-2-pressure"
Ubidots ubidots(TOKEN);

STARTUP(System.enableFeature(FEATURE_RETAINED_MEMORY));

PMIC pmic;

retained int twoDays;
int pressure;
int now;
retained int then;
int inches;
FuelGauge fuel;
int battery;

void setup() {
  
  Serial.begin(9600);
  
  ubidots.setDeviceLabel(DATA_SOURCE_NAME);
  
  Serial.println("Starting");
  
  Wire.begin();
  
  pinMode(D5, OUTPUT);
  digitalWrite(D5, HIGH);
  delay(500);

  // Initialize pressure sensor
  // Returns true if initialization was successful
  // We can't continue with the rest of the program unless we can initialize the sensor
  while (!sensor.init()) {
    Serial.println("Init failed!");
    Serial.println("Are SDA/SCL connected correctly?");
    Serial.println("Blue Robotics Bar30: White=SDA, Green=SCL");
    Serial.println("\n\n\n");
    delay(5000);
  }
  Serial.println("Sensor initiated succesfully");
  sensor.setModel(MS5837::MS5837_30BA);
  sensor.setFluidDensity(997); // kg/m^3 (freshwater, 1029 for seawater)
  
}

void loop() {

  twoDays += 1;
  // Update pressure and temperature readings
  sensor.read();
  pressure = sensor.pressure();
  inches = pressure*0.401865;
  battery = fuel.getSoC();
  
    if (battery == 90) {
        PMIC().disableCharging();
    } else {
        PMIC().enableCharging();
    }
    
    if (now >= then - 10) {
        if (twoDays == 24) {
            Serial.println(now);
            ubidots.add("water-level", now);
            twoDays = 0;
        }
    } else {
        then = now;
        twoDays = 0;
    }
      
  ubidots.add("battery-level", battery);
  ubidots.add("two-days", twoDays);
  
  Serial.print("Pressure: "); 
  Serial.print(pressure); 
  Serial.println(" mbar");
  
  Serial.print("Battery level: ");
  Serial.print(battery);
  Serial.println("% of capacity");
  
  Serial.print("Amount of water: ");
  Serial.print(inches);
  Serial.println(" square inches of water");
  
  Serial.print("Temperature: "); 
  Serial.print(sensor.temperature() * 9/5 + 32); 
  Serial.println(" deg F");
  Serial.println();
  Serial.println("---------------------------------------------------------------------------");
  Serial.println();
  
  ubidots.sendAll();
  
  System.sleep(SLEEP_MODE_DEEP,(10));  
  
  delay(1000);
}

```

---

<div class="post-metadata">

**Author:** ![jwalser](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/jwalser/32/2234_2.png) [@jwalser](https://discuss.bluerobotics.com/u/jwalser)\
**Post date:** [April 24, 2018, 7:18pm UTC](https://discuss.bluerobotics.com/t/ms5837-result-is-going-crazy/2553/8 "2018-04-24T19:18:58Z")

</div>

Have you tried using a regular arduino with the avr microcontroller?

---

<div class="post-metadata">

**Author:** ![PAStesla](https://avatars.discourse-cdn.com/v4/letter/p/a88e4f/32.png) [@PAStesla](https://discuss.bluerobotics.com/u/PAStesla)\
**Post date:** [April 24, 2018, 7:30pm UTC](https://discuss.bluerobotics.com/t/ms5837-result-is-going-crazy/2553/9 "2018-04-24T19:30:40Z")

</div>

I don’t actually have an Arduino, this is my only option in the short term, which is what I need.

Sorry!

Do you have any fixes for a Particle Electron?

Anyone have a fix?

---

<div class="post-metadata">

**Author:** ![jwalser](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/jwalser/32/2234_2.png) [@jwalser](https://discuss.bluerobotics.com/u/jwalser)\
**Post date:** [April 25, 2018, 8:00pm UTC](https://discuss.bluerobotics.com/t/ms5837-result-is-going-crazy/2553/10 "2018-04-25T20:00:26Z")

</div>

We’ve been hearing reports of similar issues with these sensors recently. Please contact [support@bluerobotics.com](mailto:support@bluerobotics.com) so that we can arrange an exchange at no cost.
