InfoHole A blog by Gordon Page

13Jul/106

Arduino Mega 2.4Ghz R/C Receiver Code

Since posting this video, a few people have been asking for the source code. I don't have that exact code available still, but here is some code which takes 3 input values from an R/C receiver and outputs them to the screen.

I took this code from another of my projects, and just deleted all the non-relevant code. I may have inadvertently deleted parts of the code that I shouldn't have, so if you have come across any errors just leave a comment below with details and I'll fix it.

#include

//these store the current transmitter positions/values
unsigned long transmitterThrottlee=0;
unsigned long transmitterLeftRight=0;
unsigned long transmitterForwardBack=0;

void setup()
{
pinMode (8, INPUT);
pinMode (9, INPUT);
pinMode (10, INPUT);

Serial.begin(57600);
Serial.println("Done with setup");
}

void checkTransmitter()
{
transmitterThrottlee = (pulseIn (9, HIGH, 100000))/10; //read RC channel, wait max of 0.1 seconds for pulse
transmitterLeftRight = (pulseIn (8, HIGH, 100000))/10; //read RC channel, wait max of 0.1 seconds for pulse
transmitterForwardBack = (pulseIn (10, HIGH, 100000))/10; //read RC channel, wait max of 0.1 seconds for pulse
}

void loop()
{
checkTransmitter();//check the data being received by the transmitter.
Serial.print ("data: ");//if we decrease altitude we should check for landing, and slow our decent when we get close to the ground.
Serial.println (transmitterThrottle);
Serial.println (transmitterLeftRight);
Serial.println (transmitterForwardBack);

delay (200);
}

Filed under: Robotics Leave a comment
Comments (6) Trackbacks (0)
  1. Thanks for the code. Are the lines in setup() commented correctly?
    I’m surprised this isn’t easier… someone needs to make a shield and a library.

  2. No, they were not. Sorry, just a quick copy, paste, and edit job. I’ve removed the incorrect comments. Simply connect your RX leads to the arduino pins mentioned.

  3. i’m not able to read receiver’s outputs with your code! please help us!

  4. Post your code at http://www.putcode.com and take a photo of your wiring setup. Post back here and I’ll take a look.

  5. hi!, thnx for the answer.

    i have simply used your code! i have connected the receivers’s CH1 pins to arduino, black to ground, red to 5v and yellow to one digital pins. i have loaded the sketch and started the terminal; the results: only random numbers.

    there is a way to capture receiver’s output signals with arduino and make it usable with other arduino’s piece of code??

  6. Does this also work with the Arduino UNO? I am a beginner and this is my first try. I want to use Arduino to improve my rc glider planes. Do i have to use the PWM pins for input?


Leave a comment


No trackbacks yet.