What hardware should I get, and help with code

I am starting a project where I have to make an airfoil follow a sine wave against time. I have used a stepper motor in a previous project but I was pointed in the direction of servo motors, The thing is I don't know where to begin on looking for a servo motor. I also don't have much experience with Arduino so I am not very knowledgeable with code. I currently have an Arduino Uno board and a power supply (Drok 200670). The airfoil does not weigh more than a pound but the servo will need to have a decent torque since it will be put in a wind tunnel. I would like for yall to help me find a decent servo motor and a servo driver, if needed, and if possible guide me into making a code that will allow me to control the servo motor. I would need to servo motor to be able to follow a sin wave that its amplitude, frequency, and the amount of time the code runs be changed at any time. Thank you

Sorry there is not enough information to even take a SWAG. You need to know the torque and speed required before a motor can be sized. This must be done at worse case. Also need to know what power is available and at what voltage. The motor will need to match the voltage or you will need to convert it to the motor voltage. You will need something to drive the motor, again unless the motor parameters are known it is at best a guess. You have a good power supply but I cannot say it will work until the other thinks are known. I am assuming you will need to measure the airfoil position, how do you plan on accomplishing that. I would guess you will have to make many measurements, what would these be and what sensors do you plan on using. This should get you started.

First thought…
Don’t connect the servo directly to the foil.
Use a simple linkage that gives you the required mechanical,advantage.

Luckily one pound is not much, so most hobby servos will suffice with the correct drive linkage.

Remember, you need a power supply.

I apologize for the lack of information, I have looked into more specs that I need and found an option. The stepper motors used before had enough torque, they had 1.9NM of torque. I wasnt planning on connecting the servo directly to the air foil, I was thinking of either using a gear box but was leaning more towards a pulley system. I will attach the servo I was looking at so I could get yalls opinion on it. The sensor we will be using is a load cell that will measure how much force the wind is pushing against the model. As for measuring the position of the model I am still figuring out a way of measuring its positions.

I dont know if any of yall have used this servo motor but do yall have any suggestions for a code? I need for it to follow a sine wave that its frequency and amplitude is adjustable. I am also thinking of getting an accelerometer to measure the change in degrees to confirm and adjust the code.

We know what "follow" means and we know what a sine wave looks like, but putting the two together in a sentence leaves me baffled. Please explain further.

Instead of using the word follow would it be better for me to say produce a sine wave? What I am trying to do is attach the servo motor to the air foil and have the air foil rotate back and forth as a sine wave would do. If i were to attach a pen to the end of the foil and have it write on a paper that moves, it should draw a sine wave. Ill see if I can attach a video explaining what I mean with some visuals so it could clear up some questions.

It wouldn’t allow me to submit a video because of the file size so I made an unlisted video on YouTube.
https://youtube.com/shorts/VDPzg6CkRF0?si=M6FYbPbJM91LvaWU

Why a servo? Connect the airfoil through a connecting rod to a crank pin on a wheel on any motor and you automatically have sine wave motion.

I thought that with a servo I would get more accuracy.

A connecting rod and a crank pin gives ABSOLUTE sine wave accuracy!

Okay thank you, I wasnt advised of this before, and it does make sense to me now. The servo motor I bought is a hybrid so I can switch it to be a regular motor as well. I will use that idea most likely in my final design, but lets say I would want to continue with the servo idea, could I get some help with a code for it?

First, show us how you care connecting to the servo. That will determine what coding is needed. High school geometry class!

The motor hasnt arrived yet, so I still havent gotten to design the base plate for it to attach to the model. I have the design idea but wanted to wait to get all the dimension of it. I can show you what I am planning on doing but I doubt it will be enough information.

I made another video, let me know if there is some other information that could useful as of now, I will receive the motor tomorrow and design and print the plate to attach to the foil.

https://youtube.com/shorts/7QOK2UuvDBY?si=OZL6yQcCJfsW30HM

Okay I have wired up the servo to the Arduino Uno R3 board, I connected the 5v cable, the ground, and have connected the servo to pin 9. Could I get some help with the code?

This is what I have now, but this was made by ChatGPT, the problem with this code is that it runs non stop and it doesnt seem to make a sine wave. It starts off by jittering a bit then it oscillates for a while but it seems to be moving, as in it starts rotating while making a sine wave.

#include <Servo.h> 
Servo myservo;  // Create a Servo object

// Constants for the sine wave parameters 
const float amplitude = 45.0;   // Amplitude of the sine wave (in degrees) 
const float frequency = 4.44;   // Frequency of the sine wave (in Hz) 
const float period = 1000.0 / frequency; // Period of the sine wave (in milliseconds) 


void setup() {   
  myservo.attach(9);  // Attach the servo to pin 9 
  } 

void loop() {   
  unsigned long currentTime = millis();   
  float angle = amplitude * sin(2 * PI * frequency * currentTime / 1000.0);   
  
  // Map the angle to servo range (0 to 180 degrees)   
  int servoPosition = map(angle, -amplitude, amplitude, 0, 180);   
  myservo.write(servoPosition);  // Set the servo angle   
  delay(20);  // Small delay to control the update rate (50 Hz)   
  
  // You can adjust the delay value to change the update rate 
  
}

Well, ChatCPT can surely debug it for you.

1 Like

Do you have any thoughts on that code?

Servo != Stepper