how to control servo connected to receiver and arduino

Hi , I am trying to make a obstacle avoidance RC wing. But a have a issue.
I want to connect my 2 servos on my receiver and the receiver to a arduino uno.
So like that i can control the wing with a transmitter and program the servos so if a ultrasonic sensors see a obstacle the 2 servos can react and make the wing avoid the obstacle.
Can you please help me with how i connect the servos to the receiver to the arduino uno and how i program this.
I am french so sorry for my bad english and thank you in advance

I am french so sorry for my bad english and thank you in advance

Would you like this thread to be moved to the French section of the forum ?

No it's okay I understand english thx

Take a look at this thread: Failsafe, a final try - Programming Questions - Arduino Forum.

The OP was trying to get a failsafe on a model submarine so that if it didn't receive signals from the RC transmitter for a while it would automatically surface so he could recover it.

To do this, the Arduino was reading the servo signals and passing them on for the most part, but it would force a ballast blow at loss of signal.

The core code is something the OP found elsewhere and at first I really didn't get what it was doing. Hopefully the above will give you enough hints to see what it's doing and you can override your servos in the same way.

Hi jtrox04,

I want to connect my 2 servos on my receiver and the receiver to a arduino uno.

That's certainly possible, but the implementation depends on which type of RC receiver you're using: traditional multi-channel, CPPM, SBUS, DSM2/DSMX, etc...?

thank you for the answer I am using a
FSiA6B receiver

These are the specs of the receiver. Can you explain me how i have to connect it with the servos on the arduino and if there is a code to make that possible .Thx a lot
FS-iA6B Specifications:
Brand Name: Flysky
Item Name: FS-iA6B
Channel: 6
Frequency Range: 2.4055--2.475GHZ
Band Width Number: 140
Transmitting Power: ≤ 20dBm
RF Receiver Sensitivity: -105dbm
2.4G Mode: The second generation of an enhanced version of the automatic FM digital system
Encoding: GFSK
Antenna Length: 26mm * 2 (dual antenna)
Input Power: 4.0-6.5V DC
Dimension: 47 x 26.2 x 15mm
Weight: 14.9g
Color: Black
i-Bus Interface: Yes
Data Acquisition Interface: Yes
Model Type: Airplane / Glider / Helicopter
Compatible Transmitter: Compatible with FS-i4,FS-i6,FS-i10,FS-GT2E,FS-GT2G

After 3h and a half i came with this solution :
if i use a breadboard so i can link the signal wires(of the 2 servos )to the arduino and the receiver

Will it work ?

thank you a lot
(before i order all the expensive stuff to make a autonomous wing i want to be shure that everything will worl)

I would be inclined to connect the servo connections from the RC receiver to the Arduino and unless an obstacle is detected pass them through unaltered to the servos. If an obstacle is detected then interrupt the passthrough and let the Arduino take control of the servos

That way you will not have a conflict between the signals from the receiver and the Arduino as you would if they were connected in parallel

Thank you for your reply . It is exactly what i want to do but how do i code this ?(how can i make the arduino recognize the 2servos connected to the rc receiver ?)
I am sorry for all these stupid questions but i've been working on this project for weeks and i desesperate

Google "arduino rc receiver". Many people have already made projects with an RC receiver feeding an Arduino which then drives the servos.

Steve

i already did that but i don't understand . Well i will continue to search

jtrox04:
i already did that but i don't understand . Well i will continue to search

You looked at all those projects that Google found and you didn't understand anything in any of them? Then this project is probably far too difficult for you.

Steve

Yeah you're probably right but i will not surender.I will try to continue my research and keep you posted .
Well thank you and if i have any question i will come back.

Pierre

Start simply. Try to get a single servo working with the Arduino. Have it read from your receiver and pass the request to the servo. Then add an override. Once that's working, add another servo and build towards your end goal.

Yes but idk how to connect the servos to receiver to the arduino.( and code the arduino to recognize the servo when pluged to the receiver)
Anyway i will order all the stuff to make my autonomous wing and try to connect the servo to a breadboard and split the signal in 2(one to the receiver and one to the arduino) . I hope it will work. otherwise I am fucked.

Pierre

Look at the thread I gave you. IIRC, the receiver was attached to the Arduino and the Arduino to the servos. Most servo signals are just passed on, but you have the opportunity to override them.

Thank you I am gonna try

Hi jtrox04,

Here's some example code that receives the airelon and elevator receiver channels on digital pins D2 and D3 respectively. The code uses interrupts to time the rising and falling edges of each channel using the micros() function to measue the incoming pulse widths. This pulse width information is then passed back to the loop() where it it loaded into timer 1's A and B outputs on digital pins D9 and D10 to be output as PWM at 50Hz. These outputs independently control the two servos.

Note that the servos must be powered from a separate 5V supply. The Arduino's voltage regulator is unable to power two servos directly. Only the Arduino's PWM outputs are and common ground are connected.

Here's the code:

// Control 2 servos from RC receiver airelon and elevator channels
#define AIRELON_PIN 2
#define ELEVATOR_PIN 3

struct Pulsewidth                             // Receiver pulsewidth sturcture
{
  unsigned long airelon;
  unsigned long elevator;
} pulsewidth;

volatile Pulsewidth isrPulsewidth;            // Volatile callback function pulsewidth structure

void setup() 
{
  ////////////////////////////////
  // Receiver initialisation
  ////////////////////////////////
   
  pinMode(AIRELON_PIN, INPUT);                // Configure the receiver pins as inputs               
  pinMode(ELEVATOR_PIN, INPUT);  
  attachInterrupt(digitalPinToInterrupt(AIRELON_PIN), calcAirelon, CHANGE);        // Attach CHANGE interrupts to the receiver pins
  attachInterrupt(digitalPinToInterrupt(ELEVATOR_PIN), calcElevator, CHANGE);

  ////////////////////////////////
  // Timer1 initialisation
  ////////////////////////////////
  
  pinMode(9, OUTPUT);                         // Set digital pin 9 (D9) to an output
  pinMode(10, OUTPUT);                        // Set digital pin 10 (D10) to an output
  TCCR1A = _BV(COM1A1) | _BV(COM1B1);         // Enable the PWM outputs OC1A, and OC1B on digital pins 9, 10
  TCCR1B = _BV(WGM13) | _BV(CS11);            // Set phase and frequency correct PWM and prescaler of 8 on timer 1
  ICR1 = 20000;                               // Set the PWM frequency to 50Hz
  OCR1A = 1500;                               // Centre the servo on D9
  OCR1B = 1500;                               // Centre the servo on D10
}

void loop()
{ 
  noInterrupts();                             // Copy the callback function pulse widths values
  pulsewidth.airelon = isrPulsewidth.airelon;
  pulsewidth.elevator = isrPulsewidth.elevator;
  interrupts();
  
  OCR1A = pulsewidth.airelon;                 // Load timer1 with the pulse widths
  OCR1B = pulsewidth.elevator;
}

//////////////////////////////////
// Interrupt callback functions
//////////////////////////////////

void calcAirelon()                            // Airelon interrupt service routine
{
  static unsigned long airelonStartTime;      // Intialise timestamp
  
  if (digitalRead(AIRELON_PIN) == HIGH)       // If the interrupt is caused by a RISING edge
  {
    airelonStartTime = micros();              // Take the timestamp at the start of the pulse
  }
  else                                        // If the interrupt is caused by a falling edge
  {   
    isrPulsewidth.airelon = micros() - airelonStartTime;     // Calculate pulse width: subtract the rising edge timestamp from the falling edge
  }
}

void calcElevator()                           // Elevator interrupt service routine
{
  static unsigned long elevatorStartTime;
  
  if (digitalRead(ELEVATOR_PIN) == HIGH)
  {
    elevatorStartTime = micros();
  }
  else
  {
    isrPulsewidth.elevator = micros() - elevatorStartTime;         
  }
}

Thank you MartinL I when i will have all the electronics i will try that