Using an Arduino to detect multirotor's RC input

Posted on 20 December 2018

So I had a setup where I had an R9DS RC receiver connected to a Librepilot CC3D with SBUS and I wanted to control two servos with an accessory channel switch on my transmitter. I needed the servos to trigger, but reversed to each other when I flipped the accessory switch on. I figured out it was pretty impossible to do on the CC3D, so here’s how I did it with an arduino nano. NOTE: The exact method I used only works when your receiver can output the channel on SBUS and PWM simultaneously, the arduino will listen to PWM.

  1. Wire up 5v power to the arduino nano and servos
  2. Wire the PWM channel to a digital input on the arduino
  3. Upload this to arduino to see what the on/off PWM values for are by watching the serial window as you flip the transmitter accessory switch
byte PWM_PIN = 3;
 
int pwm_value;
 
void setup() {
  pinMode(PWM_PIN, INPUT);
  Serial.begin(115200);
}
 
void loop() {
  pwm_value = pulseIn(PWM_PIN, HIGH);
  Serial.println(pwm_value);
  //delay(500);
}

Now you can determine what state the remote acessory switch is in with pulseIn. Here’s my use case:

{

#include <Servo.h>

Servo LeftServo;  // create servo object to control a servo
Servo RightServo;

void setup() {
  pinMode(3, INPUT);
  LeftServo.attach(9);  // attaches the servo on pin 9 to the servo object
  RightServo.attach(10);
}
void OperateJaw(bool isOpen)
{
  if(isOpen)
  {
    LeftServo.write(180);
    RightServo.write(0);
  }
  else
  {
    LeftServo.write(0);
    RightServo.write(180);
  }
}
int pwm_value;
void loop() {
  pwm_value = pulseIn(3, HIGH);
  if(pwm_value > 1200)
    openState = false;
  else
    openState = true;
  OperateJaw(openState);
}