Creating a code for a servo motor to create a sine wave

I have been tasked to fix a machine that is supposed to rotate a 3D printed geometry that follows a sine wave. The exact frequency that is supposed to be read in 4.44Hz, but it is also supposed to be altered for future use. The people who worked on the machine before me made a crappy code for some cheap stepper motors that doesnt seem to work or be accurate. I came up with the idea to use servo motors but I have no idea how to use arduino or what servo motor to use

Welcome to the forum

Your topic was MOVED to its current forum category which is more appropriate than the original as it has nothing to do with Installation and Troubleshooting of the IDE

Clear as mud. What are you talking about? Please read the forum introduction which explains how to present information in a useful form.

I came up with the idea to use servo motors but I have no idea how to use arduino or what servo motor to use

Neither can we, unless you tell us what the servo motor is supposed to do.

Also, what is your mechanical, electronic, software experience level, exactly?

Do you have the actual parameters that the code was supposed to follow? Cheap does not necessarily relate to accuracy. Are there missteps and do they accumulate? Are there limit switches involved in the project? Is there a wiring diagram for the current project? Is there a bill of material for the current project?

Even just some photos would be 1000% better than what we can see now.
Please read:

I am sorry about the initial introduction. I am using an arduino uno r3 board. The motors currently on the machine itself are nema 23 stepper motors with a 1.8 degrees per step, so a 200 step motor. If I were to get a servo motor, the motor itself will have to create a sine wave that can be manipulated, the frequency and amplitude. I will send some pictures of the code they created here shortly, but I have no idea what exactly they used on their arduino board. I dont have much experience with these motors or coding, I am a sophomore in college.

// Include the AccelStepper Library
#include <AccelStepper.h>

// Motor Connections (constant current, step/direction bipolar motor driver)
const int dirPin = 8;
const int stepPin = 9;
const int dirPin2 = 7;
const int stepPin2 = 6;
const int dirPin3 = 4;
const int stepPin3 = 3;
AccelStepper myStepper(AccelStepper::DRIVER, stepPin, dirPin);
AccelStepper myStepper2(AccelStepper::DRIVER, stepPin2, dirPin2);
AccelStepper myStepper3(AccelStepper::DRIVER, stepPin3, dirPin3);

void setup() {
// set the maximum speed, acceleration factor,and the target position

// Horizontal Movement
myStepper.setMaxSpeed(2000);
myStepper.setAcceleration(10000);
myStepper.moveTo(100);

// Vertical Movement
myStepper2.setMaxSpeed(2000);
myStepper2.setAcceleration(10000);
myStepper2.moveTo(100);

// Rotational Movement
myStepper3.setMaxSpeed(2000);
myStepper3.setAcceleration(10000);
myStepper3.moveTo(50);

}

void loop() {

if (myStepper.distanceToGo() == 0)   

myStepper.moveTo(-myStepper.currentPosition());

if (myStepper2.distanceToGo() == 0)   

myStepper2.moveTo(-myStepper2.currentPosition());

if (myStepper3.distanceToGo() == 0)   

myStepper3.moveTo(-myStepper3.currentPosition());

// Move the motor one step
myStepper.run();

myStepper2.run();

myStepper3.run();

}

Step 0:
Forget what you have now for the moment. Describe clearly what it is that you need to accomplish. Don't mention stepper motors, servo motors, induction motors, frequencies, etc. Just tell us "I need to do X."

Once we know that, then we can determine what other questions to ask in order to help you.

Well, nothing has improved much since then. You really need to follow the protocols

I need to make a servo motor create a sine wave.

Thank you for your time, I am sorry I wasted your time and didnt follow the forum structure. I appreciate your attempt at helping me.

That is vastly different that a motor that creates a sine wave. Please make a drawing of the mechanical parts and how they are connected and moved by the motor.

Sure, no problem. Do you intend to address that deficiency soon? Or will you continue to not follow it?

I have decided to give up on this site, I will figure it out on my own. Thank you

Don't let the screen door hit you on the way out.

The existing steppers seem to turn turn:

All 10 RPM (2000 steps per minute)
myStepper: 1/2 turn forward, 1/2 turn back
myStepper2: 1/2 turn forward, 1/2 turn back
myStepper3: 1/4 turn forward, 1/4 turn back

The same motion with servos would be:
10 RPM is 3600 degrees per minute, 60 per second, 17 milliseconds per degree
servo: 0 to 180 to 0
servo2: 0 to 180 to 0
servo3: 0 to 90 to 0 to 90 to 0

#include <Servo.h>

const byte ServoPin = 4;
const byte Servo2Pin = 5;
const byte Servo3Pin = 6

Servo servo, servo2, servo3;

void setup()
{
  servo.attach(ServoPin);
  servo.attach(Servo2Pin);
  servo.attach(Servo2Pin);
}
int ServoPosition = 0;
int ServoIncrement = 1;
int Servo2Position = 0;
int Servo2Increment = 1;
int Servo3Position = 0;
int Servo3Increment = 1;

void loop()
{
  servo.write(ServoPosition);
  servo2.write(Servo2Position);
  servo3.write(Servo3Position);

  ServoPosition += ServoIncrement;
  if (ServoPosition > 180)
  {
    ServoIncrement = -ServoIncrement;
    ServoPosition = 179;
  }
  if (ServoPosition < 0)
  {
    ServoIncrement = -ServoIncrement;
    ServoPoition = 1;
  }

  Servo2Position += Servo2Increment;
  if (Servo2Position > 180)
  {
    Servo2Increment = -Servo2Increment;
    Servo2Position = 179;
  }
  if (Servo2Position < 0)
  {
    Servo2Increment = -Servo2Increment;
    Servo2Poition = 1;
  }

  Servo3Position += Servo3Increment;
  if (Servo3Position > 90)
  {
    Servo3Increment = -Servo3Increment;
    Servo3Position = 89;
  }
  if (Servo3Position < 0)
  {
    Servo3Increment = -Servo3Increment;
    Servo3Poition = 1;
  }

delay(17); // 10 RPM
}

ANY continuous rotation motor can plot a sine wave.

Just identify a fixed point on the diameter, and plot that over time - eg against a piece of paper drawn past the avis of the motor.

The speed of rotation, and the time base of the plotting mechanism affect the frequency of the plotted wave.

Good. That's a start. Now, a sine wave is a two-dimensional plot of time vs amplitude. Which axis is the servo moving?

Hi,
What sort of servo are you thinking of?


OR
image

The lower one I would think will not be able to move at the speed you need, plus you will need a metal geared and quite expensive version to attempt to accomplish your goal.

What is the mass of what the 3D printed geometry?

Does the existing stepper system have position/encoder feedback?

Tom.. :smiley: :+1: :coffee: :australia:

The OP, may have left the forum.