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 6 Comments