Use an Arduino to Achieve Custom RC functions.

by GremlinRC | July 10, 2016 | (8) Posted in Projects

Arduino's are incredibly useful devices. They are versatile and easy to programme.  They are ideally suited to RC usage.    Tiny arduino devices are now available for as little as $3 dollars on ebay and you can really use them to add some pizazz to your FT build.


In this series of articles I will explain by using a custom gear sequencer as an example.  In this first article we will look at how to read the state of the gear switch and then in a later article, in part two, I will explain how to use this information to cause the arduino to sequence a set of retracts and in part three we will put what we've learned together to cause the custom retract operation to run from your radio. I should add at this point that it is not the objective of this article to teach arduino programming but I will attempt to explain the key concepts which relate to the subject matter.

So what can you do with these in the context of the RC hobby?  The answer is only limited by your imagination but a couple of examples would be to make a custom gear sequencer or maybe a fancy LED light sequencer.  You could even add sensors which trigger events or sequences of events, e.g. lights which turn on only when the ambient light level falls below a defined threshold. You can read any of the outputs from your receiver process that information and use that information do make servos and other add on devices do real world things.

Part 1 of 3 - Reading the Receiver's output.

An Arduino Pro Mini is just 33mm by 18mm

So what will you need?

You will definitely need an Arduino.  They come in many flavours but for RC applications we probably want to keep things as small as possible.  I'm using an Arduino Pro Mini as it measures just 33 x 18mm and weights practically nothing.  It has plenty of input/output pins to cover pretty much any application.  These can be had directly from China for as little as $3. There is a caveat here.  Some of the Pro Mini "Clones" I've bought simply didn't work.  You get what you pay for!  If you choose a Pro Mini then you will also need a USB-Serial programmer board as these do not have an inbuilt USB-Serial converter as most other arduino's do.  If you need to get a programmer board look for "FTDI232 arduino programmer" on ebay. I can't cover all of the variations of Arduinos in one article so everything here on will relate to the Pro Mini.

You will also need a few male - male servo extensions
Make sure you have downloaded and installed the Arduino IDE.

Before proceeding further you will need to be comfortable with programming your arduino.  You should be at a minimum capable of programming the example "Blink" sketch successfully.  If you dont know how to do this, go off to the arduino site and learn how to do that much and then come back to this article.

You will also need a receiver, and esc and a battery for testing and learning. Ok so were through all of that, you have everything you need lets get started by hooking up your receivers gear channel to the arduino.

 

Start by taking a Male-Male servo extension and unhook the plug on one side (as per the picture above).  Tape away the red lead as you wont be needing it and you don't want it floating around and accidentally creating a short.  Hook up the white lead to a free digital input pin.  You can use any digital pin but in this example we'll use pin 10.  (note: all the pin numbers are marked on the back of the arduino) A tip here: look at the schematic for your device and note that some pins are labeled as PWM and some are not.  For reading an RX you can use either, but you might want to save those PWM pins for outputting to a servo later.  Therefore you should connect inputs from the receiver to a non-pwm pin and save those precious PWM pins for contolling servos.  Connect the black lead to a pin marked GND on your arduino.

In this example we use Pin 10 on the pro mini to read the output from the gear channel on a receiver

Using a breadboard and a couple of header pins for learning and testing can greatly speed up the process of making the right connections.  You can solder the leads directly to the board (carefully) when you're ready to install your finished application inside your model

Here it is all hooked up (remember to tape off that red lead) (the red device on top is the FTDI232 programmer)


Powering the arduino inside your model.  You will note that in my pictures the arduino is powered from the FTDI232 board which in turn is powered from the USB cable.  Of course, inside a model you won't have a USB port so you will need to power your arduino from a spare RX channel (or a separate BEC). Start by taking an extension lead and remove the white wire.  Connect one end to the arduino mini as shown in the picture.  If you look under the board you will see two pins marked as VCC and GND. Make sure you connect the red wire to VCC and the Black to GND.  You can now connect the other end of the extension and your arduino will draw its power from your receiver/esc

This shows the two pins to provide power to from any free rx channel or alternatively use a separate 5v BEC.  An arduino draws just a couple of hundred milliamps.  Only use 5v and ensure red goes to VCC and black to GND. Get this wrong and you'll probably fry your arduino!

Next up power up and bind your receiver to your tx radio.  Mine's a Spektrum DX8.

We'll need to program the arduino to read the receiver's output but before we do that lets look at what the receivers output actually is.  The output of the receiver is a "Pulse Width Modulated" signal. What does that mean?  It's quite simple really the receiver issues a sequence of pulses at very regular intervals, the length of these pulses changes depending on the position of the actual control on the radio.  The image below shows what an oscilliscope sees when connected to a receiver channel and the stick/switch position is changed.

When the control is moved it the receiver converts the position and emits pulses of varying width.  Note the frequency of the pulses does not change, i.e. the pulses still begin the same time distance apart.

If we could measure the width of the pulses then we could determine the position of the control.  Thankfully the arduino core library has the capability to do that using a function called pulseIn.  Without further ado, download my sample code (rx_read_example), unzip it and load it up onto your arduino.  Once you're powered, open the arduino serial monitor, you should be seeing the raw numeric output of the gear channel echoed in the serial terminal.

 

The value will not be exactly the same each read cycle, but if your radio is decent, it should only change slightly.  Now flip the gear switch on your radio and you will see the values change significantly. On my setup the value changes from ~1900 with the switch at position 0 to ~1100 with the switch as position 1.

Now that we can read the raw value from the RX lets do something with it and convert that into a switchstate on the receiver.

Download/unzip and program sample program (rx_read_example2) which expands on the first program and open the serial monitor once powered and connected to your radio. Now when we flip the gear switch we see the output change from 0 to 1 and vice versa.  The switch state is now stored in the variable "pos" we can now use this value to cause some action to happen, like sequence our retracts.  We'll do that in part 2 of this article.


Lets take a little look at whats going on inside the program.

raw_gear = pulseIn(10, HIGH, 25000);

This is the point the width of the pulse is read.  The parameters tell the function to read the next pulse at pin 10, start when the signal goes high and 25,000 is a very long timeout value after which the function will return 0.

    if (raw_gear >= 1050 && raw_gear <= 1150){
     pos = 1;
    }
    if (raw_gear >= 1850 && raw_gear <= 1950){
     pos = 0;
    }

This part of the program takes the value just read and sees if it falls within defined ranges, if it does then it sets a position variable to be the new switch position.

Since the above code resides in the main loop of the program it repeats over and over.  Thats really all there is to reading the value of a receiver output with an arduino.  In part two we will expand on what we learned here by putting that position variable to use by sequencing a pair of retracts to open/close with a customisable delay between the first and second retract operation.

Anyway I hope you enjoyed this my first flitetest article, if you would like to see more like this, let me know.

rx_read_example.zip

rx_read_example2.zip

COMMENTS

Curmudgeon Air on July 14, 2016
Good introduction. I look forward to the rest of the series. The Arduino is one of the handiest hobbyist devices around.
Log In to reply
andy.engle@live.com on July 18, 2016
Wow! I literally JUST started accumulating some Arduino Nano's and jumping back into learning specifically for RC stuff. This is a great & timely article and I look forward to learning more!
One topic of interest: while I have been able to monitor a single receiver channel, monitoring two seems to be more challenging. I assume it has to do with the timing of the PWM coming out of the receiver and the blocking nature of the PulseIn() function. I wonder if PPM is a better approach for multi-channel projects.
Log In to reply
kkmalu on July 14, 2016
A very good article... A few more examples with arduino nano would be fantastic!
I have done a couple such small projects with arduino nano...

1) Check my afterburner with increasing throttle here:
https://www.youtube.com/watch?v=fngBRGIGr4c

2) Live painting a plane with LED lights (the regions of plane appear as though there is actual fire inside it):
https://www.youtube.com/watch?v=0XtKnEdt-Lc

I would love to see more of your projects and will do an article myself on how i did the lights on these planes with the Arduino code...


Log In to reply
Bayboos on July 13, 2016
Thank you for this article; that's exactly what I needed to get more new projects started before I complete the current ones :)
Log In to reply
ta33ers on July 22, 2016
I have been wondering if I could use an Arduino to get differential thrust working on my Spektrum DX6i, do you have any thoughts. Thanks for a great article.
Log In to reply
GremlinRC on July 23, 2016
Hi. I really don't see why not. The basic idea would be to read your throttle input in a similar manner to the way the gear switch is read in the article. This time you would output that as two PWM signals which drives the throttle on each esc (which will be described in part two). Then the trick would be to read the aileron channel and adjust each motors pwm by a suitable amount to give you the differential you need. It certainly seems like the perfect application albeit slighty more involved. Maybe when I get this sequence of articles done I'll do up a prototype and write it up.
Log In to reply
Helijatek on October 20, 2020
Hi! Nice article. Technically you can read any channel output. Now if you read, you can store it, too. Next time all you need is to disconnect or bypass the receiver and feed the stored data from the arduino. Now you got a self flying quadcopter. ... well more or less. Wish there would be more on this project. Thanks
Log In to reply

You need to log-in to comment on articles.


Use an Arduino to Achieve Custom RC functions.