DIY Retract Sequencer using an Arduino.

by GremlinRC | November 18, 2017 | (0) Posted in Projects

Back in 2016 I wrote part 1 of an article explaining how a cheaply available arduino can be leveraged to make all kinds of cool stuff happen in your RC project.  Firstly I need to apologise for taking so long to get to part two.  I promised I would explain in part two how to write to a servo and in part three, to tie it all together.  Rather than make this series longer than necessary, I've decided to combine parts two and three and take this to a conclusion in this article by showing you how you can couple reading a receiver port with outputting to a servo or other device controlled like a servo (e.g. a retract).

A set of retracts make your warbird look really cool but often warbirds like the spitfire used sequenced undercarriage which has one side extending or retracting a couple of seconds in front or behind the second.  You can of course buy a retract sequencer from your LHS but you won't have full control over the exact sequence and timing.


Enter the arduino.  This device has revolutionised many aspects of hobby electronics over the past few years, from robotics to automation and of course our beloved RC.  Arduino's allow people with limited electronics skills to build incredible projects which would have taken years of experience and a couple of masters degrees in electronic engineering previously.

Here's our arduino retract sequencer in action



What You will need.

  • Electric retracts
  • Arduino Pro Mini.
  • A BEC (Battery Eliminator Circuit)
  • Several extension leads to be built into a wiring harness.
  • Serial Port programmer for the Pro Mini
  • Soldering practice.


It the case of the wiring it would be better if you have the ability to crimp your own JST connectors to RC servo wire.  Otherwise look at the diagram below and splice some together to make the wiring as shown.  Note that the WHITE/RED/BLACK shown may be ORANGE/RED/BROWN on your wires.

(Click for full sized image)

The white/orange wires on servos are signal wires this takes the PWM (Pulse Width Modulated) signal from your receiver so that it can be interpreted by your servo/retract and acted on.  For our application you should cut and separate the white/orange wires on your wiring loom, which goto your retracts (Don't cut the actual retract wires, cut the wire on the lead which the retract is plugged into.)  COnnect these white/orange wires to pins 5 and 6 on your arduino.  Next take a standard extension and remove one end  connect the white/orange wire to pin 10 on the arduino and connect the black/brown wire to any port on the arduino labelled "gnd" (ground).  This lead will plug into the gear port on your RX and will send the signal to be interpreted by the arduino.  But what about the red center wire.  You can do one of two things with this.  1. connect it to the red wire coming from your BEC.  This way the BEC will provide power to your RC receiver.  If you do this, it is recommended to remove the red wire from your throttle lead from the ESC.  2, Simply remove the red wire altogether.  If you do this your ESC will power your receiver and servos but the BEC will provide power to your retracts.

As noted in part 1, you will need to get comfortable with compiling and loading code to the arduino before you begin.  You should at least be able to load the example "Blink" sketch which is included with the Arduino IDE software.

Once you have everything wired up its time to load up the code and test.  My example code can be downloaded here.  I will go through this with you shortly but for now lets get it loaded so that we can see it in action.

DOWNLOAD THE SAMPLE CODE HERE

Once loaded and verified, disconnect the programmer.  Connect your BEC to the BEC input on your new sequencer.  Connect the retracts and plug the lead with just the black/brown and white/orange lead to your receiver gear channel.  Remember, if you are testing this inside a plane, remove the prop for safety.

Power everything up and flip your receiver gear switch.  You should see something like the video at the beginning of the article.  Note the retract I used have a more scale opening speed.  Others may just flip open almost immediately.  The speed of opening cannot be controlled typically.

The Code Explained

Now that you have it up and running lets look at the code so we can understand how it works and how you can modify this to sequence your landing gear any way you can possibly imagine.

In part one I explained how to read and RX signal with arduino code, so I won't repeat that here.  Just to highlight that this is the part of the code concerned with monitoring the signal coming from your receiver port;

raw_gear = pulseIn(10, HIGH, 25000); // Read the pulse width of pin 10 (connected to gear channel signal lead)

    if (raw_gear >= 1050 && raw_gear <= 1150)

    { //see if its in the low range

      pos = 1;

    }

    if (raw_gear >= 1850 && raw_gear <= 1950)

    { //or is it in the highw range

     pos = 0;

    }

..and sets the value of pos (the variable which holds the gear position) accordingly.

Detecting the position switch change

We need to determine when this position changes so that we lower or raise the landing gear only once per flip of your radio switch.  This is done by storing the value of 'pos' into 'oldpos' and the end of the main loop.  Next time around the loop pos is read again and compared with the value of oldpos.  If these are not equal then pos has changed and its time to get some action going;

void loop

    {

        update pos (described above)

         if(oldpos != pos) //Position has changed

           oldpos = pos; (preserve the state of pos)

    } (loop around again)


Moving the Retracts

   So once we know the position switch has changed we extand or retract the landing gear as follows;

    retract1.writeMicroseconds(900);

    delay(2500);

    retract2.writeMicroseconds(900);

Retract 1 is set to have a pulse width of 900ms (close to the lower end) the retract sees this and extends/retracts

Wait 2.5 seconds

Retract 1 is set to have a pulse width of 900ms

 Those of you familiar with the servo library in arduino might ask why not just use servo.write(angle) to set the position of the retracts?  In my experience servo.write is unreliable.  servo.writemilliseconds(PWM value) works much better.  Those with servo testers with a display screen will be familar with the fact that most servos are at their lower position when the PWM signal has a pulse width of 800ms and is fully extended with a pulse width of 2200ms.  Retracts tend of activate when the pulse width enters the ranges (800 - 1200ms) and ( 1800 - 2200ms).  We set our values as 900 and 2100 that should be correct to make most retracts trigger.  If not use a servo tester with a display to find which value triggers your retracts and amend accordingly.

 You could of course swap around retract1 and retract2 to change the order they activate.  You can change the value of the delay between them to another value in milliseconds to vary the delay between retract activation.  Amend these until you get the desired behaviour. In the code I've written you will get a scale activation like you might see in a Spitfire.  The effect is better if you have slow opening retracts.  Unfortunately you can't partially extend or retract most units.  It's just simply fully lowered or fully raised

I hope you learned something from this series of articles and more importantly, that you can clearly see just how cool arduino's are and how useful they can be in the context of the RC hobby.  If you get stuck or have any questions just drop a comment below and I'll do my best to answer.  Until then, as they say in all the best Flitetest episodes, go fly with a friend and make some memories!


COMMENTS

No Comments Yet

Be the first to leave one!

You need to log-in to comment on articles.


DIY Retract Sequencer using an Arduino.