File Exchange

image thumbnail

RC Receive Driver Block for Arduino

version 15.2.01 (2.23 MB) by Sergio Biagioni
Control an Arduino robot using an RC Transmitter and Receiver with Simulink


Updated 05 Oct 2015

View Version History

View License

With this block, a user can use Simulink to generate code for an Arduino which receives signals from an RC Transmitter.
When the output of an RC Receiver is connected to an Arduino, this custom driver block outputs the length of the RC signal's pulse in microseconds, which corresponds directly to the signal's value.

This material is meant to support the article "R/C Controller for Arduino and Simulink".

For examples and documentation showing how to use block, see the "Supplemental Software" section of the main doc page. There will be link to the "Arduino RC Receive Toolbox".

Legacy Code:
To access the old version, type the following command after installation:

This driver block was tested with the Cirrus-DPR-4FM Transmitter and Receiver. All Receivers output servo protocol so the block will work with all RC Transmitter/Receivers.

The block works with the Arduino Uno, Mega 2560, and Due. The maximum channels supported is 6.

Cite As

Sergio Biagioni (2021). RC Receive Driver Block for Arduino (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (22)

Thomas Christ

Works Great!!! Thanks! I would recommend this block to be part of the arduino toolbox!

Ömer Abdo

Hello Mr. Sergio Biagioni
Thank you for this great work. I have created fixed wing SS blocks in SIMULINK. At the end, I decided to use rc controller instead of joystick in order to have live input. The problem now is that the code you made sir works for (discrete time) while state space matrises and PID controller I designed works in (continuous time). I tried to change it from (RC Receiver) block but it rejected to change. Is it possible to change (sfcn_rcreceive_wrapper) codes to get a (continuous time) output? May you help me please?


Going to answer my own question in case it helps anyone else getting this to work on NANO. Not only did I have to make sure "#if defined" included my board and the correct pin assignments, but I also had to use "digitalPinToInterrupt()" instead of "getIntNum()" where the interrupts are attached. The atMega lines read attachInterrupt(getIntNum(pins[idx]), calc0,CHANGE). For the Nano, changing it to say attachInterrupt(digitalPinToInterrupt(pins[idx]), calc0,CHANGE). Worked flawlessly


Was wondering if you had any tips for a newbie. I have been trying to get Arduino to read PWM signals through Simulink for some time now, but I think the Arduinos are simply not fast enough to do it simply by sampling digital inputs while running all that MATLAB stuff. I think it must use the interrupt method as you've chosen.

Trying to see if this can work with a Nano 33 IoT, which has a SAMD21, but I have very limited knowledge about code. I tried modifying the cpp to add #if defined (ARDUINO_SAMD_NANO_33_IOT), then change the case numbers to the corresponding interrupt pins (which are different) to use 2,3,9, and 10. There are more interrupt ports than that but I'll worry about that later. It compiles fine, but unfortunately those pins all show 0 value on the scope while being fed live ~1.5 ms signal at 45hz. Might you have any advice what else I might need to modify?

Engr.Saad Fareed

Thanks a lot for develpoing that much useful thing...

M Ebrahimi

HI Sergio,
you have introduced a nice solution for our big problem, cool thanx.
I used the block, it has good outputs for time constants 0.5 sec. but for simulations with small sample times such as 0.002 sec, the output has unstable values that changes between the true pwm value and values less than '500'.

Sharon Koppolu

Hi Sergio,

When I have a Arduino PWM block along with this RC Receiver block in a simulink model, the RC Receiver block is outputting random values. Can you please let me know if you are aware of this issue?

Edgar Hernandez

Hi Sergio!

I will start a project and I need the RC Receiver Driver Block function in Matlab R2014b.

Could you send me please?

My email is


Zakarya Motea

i have 2 simulink models, one for controller (external mode) using DUE Arduino and one for the quad rotor dynamic model (deployed on Mega Arduino). now on which simulink model i should place this RC Receiver block?



I'm having a problem with this driver: it only works in external mode. If I just deploy it to my Uno, it never calls the step function. I had a similar problem when I tried to use the MATLAB System block to build an AF Motor shield driver, and was told I would need to write tlc code to make it work.


Thomas Wegele

Hi Sergio,
I´m using an Atmega328. I tried now the atmega2560 as used in the example and that one works fine.
Do you have another idea why it shouldn't work with an arduino nano?
By the way in the future i'm looking into the arduino micro due to four possible interrupt pins.
Is the block working with the micro as well?
Thanks a lot

just in case the reply might be longer .-)

Sergio Biagioni

Hi Thomas,
Does your Arduino Nano have an ATmega168 or ATmega328 processor?


Thomas Wegele

Hi Sergio,

i was just wondering whether the block works with an arduino nano as well;
All my test on the INT-Channel Pin3 and the PWM Pin6 didn't work fine.
Maybe you have a small advice to look at.


Sergio Biagioni

Hi Sean,
Great to hear. Since you are using the Arduino Uno, you should specify only two pins in the block, 2 and 3.


sean cleary

Hey Sergio,

Thanks for your help previously, all working fine now.

Just wondering, I'm going to use an arduino uno with this block which only has 2 pins available compared to the 4 for the arduino mega. If I use just 2 pins, do I need to modify the code at all? should i just input 2 pins or input 4 pins(where the last 2 are random)


sean cleary

Thanks very much for that Sergio

sean cleary

Hi Sergio,

Thanks very much for this.

Though I am stuck on windows XP at the moment and am having trouble getting Window SDK for it for use with the rc reciever block. Any advice*?


Sergio Biagioni

Hi Andrea,
You could just copy everything I did with channels 0-4 and expand necessary arrays. I would do it for you but I don't have a 6 channel tx/rx on hand at the moment to test. The specific steps are as follows;

1. Open RC Receive Driver Block
2. Change Data Properties->Output ports "Rows" to 6
3. In Libraries, change definition for rcc to:
volatile rcChannel rcc[6] = {{0,1,0,0}, {0,2,0,0}, {0,3,0,0}, {0,4,0,0}, {0,5,0,0}, {0,6,0,0}};
4. In Libraries, add void calc4 and calc5 interrupt service routines, just as calc0-4 were defined
5. In Outputs, change duration vector to the following:
static uint16_t duration[6] = {0,0,0,0,0,0};
6. In Outputs, add updateflag "if statements" for channels 4 and 5
7. In Outputs, add out[4] = duration[4] and out[5] = duration[5]
8. In Discrete Update, add attach interrupts for calc4 and calc5
9. Build the S-Function builder block
10. Run modify('sfcn_rcreceive')


Great work Sergio! At now I'm working with four channels, how can I upgrade your block to six channels?



Sergio Biagioni

The test model was built in R2013b. If you're using a previous version of MATLAB (i.e. R2013a), you could receive an error if you try to run the model in external mode.

Error Message Example:
Error occurred while executing External Mode MEX-file 'ext_comm':
Expected 1xN string array for host name

To resolve this, create a new model and copy the RC Receive block into it.



MATLAB Release Compatibility
Created with R2015b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: Device Drivers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!