Pages: [1]   Go Down
Author Topic: RC reciever to analog 0-5 voltage  (Read 2085 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8855
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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));
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 22
Posts: 1675
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Alternativley, using interrupts -

http://rcarduino.blogspot.com/2012/01/how-to-read-rc-receiver-with.html

More Channels -

http://rcarduino.blogspot.com/2012/04/how-to-read-multiple-rc-channels-draft.html

Then for 5 volt output -

http://rcarduino.blogspot.com/2012/05/rc-arduino-robot.html

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

http://rcarduino.blogspot.com/2012/05/interfacing-rc-channels-to-l293d-motor.html

Duane B

rcarduino.blogspot.com
Logged


Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8855
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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, 3000);
    analogWrite(outputPinA, map(pulseLength, 1000, 3000, 0, 255));

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

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 22
Posts: 1675
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Code:
// 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
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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));
}


Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8855
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Pages: [1]   Go Up
Jump to: