How to servo hold

I would like to make an arm that holds position like with this video: https://youtu.be/WnKNEcDZwfM?list=LL and also controlled by a RC reciever

They are simply using the press toggle on the joystick to switch between live mode and latching mode.

Nothing complicated there.

And how would I create a sketch like that?

Do you have the hardware?

You could start here

https://docs.arduino.cc/learn/electronics/servo-motors/

and here

https://docs.arduino.cc/libraries/servo/

Since we have no idea what level of programming you've been up to, it's hard to be more specific.

Switching between the modes that @lastchancename points out would involve code that would be logically identical to being able to turn on and off one LED using one pushbutton.

Can you write that now? If not, it would make a good first and reusable step toward your goal.

HTH and welcome to the forum.

a7

An interesting position with the az/el servos, for example, is when, together, they are "facing west" and given the commands to "face east"... there are four ways to complete the travel... (1) send the el servo over the top (az = 0, el = 180) or (2) send the az servo around the corner (az = 180, el = 0), (3) move one, then catch-up with the other, and (4) move az and el together. Gimbals (think airborne GoPro/EOIR) call two of these points Nadir (straight down) and Zenith (straight up), and could cause a fight for which servo does the work. The code people did amazing work. The user in this video helps the servos by giving a little az before the el or a little el before the az.

1 Like

I recommend you get a copy of the Arduino Cookbook and skim cover to cover before going any further.

I don't have any experience coding but I have a few RCs. I want to build a loader that uses servos to lift and tilt the arm. I used CHATGPT to come up with this and it works perfectly

#include <Servo.h>

Servo servo1;
Servo servo2;

const int pwmInPin1 = 3;
const int pwmInPin2 = 5;
const int servoPin1 = 6;
const int servoPin2 = 9;

// Servo positions
int pos1 = 90;
int pos2 = 90;

// PWM characteristics
const int center = 1500;
const int deadband = 100;

// Update timing
unsigned long lastUpdate = 0;
const int updateInterval = 5; // ms (50Hz)

void setup() {
  pinMode(pwmInPin1, INPUT);
  pinMode(pwmInPin2, INPUT);

  servo1.attach(servoPin1);
  servo2.attach(servoPin2);

  servo1.write(pos1);
  servo2.write(pos2);
}

void loop() {
  unsigned long now = millis();

  if (now - lastUpdate >= updateInterval) {
    lastUpdate = now;

    unsigned long pulse1 = pulseIn(pwmInPin1, HIGH, 25000);
    unsigned long pulse2 = pulseIn(pwmInPin2, HIGH, 25000);

    updateServo(pulse1, pos1, servo1);
    updateServo(pulse2, pos2, servo2);
  }
}

// -------- Helper Function --------
void updateServo(unsigned long pulse, int &position, Servo &servo) {
  if (pulse < 1000 || pulse > 2000) return;

  int speed = 0;

  if (pulse > center + deadband) {
    speed = map(pulse, center + deadband, 2000, 1, 10);
  }
  else if (pulse < center - deadband) {
    speed = map(pulse, 1000, center - deadband, -10, -1);
  }

  position += speed;
  position = constrain(position, 0, 180);
  servo.write(position);
}