RC reciever to analog 0-5 voltage

Hi people

I really need your help.

I need to convert from RC reciever input to analog 0-5V output using the arduino

can someone tell me how write a code?

p.s
I know I have to connect lowpass filter to the analog output for steady Vout

const int receivePin = 2;  // The pin connected to the RC receiver's servo output
const int outputPin = 3;  // Output PWM pin
unsigned long pulseLength = constrain(pulseIn(receivePin, HIGH), 1000, 2000);
analogWrite(outputPin, map(pulseLength, 1000, 2000, 0, 255));

Alternativley, using interrupts -

More Channels -

Then for 5 volt output -

Then when you find that your transmitter does not use the exact range 1000 to 2000 us and you need to calibrate -

Duane B

rcarduino.blogspot.com

And for two channels (with RC output pulses of 1000 to 3000 uS instead of 1000 to 2000):

const int inputPinA = 2;  // The pin connected to the RC receiver's servo output A
const int outputPinA = 3;  // Output PWM pin A
const int inputPinB = 4;  // The pin connected to the RC receiver's servo output B
const int outputPinB = 5;  // Output PWM pin B

void setup() {
    pinMode(inputPinA, INPUT);
    pinMode(inputPinB, INPUT);
}

void loop() {
    unsigned long pulseLength;

    pulseLength = constrain(pulseIn(inputPinA, HIGH), 1000, 3000);
    analogWrite(outputPinA, map(pulseLength, 1000, 3000, 0, 255));

    pulseLength = constrain(pulseIn(inputPinB, HIGH), 1000, 3000);
    analogWrite(outputPinB, map(pulseLength, 1000, 3000, 0, 255));
}

If you want to miss more than half of the information in the RC Signal this is fine.

If your interested in why you miss half this information, here is why, its also the reason why I prefer using interrupts, the situation gets worse for each channel that you add because pulse in can only look at a single channel at a time meaning that you are forced to ignore any other information in the signal.

// wait for channel  0
pulseLength = constrain(pulseIn(inputPinA, HIGH), 1000, 3000);
// do something time consuming guaranteeing that we miss channel 1
analogWrite(outputPinA, map(pulseLength, 1000, 3000, 0, 255));

// now wait for channel1, channel 0 will come and go without us seeing it because now we aren't even looking for it 
pulseLength = constrain(pulseIn(inputPinB, HIGH), 1000, 3000);
// do something time consuming to guarantee that we miss channel 0
analogWrite(outputPinB, map(pulseLength, 1000, 3000, 0, 255));

// and repeat

Duane B

rcarduino.blogspot.com

Hi people.

OK. John's code works good
the only problem is that if I move the RC transmitter stick from full right to full left I get about two seconds respond time.
anyone knows how to improve that?

the code:

const int inputPinA = 2; // The pin connected to the RC receiver's servo output A
const int outputPinA = 3; // Output PWM pin A
const int inputPinB = 4; // The pin connected to the RC receiver's servo output B
const int outputPinB = 5; // Output PWM pin B

void setup() {
pinMode(inputPinA, INPUT);
pinMode(inputPinB, INPUT);
}

void loop() {
unsigned long pulseLength;

pulseLength = constrain(pulseIn(inputPinA, HIGH), 1000, 2000);
analogWrite(outputPinA, map(pulseLength, 1000, 2000, 0, 255));

pulseLength = constrain(pulseIn(inputPinB, HIGH), 1000, 2000);
analogWrite(outputPinB, map(pulseLength, 1000, 2000, 0, 255));
}

shahar:
the only problem is that if I move the RC transmitter stick from full right to full left I get about two seconds respond time.
anyone knows how to improve that?

Perhaps the low-pass filter you use for converting PWM to a voltage has too large a capacitor or too large a resistor. Sounds like the frequency cut-off is closer to 0.5 HZ than, say, 100 Hz.