Using a linear actuator to mimic a sinusoidal waveform

Hi, I am new to Arduino, but I am using it for my thesis research. I'm using a linear actuator to mimic the tricuspid annulus motion for a flow loop. Basically I need to be able to make the linear actuator move in a sinusoidal motion in the rhythm of a heart beat. Right now I have it moving at constant speed both ways.

My wiring is based off of the diagram on this website

My code is as follows:

// constants won't change
const int ENA_PIN = 9; // the Arduino pin connected to the EN1 pin L298N
const int IN1_PIN = 6; // the Arduino pin connected to the IN1 pin L298N
const int IN2_PIN = 5; // the Arduino pin connected to the IN2 pin L298N

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pins as outputs.
  pinMode(ENA_PIN, OUTPUT);
  pinMode(IN1_PIN, OUTPUT);
  pinMode(IN2_PIN, OUTPUT);

  //digitalWrite(ENA_PIN, HIGH); automatically sets speed to max
  analogWrite(ENA_PIN, 255); // speed is a value from 0 to 255
}

// the loop function runs over and over again forever
void loop() {
  // extend the actuator
  digitalWrite(IN1_PIN, HIGH);
  digitalWrite(IN2_PIN, LOW);

  delay(500); // actuator will stop extending automatically when reaching the limit
// set this to 20000 to let it extend all the way

  // retracts the actuator
  digitalWrite(IN1_PIN, LOW);
  digitalWrite(IN2_PIN, HIGH);

  delay(500); // actuator will stop retracting automatically when reaching the limit
// set this to 20000 to let it extend all the way
}

Any help is greatly appreciated. Thanks everyone!

You haven't said specifically what you need help with, but if you're trying to position the actuator at specific locations, you should use position feedback of some sort. You can add an external sensor, or alternately, some variants of those actuators are sold with built-in potentiometers for feedback.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.