Hey, this code was very helpful and simple. Thank you! How would I adjust the speed of the servos as well? I'm basically duplicating the code for the start position, a delay, and an end position but the servos I have are too fast. How might I slow them down?
hey there! you can add 2 variables, "step" and delayTime" in this example. delayTime determines the pause length between each movement (smaller delay = faster movement) and step determines will determine how smooth the motor will move. You can play around with both variables. Try this: #include Servo servoMotor; const int servoPin = 3; const int targetAngle = 90; // Target position for the servo void setup() { Serial.begin(9600); servoMotor.attach(servoPin); servoMotor.write(0); // Start at 0 degrees int pos = 0; int step = 1; // Step size of 1 degree per movement int delayTime = 15; // Fixed delay time in milliseconds if (targetAngle > pos) { for (pos = 0; pos = targetAngle; pos -= step) { servoMotor.write(pos); delay(delayTime); } } } void loop() { int targetAngle = 90; // Target position for the servo int pos = servoMotor.read(); // Read current position of the servo int delayTime = 15; // Fixed delay time in milliseconds int step = pos < targetAngle ? 1 : -1; // Determine step direction based on current position while (pos != targetAngle) { pos += step; // Increment or decrement the position servoMotor.write(pos); // Move the servo to the new position delay(delayTime); // Wait to maintain a consistent speed } // Optional delay to handle behavior at the end of movement delay(1000); // Wait for 1 second before next move or action }
Is this the only way to change servo parameters? Im just getting into rc planes, and dont like that some servos come with a max of 70-80° movement. Wtf do they even put servo travel limits in the radios for. 🙄Suppliers also arent great about listing details like that. So i want to be able to change things myself.
Hi there! There are other ways to change the parameters, you don't have to use a programmable microcontroller. I found "DROK Signal Generator, DC 3.3-30V Function Generator 5-30mA LCD Display PWM Pulse Frequency Duty Cycle Rectangular Wave Square Wave Signal Generator" on Amazon. I have never used particular item. The servo motor interprets the pulse width of the PWM signal to determine its position. The frequency sets the period of the signal, and the duty cycle determines the length of the high pulse within that period. May be worth checking out, or maybe something like it depending on your needs. This one may be too big for a plane, but maybe there a smaller version of this. Many rc planes have servos that restrict movement to prevent overtravel. Like other RC vehicles, I assume you can upgrade the servos. I imagine changing to a servo with more movement would drastically change the controls, especially for a plane. Check out the data sheet for the servo before you purchase it to make sure it has the movement you want. It sounds like you found a fun hobby once you get everything going!
hey there! Yes, this servo can change rotation in increments of 5 degrees. The MG995 can rotate 120 deg, -60degrees to +60degrees. here's a link to the data sheet - www.electronicoscaldas.com/datasheet/MG995_Tower-Pro.pdf There are servos that rotate 180degrees and continuous rotation. 👍
@@BMonsterLaboratory Yow thanks for the reply. We try your code on MG995 360 degree servo with 5V 2A external power supply, but the servo turn to the right continuously. Were having a problem positioning MG995 360 degree servo to a particular angle we want too. thanks for the reply appreciate any help!
@@feeldulfo9387 I don't currently have a continuous rotation servo but, try this. #include "Servo.h" #define SERVO_PIN 6 // Can use any PWM pin Servo servo; // Creates a servo object used to control the servo motor void setup() { servo.attach(SERVO_PIN); // Assigns PWM pin to the servo object } void loop() { servo.write(90); // Set the servo to its neutral position (zero degrees) delay(1000); // Wait for a moment (adjust the delay as needed) } For most continuous rotation servos, a value of 90 is often used as a "stop" or "neutral" position, where the servo should not rotate. Sending a value less than 90 will make it rotate in one direction, and sending a value greater than 90 will make it rotate in the opposite direction. So, when you use servo.write(90); with a continuous rotation servo, you are typically instructing it to stop rotating. If it doesn't stop at exactly 90, you may need to calibrate it or adjust the value slightly to find the actual "stop" position for your specific servo. I hope this was helpful! 👍
Thank you thank you a lot (:
Thanks! I appreciate it 👍
Hey, this code was very helpful and simple. Thank you! How would I adjust the speed of the servos as well? I'm basically duplicating the code for the start position, a delay, and an end position but the servos I have are too fast. How might I slow them down?
hey there! you can add 2 variables, "step" and delayTime" in this example. delayTime determines the pause length between each movement (smaller delay = faster movement) and step determines will determine how smooth the motor will move. You can play around with both variables. Try this:
#include
Servo servoMotor;
const int servoPin = 3;
const int targetAngle = 90; // Target position for the servo
void setup() {
Serial.begin(9600);
servoMotor.attach(servoPin);
servoMotor.write(0); // Start at 0 degrees
int pos = 0;
int step = 1; // Step size of 1 degree per movement
int delayTime = 15; // Fixed delay time in milliseconds
if (targetAngle > pos) {
for (pos = 0; pos = targetAngle; pos -= step) {
servoMotor.write(pos);
delay(delayTime);
}
}
}
void loop() {
int targetAngle = 90; // Target position for the servo
int pos = servoMotor.read(); // Read current position of the servo
int delayTime = 15; // Fixed delay time in milliseconds
int step = pos < targetAngle ? 1 : -1; // Determine step direction based on current position
while (pos != targetAngle) {
pos += step; // Increment or decrement the position
servoMotor.write(pos); // Move the servo to the new position
delay(delayTime); // Wait to maintain a consistent speed
}
// Optional delay to handle behavior at the end of movement
delay(1000); // Wait for 1 second before next move or action
}
Is this the only way to change servo parameters? Im just getting into rc planes, and dont like that some servos come with a max of 70-80° movement. Wtf do they even put servo travel limits in the radios for. 🙄Suppliers also arent great about listing details like that. So i want to be able to change things myself.
Hi there!
There are other ways to change the parameters, you don't have to use a programmable microcontroller. I found "DROK Signal Generator, DC 3.3-30V Function Generator 5-30mA LCD Display PWM Pulse Frequency Duty Cycle Rectangular Wave Square Wave Signal Generator" on Amazon. I have never used particular item. The servo motor interprets the pulse width of the PWM signal to determine its position. The frequency sets the period of the signal, and the duty cycle determines the length of the high pulse within that period. May be worth checking out, or maybe something like it depending on your needs. This one may be too big for a plane, but maybe there a smaller version of this.
Many rc planes have servos that restrict movement to prevent overtravel. Like other RC vehicles, I assume you can upgrade the servos. I imagine changing to a servo with more movement would drastically change the controls, especially for a plane. Check out the data sheet for the servo before you purchase it to make sure it has the movement you want.
It sounds like you found a fun hobby once you get everything going!
can this servo changes like 0 ,5,10,15 degrees. Waht is the minimum angle it can change
hey there! Yes, this servo can change rotation in increments of 5 degrees. The MG995 can rotate 120 deg, -60degrees to +60degrees. here's a link to the data sheet - www.electronicoscaldas.com/datasheet/MG995_Tower-Pro.pdf There are servos that rotate 180degrees and continuous rotation. 👍
Ye i am able to rotate to 0 to 50 degree but simultanously motor rotating to 360 slowly slowly
do you have a continuous rotation servo ?
What servo did you used?
Hey! These are MG995
@@BMonsterLaboratory we used the same servo but it just rotates continuously
@@user-hu4jl6sy6j can you post your code here?
hmm
hi there! did you get it to work?
Not working! : (
Hi there. Give more detail and I'll help as much as I can 👍
@@BMonsterLaboratory Yow thanks for the reply. We try your code on MG995 360 degree servo with 5V 2A external power supply, but the servo turn to the right continuously. Were having a problem positioning MG995 360 degree servo to a particular angle we want too. thanks for the reply appreciate any help!
@@feeldulfo9387 I don't currently have a continuous rotation servo but, try this.
#include "Servo.h"
#define SERVO_PIN 6 // Can use any PWM pin
Servo servo; // Creates a servo object used to control the servo motor
void setup() {
servo.attach(SERVO_PIN); // Assigns PWM pin to the servo object
}
void loop() {
servo.write(90); // Set the servo to its neutral position (zero degrees)
delay(1000); // Wait for a moment (adjust the delay as needed)
}
For most continuous rotation servos, a value of 90 is often used as a "stop" or "neutral" position, where the servo should not rotate. Sending a value less than 90 will make it rotate in one direction, and sending a value greater than 90 will make it rotate in the opposite direction. So, when you use servo.write(90); with a continuous rotation servo, you are typically instructing it to stop rotating. If it doesn't stop at exactly 90, you may need to calibrate it or adjust the value slightly to find the actual "stop" position for your specific servo. I hope this was helpful! 👍
servo motor mg996r can’t control the angle by the arduino only 180 can control