read pwm values

i used a code to work with futaba transmitter it works well but when i change to radiolink transmitter it doesnt work at all. whats wrong? pls help. thanks!

#include <Servo.h>
#include <NewPing.h>


Servo AIL;
Servo ELE;
Servo THR;
Servo RUD;
//Servo AUX1;
//Servo AUX2;

int AIL_PIN = 2;
int ELE_PIN = 3;
int THR_PIN = 4;
int RUD_PIN = 5;
//int AUX1_PIN = 6;
//int AUX2_PIN = 12;
int Throttle_Enable = 0;
int Auto_Arm = 0;
char i;
int reading;


unsigned long REC_AIL;
unsigned long REC_ELE;
unsigned long REC_THR;
unsigned long REC_RUD;
//unsigned long REC_AUX1;
//unsigned long REC_AUX2;
unsigned long REC_AIL_Total;
unsigned long REC_ELE_Total;
unsigned long REC_THR_Total;
unsigned long REC_RUD_Total;
//unsigned long REC_AUX1_Total;
#define TRIGGER_PIN  13  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     14  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 100 // Maximum distance we want to ping for (in centimeters)
#define SONAR_MAX_DISTANCE 400//Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, SONAR_MAX_DISTANCE); // NewPing setup of pins and maximum distance.

//void Auto_Takeoff()
//{
//  {
//    if (Auto_Arm == 0)
//    {
//          REC_AIL = 1090;
//          AIL.writeMicroseconds(REC_AIL);
//          
//          
//          REC_ELE = 2000;
//          ELE.writeMicroseconds(REC_ELE);
//          
//
//          REC_THR = 1090;
//          THR.writeMicroseconds(REC_THR);
//          
//
//          REC_RUD = 1090;
//          RUD.writeMicroseconds(REC_RUD);
//          
//          delay(2000);
//    }
//  
//               REC_AIL = pulseIn(AIL_PIN, HIGH, 20000);
//               AIL.writeMicroseconds(REC_AIL);
//               REC_ELE = pulseIn(ELE_PIN, HIGH, 20000);
//               ELE.writeMicroseconds(REC_ELE);
//               REC_RUD = pulseIn(RUD_PIN, HIGH, 20000);
//               RUD.writeMicroseconds(REC_RUD);
//               delay(1000);
//          
//          if(reading < MAX_DISTANCE) //auto takeoff, throttle up
//          {
//               REC_THR = 1570;
//          
//          }
//                  
//          if (reading > MAX_DISTANCE)
//               {
//               
//                   REC_THR = 1450;
//                  
//               }
//          if (reading==MAX_DISTANCE)
//          {
//               
//                   REC_THR = 1520;
//                  
//               }
//               
//               THR.writeMicroseconds(REC_THR);
//          }
//               
//               
//               
//               Auto_Arm = 1; 
//               Throttle_Enable = 1;
//             
//  
//}

void setup()
{
  Serial.begin(9600);
  
  
  pinMode(AIL_PIN, INPUT);
  AIL.attach(6);
  pinMode(ELE_PIN, INPUT);
  ELE.attach(7);
  pinMode(THR_PIN, INPUT);
  THR.attach(8);
  pinMode(RUD_PIN, INPUT);
  RUD.attach(9);
//  pinMode(AUX1_PIN, INPUT);
//  AUX1.attach(11);  
}



void loop()
{
     
   delay(50);    // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
  reading = uS / US_ROUNDTRIP_CM;
  //Serial.print("Ping: ");
  Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)
  Serial.println(" cm");

                  
    REC_AIL_Total = 0;
    for(i=0;i<3;i++)
    {
      REC_AIL = pulseIn(AIL_PIN, HIGH, 20000);
      REC_AIL_Total = REC_AIL_Total + REC_AIL;
    }
    REC_AIL = REC_AIL_Total / 3;
    AIL.writeMicroseconds(REC_AIL);
    
    /*Serial.print(REC_AIL);
    Serial.print("\n");*/

  
    REC_ELE_Total = 0;
    for(i=0; i<3; i++)
    {
      REC_ELE = pulseIn(ELE_PIN, HIGH, 20000);
      REC_ELE_Total = REC_ELE_Total + REC_ELE;
    }
    REC_ELE = REC_ELE_Total / 3;
    ELE.writeMicroseconds(REC_ELE);
    
    /*Serial.print(REC_ELE);
    Serial.print("\n");*/
    
    if(Throttle_Enable == 0)
  {
    REC_THR_Total = 0;
    for(i=0; i<3; i++)
    {
      REC_THR = pulseIn(THR_PIN, HIGH, 20000);
      REC_THR_Total = REC_THR_Total + REC_THR;
    }
    REC_THR = REC_THR_Total / 3;
    THR.writeMicroseconds(REC_THR);
  }
    
    /*Serial.print(REC_THR);
    Serial.print("\n");*/



      
    REC_RUD_Total = 0;
    for(i=0; i<10; i++)
    {
      REC_RUD = pulseIn(RUD_PIN, HIGH, 20000);
      REC_RUD_Total = REC_RUD_Total + REC_RUD;
    }
    REC_RUD = REC_RUD_Total / 10;
    RUD.writeMicroseconds(REC_RUD);
    
    /*Serial.print(REC_RUD);
    Serial.print("\n");*/
    
//     REC_AUX1_Total = 0;
//    for(i=0; i<3; i++)
//    {
//      REC_AUX1 = pulseIn(AUX1_PIN, HIGH, 20000);
//      REC_AUX1_Total = REC_AUX1_Total + REC_AUX1;
//    }
//    REC_AUX1 = REC_AUX1_Total / 3;
//    AUX1.writeMicroseconds(REC_AUX1);
//      
//      
            
      
    Serial.print("\t AIL: "); 
    Serial.print(REC_AIL);
    
    Serial.print("\t ELE:  ");
    Serial.print(REC_ELE);
    
    
    Serial.print("\t THR: ");
    Serial.print(REC_THR);
    
    
    Serial.print("\t RUD: ");
    Serial.print(REC_RUD); 
   
 
}

22550077:
it doesnt work at all. whats wrong? pls help. thanks!

The Radiolink apparently updates servos at a much higher rate. The servos have to be digital to accept this fast refresh rates. I'm not real sure if the faster refresh rates are getting to the servos since the program appears to average multiple pulses before passing the pulse on.

I'm curious what this program controls. It seems like whatever is being controlled would have a relatively long delay between control inputs and response to these inputs.

Does the program display serial output?

ya it display serial output.

22550077:
i used a code to work with futaba transmitter it works well but when i change to radiolink transmitter it doesnt work at all. whats wrong? pls help. thanks

It looks like that code reads servo signals from a RC receiver. When you changed the transmitter from Futaba to Radiolink did you also change the receiver to match?!?

22550077:
it doesnt work at all.

22550077:
it display serial output.

IMO, the above two quotes contradict each other.

What output/action do you expect and what output/action to you get?

And what johnwasser asked.