Programming Depth sensor with Liner actuator

Im using a Bar30 High-Resolution 300m Depth/Pressure Sensor from Blue robotics to read the depth, pressure and temperature of water. I am trying to link the sensor to a linear actuator to move back and forth.

I am using the MS5837_Example code for the depth sensor and a L16-R series linear actuator from Actuonix.

I am trying to program it so that when the depth sensor picks up a certain value, it will tell the linear actuator retract back in, and then when the depth sensor reads a lower valueit will tell the linear actuator to stretch out.

But I am having trouble programming this.

Here are the links for the parts I am using

Including links for the hardware is a good start but, you mention programming issues and don't include the code. Kinda hard for anybody to help with that.

Don't forget:

#include <Wire.h>
#include "MS5837.h"
#include <Servo.h>

Servo myservo;
MS5837 sensor;

int depth = 0;
int val;

void setup() {

  // 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");
  sensor.setFluidDensity(997); // kg/m^3 (freshwater, 1029 for seawater)

void loop() {
  // Update pressure and temperature readings
  val = analogRead(depth);
  val = map(val, 0, 1023, 0, 180);

  Serial.print("Pressure: "); 
  Serial.println(" mbar");
  Serial.print("Temperature: "); 
  Serial.println(" deg C");
  Serial.print("Depth: "); 
  Serial.println(" m");
  Serial.print("Altitude: "); 
  Serial.println(" m above mean sea level");

  if ( >= 1.2)){
    digitalWrite(val, 0);

  if ( <= 0.5)){
    digitalWrite(val, 180);

This the code that I have so far, my main issue coming up with some “if” statement for the actuator for when it reads the depth value.

Have you determined you're getting reasonable data from the sensor?

    digitalWrite(val, 180); Unusual, on several levels.

Servo myservo;

Who else’s servo would you be using? You’re not really using a servo, are you? So, the instance name has TWO dumb parts. Start by fixing this.

  val = analogRead(depth);

That is NOT how to get a depth reading from an I2C device.;
  if ( >= 1.2)){

Is the read() method really overloaded?

Does the second overload really take true or false?

  if ( >= 1.2)){
    digitalWrite(val, 0);

  if ( <= 0.5)){
    digitalWrite(val, 180);

You have defined val to be the value read from an analog pin, mapped to the range 0 to 180. It is extremely unlikely that you want to be able to write to all 180 pins on your Arduino. Which Arduino are you using, that has 180 pins? Why do you want to set the pin to state 180, anyway? They only have 2 states - on or off.