Sending radio control signals from the Arduino to the throttle and the elevator servo

Greg Wilson
2 min readJan 14, 2018

--

This article, part of the Arduino Radio Control Model Plane Altitude Hold series, describes sending radio control signals from the Arduino to the aircraft controls.

Background

The Servo library does all the work for us. We just invoke it, create servo objects, link them to some Arduino pins, and then determine the size of the pulses to send.

Hardware setup

The servos are connected to +5V, GROUND and to a Arduino pin for the signal data. We could have connected an electronic speed control to the throttle pin, but since this is just an illustration, connecting a servo instead still meets our purpose.

Program

Here’s a program to demonstrate control of two servos.

We send out signals to the servos based on:

  • (rc_elevator_pulsewidth_max_out + rc_elevator_pulsewidth_min_out)/2 the midpoint of their range, plus
  • (rc_elevator_pulsewidth_max_out — rc_elevator_pulsewidth_min_out)/2 half their range multiplied by
  • sin(millis()*2*3.14/10000) a nice smooth sine function that cycles every 10 seconds.

It is the same for the throttle, but using a cos function instead.

/* Demonstrates one way to write signal data to servos. 
* We use the Servo library.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY
* OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// We'll use the Servo library
#include <Servo.h>
Servo elevator;
Servo throttle;
// Elevator
#define rc_elevator_pin_out 11
int rc_elevator_pulsewidth_max_out = 1900;
int rc_elevator_pulsewidth_min_out = 1100;
// Throttle
#define rc_throttle_pin_out 12
int rc_throttle_pulsewidth_max_out = 1900;
int rc_throttle_pulsewidth_min_out = 1100;
void setup() {
// Attach the servos tho their pins
elevator.attach(rc_elevator_pin_out);
throttle.attach(rc_throttle_pin_out);
}
void loop() {
int rc_elevator_pulsewidth_out;
int rc_throttle_pulsewidth_out;
rc_elevator_pulsewidth_out =
(rc_elevator_pulsewidth_max_out +
rc_elevator_pulsewidth_min_out)/2 +
(rc_elevator_pulsewidth_max_out -
rc_elevator_pulsewidth_min_out)/2 *
sin(millis()*2*3.14/10000);
elevator.writeMicroseconds(rc_elevator_pulsewidth_out);
rc_throttle_pulsewidth_out =
(rc_throttle_pulsewidth_max_out +
rc_throttle_pulsewidth_min_out)/2 +
(rc_throttle_pulsewidth_max_out -
rc_throttle_pulsewidth_min_out)/2 *
cos(millis()*2*3.14/10000);
throttle.writeMicroseconds(rc_throttle_pulsewidth_out);
delay(25);
}

Results

The servos sweep from side to side, across their range.

Conclusions

We can use the Servo library to control the aircraft.

--

--

Greg Wilson

Hopeless at orienteering, rubbish at flying radio controlled planes, but enjoys both activities anyway.