Arduino between a RC reciever and speed controllers

Hello all,

First of I just want to say that I (a group of 4 but im refering it as me) am a complete noob when it comes to this things.:blush: But we have a school project and this sounded cool so i wanted to try it out.

Second of all, I have done some good amount of searching on this. But as I am a noob I am having trouble to really get everything togheter. With that said, this is my problem.

The idea for the project is that I have a RC 4WD car (1 engine and esc for every wheel). And i want the Arduino to "handle" the signals between the the reciever and esc. The future goal is to add a gyro and to be able to work some magic with this stuff and program a electronic diff, ABS and traction control. But right now im just trying to get it to work normally (full throttle on the controller = full speed on the egnines) so that the arduino just sends the signal through to the esc. I have tried different stuff like PulseIn, servos etc but its not working.

So it would be GREATLY appriciated if someone could give me some pointers on which way is the best to go with this, both now and for the future objectives. As this seems really funny but im having trouble getting this started as i have no experience. :)


Hi, Here


Or Here

Duane B

Thank you very much. That was good reading. We looked alot on the example code and we have some questions about it.

// First Example in a series of posts illustrating reading an RC Receiver with
// micro controller interrupts.
// Subsequent posts will provide enhancements required for real world operation
// in high speed applications with multiple inputs.
// Posts in the series will be titled - How To Read an RC Receiver With A Microcontroller

#define THROTTLE_SIGNAL_IN 0 // INTERRUPT 0 = DIGITAL PIN 2 - use the interrupt number in attachInterrupt
#define THROTTLE_SIGNAL_IN_PIN 2 // INTERRUPT 0 = DIGITAL PIN 2 - use the PIN number in digitalRead

#define NEUTRAL_THROTTLE 1500 // this is the duration in microseconds of neutral throttle on an electric RC Car

volatile int nThrottleIn = NEUTRAL_THROTTLE; // volatile, we set this in the Interrupt and read it in loop so it must be declared volatile
volatile unsigned long ulStartPeriod = 0; // set in the interrupt
volatile boolean bNewThrottleSignal = false; // set in the interrupt and read in the loop
// we could use nThrottleIn = 0 in loop instead of a separate variable, but using bNewThrottleSignal to indicate we have a new signal 
// is clearer for this first example

void setup()
  // tell the Arduino we want the function calcInput to be called whenever INT0 (digital pin 2) changes from HIGH to LOW or LOW to HIGH
  // catching these changes will allow us to calculate how long the input pulse is


void loop()
 // if a new throttle signal has been measured, lets print the value to serial, if not our code could carry on with some other processing


   // set this back to false when we have finished
   // with nThrottleIn, while true, calcInput will not update
   // nThrottleIn
   bNewThrottleSignal = false;

 // other processing ... 

void calcInput()
  // if the pin is high, its the start of an interrupt
  if(digitalRead(THROTTLE_SIGNAL_IN_PIN) == HIGH)
    // get the time using micros - when our code gets really busy this will become inaccurate, but for the current application its 
    // easy to understand and works very well
    ulStartPeriod = micros();
    // if the pin is low, its the falling edge of the pulse so now we can calculate the pulse duration by subtracting the 
    // start time ulStartPeriod from the current time returned by micros()
    if(ulStartPeriod && (bNewThrottleSignal == false))
      nThrottleIn = (int)(micros() - ulStartPeriod);
      ulStartPeriod = 0;

      // tell loop we have a new signal on the throttle channel
      // we will not update nThrottleIn until loop sets
      // bNewThrottleSignal back to false
      bNewThrottleSignal = true;

To be able to make this code work we have do ad our ouputs (esc). And also make the nThrottleIn (uS) into degrees for the esc to read (1ms = 0 degrees, 2 ms = 180 degrees)? Maybe some sort of maping:

map (nThrottleSignal, 1000, 2000, 0, 180)

Something like that? And then write it out to the esc?

And also we are wondering a bit why there is a "if" line inside the "else" within the void calcInput section. Whats the function with having a if-line there when there is no else-line with it so to say.

As we said, we are not good at this and appreciate every answer/help/pointers we can get from you guys.


Not sure on the mapping thing, have not dealt with RC servos and motor control. However with the if statement the "else do nothing" is implied if no explicit else instructions are given.


Regarding the mapping, no you don't need it. To figure out why, read the part 1 post again.

Duane B

Ok, thanks. I'll take a look at it again and try to figure it out.


Hey again, we got a new question about the code. we were wondering why he assigned and using two different throttle inputs in the code? He reads one and attaches the other one. Can someone please explain that? :)


Hi, He is me, Duane.

There are two basic ways to measure input times on the Arduino. One is to sit around waiting for something to happen, this is what pulseIn does, its a very basic approach that is rarely used because while you are waiting for a signal, you cant do anything else.

The other approach it to use interrupts, this allows your code to perform calculations, log inputs, generate outputs and anything else you might want. Whenever something of interest happens, you code will be 'interrupted' to deal with it.

We are not always interested in everything that might happen and so we are allowed to register our interest in specific events, the Arduino will not interrupt our code with anything we are not interested in.

We tell the Arduino we are interested through the attachInterrupt function, this says if something happens I want you to call a specific function - in my case its 'calcInput' which is called whenever the state of pin2 changes as a result of a receiver pulse starting or ending.

I suggest you read up on Arduino Interrupts and then have another look at the code, it does what you want, but there are some generally Ardiuno concepts such as interrupts that you should understand.

Duane B