Controlling extension/retraction of P-type L12 Actuonix actuator using values from accelerometer

based on the example here for the actuator control, maybe something like this:
(Compiles, NOT tested!)

#include <Servo.h>

const int MinPos = 0, MaxPos = 180; //update min and max values as required
const float scale = 3.0; // 3 (±3g) for ADXL337, 200 (±200g) for ADXL377
boolean micro_is_5V = true; // Set to true if using a 5V microcontroller such as the Arduino Uno, false if using a 3.3V microcontroller, this affects the interpretation of the sensor data
int pos = 0;    // variable to store the servo position

Servo myservo;  // create servo object to control a servo

void setup()
{
  // Initialize serial communication at 9600 baud
  Serial.begin(9600);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

// Read, scale, and print accelerometer data
void loop()
{
  // Get raw accelerometer data for each axis
  int rawX = analogRead(A0);
  
  // Scale accelerometer ADC readings into common units
  // Scale map depends on if using a 5V or 3.3V microcontroller
  float scaledX; // Scaled values for each axis
  if (micro_is_5V) // Microcontroller runs off 5V
  {
    scaledX = mapf(rawX, 0, 675, -scale, scale); // 3.3/5 * 1023 =~ 675
  }

  if(scaledX > scale){ //has exceeded the max range value
    myservo.write(MaxPos);              // tell servo to go to Maximum Position
    delay(30); //abitrarity delay. adjust accordingly to sufficient time for actuator movement to complete
  }
  else if(scaledX < -scale){ //has exceeded the min range value
    myservo.write(MinPos);              // tell servo to go to Minimum Position
    delay(30); //abitrarity delay. adjust accordingly to sufficient time for actuator movement to complete    
  }
  else{
    pos = map((int)(scaledX),-scale, scale, MinPos, MaxPos); //map accel range to servo range
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(30); //abitrarity delay. adjust accordingly to sufficient time for actuator movement to complete
  }

  // Print out scaled X accelerometer readings
  Serial.print("X: "); Serial.print(scaledX); Serial.println(" g");
  Serial.println();
  
  delay(200); // Minimum delay of 2 milliseconds between sensor reads (500 Hz)
}

// Same functionality as Arduino's standard map function, except using floats
float mapf(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

hope that helps....

PS you probably will need to add another 'map' function to convert 'actuator displacement' to 'servo pos' :wink: