servo controlling

Hello everybody!
I've got a projet to control 4 servo with my rc receiver, I want to use 3 "axis" on my rc remote control, 2 on a joystick to control 2 servo on a time the third axis would be a switch. When the switch is on the servo 1 and 2 would be controled by the joystick and when the switch is off the servo 3 and 4 would be controled. some one knows how to do that with an arduino nano?

Thanks Lucas.

Your description is quite confusing.
If I read it correctly the Arduino is to be be wired between the RC receiver and the servos. Is that right ?

If so, wire one channel of the receiver to the Arduino using 5V, GND and a digital pin. Then use the pulseIn() function on that pin like this

byte receiverPin = 7;
unsigned long duration;

void setup()
{
  Serial.begin(115200);
  pinMode(receiverPin, INPUT);
}

void loop()
{
  duration = pulseIn(receiverPin, HIGH);
  Serial.println(duration);
  delay(100);
}

The duration should vary as you move the transmitter stick for the channel being monitored. Once that works you can consider expanding to more channels and passing the duration to servos driven by the Arduino.

So what do you want to happen to the servos that are currently de-selected? Keep
their last value or go to some default?

You'll probably have to put up with some jitter using pulseIn as the Servo library
interrupt may affect it. Putting the incoming servo lines on pin-change interrupt
might allow better timing acquistion, but that interrupt handler may affect the outgoing
servo pulses(!)

If you forgo the Servo library completely and use a pin-change interrupt handler to
both acquire timing for the control channel and copy the pulses out to the 4 output
channels from the 2 joystick channels you are more likely to get jitter-free behaviour.

Thanks to both of you!
I did a wee diagram cause i'm not really good with English,
as MarkT said it would be, I suppose, better if the signal of the rc receiver is not "damaged" so I guess, I don't really want to control the servo through the arduino board but just switch the control signal from a servo to another. Like a 2 position switch that would be controlled by my ch1. in the first position (I) the signal is going the a servo and in the second position (O) the signal is going to another servo...
I presume with this configuration I can't control the behavior of the servos that are de-selected, the must would be to go back to the neutral position...

I really sorry if I ask too much, I'm a really beginner whith arduino stuff and I'm not sure if I can do all that by myself...

Sorry for my English... :blush:

If you want to switch the servo outputs from one set of servos to another then using a relay or relays would be the easiest way to do it. Either using relays or direct control of the servos via the Arduino you could arrange for the deselected servos to move to a position of your choosing when they are deselected. If using relay(s) the deselected servos would receive no signal when deselected and could move if a force is applied to their output arms but that need not be the case using direct control.

Another thought. If you don't mind a quick and dirty solution you could use a servo to change the position of a physical switch to select one set of servos or another.

Thank you!
Relays is an easy solution, i'm not sure if I can do something complex right now I need to learn more about arduino stuff.
I'm gonna try like that thank you again!

Hey again,

I found a tuto to control a servo via a rc controller, i modified it do do what I wanted

//Included Libraries
#include <Servo.h>

// Define Variables:
const int chA=7;  //Constant variables relating to pin locations
const int chB=8;


//Signal Conditioning limits
const int lo=1150;
const int hi=1950;
const int deadlo=1480;
const int deadhi=1540;
const int center=1510;

int ch[2];  //Array to store and display the values of each channel
int ch4;  //Servo Output Variable


Servo steer;
Servo steer1;//Steering Servo

// the setup routine runs once when you press reset:
void setup()
{
  // initialize serial communication at 9600 bits per second:
  Serial.begin(115200);
 
  //Input Pins:
  pinMode(chA,INPUT);
  pinMode(chB,INPUT);

  //Servo Outputs:
  steer.attach(11);      //Attach Steering Servo to PWM Pin 2
  steer1.attach(5);

}

//Main Program
void loop()
{
  // read the input channels
  ch[0] = pulseIn (chA,HIGH);  //Read and store channel 1
  ch[1] = pulseIn (chB,HIGH);
  
 
  //Input Signal conditioning
  for (int i=0; i<=2; i++)      //Signal Conditioning loop
  {
   if (ch[i] <= lo)             //Trim Noise from bottom end
   {
    ch[i] = lo;
   }
  
   if (ch[i] <= deadhi && ch[i] >= deadlo)     //Create Dead-Band
   {
    ch[i] = center;
   }
  
   if (ch[i] >= hi)            //Trim Noise from top end
   {
     ch[i] = hi;
   }
  }
 
  //Steering Control Output on Channel 4
  if (ch[1]>= lo && ch[1]<= deadlo)
  {
  ch4 = ch[0];
  if (ch4 >= lo && ch4 <= deadlo)
  {
    ch4 = map(ch4, lo, deadlo, 0, 90);
  }
  else if (ch4 == center)
  {
    ch4 = 90;
  }
  else if (ch4 >= deadhi && ch4 <= hi)
  {
    ch4 = map(ch4, deadhi, hi, 90, 180);
  }
  steer.write(ch4);
  
  }
  
   if (ch[1] >= deadhi && ch[1] <= hi)
  {
  ch4 = ch[0];
  if (ch4 >= lo && ch4 <= deadlo)
  {
    ch4 = map(ch4, lo, deadlo, 0, 90);
  }
  else if (ch4 == center)
  {
    ch4 = 90;
  }
  else if (ch4 >= deadhi && ch4 <= hi)
  {
    ch4 = map(ch4, deadhi, hi, 90, 180);
  }
  steer1.write(ch4);
  }
 
//Serial Outputs
  Serial.print ("Ch1:");  //Display text string on Serial Monitor to distinguish variables
  Serial.print (ch[0]);     //Print in the value of channel 1
  Serial.print ("|");
  Serial.print ("Ch2:");
  Serial.print (ch[1]);
  Serial.print ("|");

  Serial.print ("Steering Output1:");
  Serial.println (ch4);
   
}

chB is my switch so or i use steer1.write(ch4); or steer.write(ch4);

is it good ? cause it does work...
I want to control an RC plane with this batch of servo, in normal position chb =0 i can control my plane when chb is 1 i control my FPV camera so i can look around, will i have any problems when flying?

Servo steer;
Servo steer1;//Steering Servo

So, what's the other one for? Do you count 1, 2, 3, or do you count yep, 1, 2? If you number one, number them all!

How many of your global variables need to be global?

hB is my switch so or i use steer1.write(ch4); or steer.write(ch4);

is it good ? cause it does work...
I want to control an RC plane with this batch of servo, in normal position chb =0 i can control my plane when chb is 1 i control my FPV camera so i can look around, will i have any problems when flying?

No idea, since your code doesn't have a chB or a chb.

hey PaulS thank for your answer,
Servo steer; is supossed to control my servo n°1 and Servo steer1; for my second servo, i'm doing it with only 2 servo for yet.

"How many of your global variables need to be global?"
I'm sorry but i don't understand the question i'm a beginner i just modify the part of a code that I found on the web.

No idea, since your code doesn't have a chB or a chb.
yeah CHB= CH[0]=CH4

I'm a bit confused now...

I took the code from here :http://www.instructables.com/id/RC-Control-and-Arduino-A-Complete-Works/?ALLSTEPS

So, what's the other one for? Do you count 1, 2, 3, or do you count yep, 1, 2? If you number one, number them all!

Tell it to the arduino folks with their Serial.xxx , serial1.xxx, Serial2.xxx etc.
Yea I know, they didn't want to break old code (unlike their decision on IDE 1.x breakage)
It's not a perfect black and white world we live in, especially if we have to use or share code others write for us. :wink: