(solved) problem reading data from rc receiver

i am trying to read data from a frsky rc receiver. i have an extra channel hooked to A0 on the arduino, when i open the serial monitor it is constantly sending random integers. is there something i can put in-between the signal wire from my receiver and A0 to make it stop constantly sending random integers and only send one or two? i want to be able to flip a switch on my rc transmitter and control a TIP120 hooked to a digital pin on the arduino.

Is the output from the receiver supposed to connect to a servo? If so, it is a PWM signal and the servo position is encoded as a pulse width. You hook the receiver output to a DIGITAL input and measure the pulse width with the puilseIn() function. Then set a digital output based on the pulse width ( if(PW > 1800) turn on tip120).

ill give that a try. thank you! ill post results later. im going to read up on this puilseIn() function and look at some example sketches and maybe that will work.

ok, im lost.... im trying to take pieces of code from multiple sources and make this work but im not getting anywhere.

 width = pulseIn(ch3Pin, HIGH, 30000);

this will write the pulse width, in microseconds to the variable width. The pin is low at the start and when it goes high pulseIn() will time till the pin goes low again. If there is no high going edge within 30mS (30000 microseconds) it will time out and return.
If this doesn't do what you want, post your code and the results (Serial.print(width);).

ok, whats wrong here?

int ch1;
int led;
void setup() {

  pinMode(3, INPUT);
  pinMode(13, OUTPUT);

  Serial.begin(9600);

}

void loop() {

  ch1 = pulseIn(3, HIGH, 25000);
 

  Serial.print("Channel 1:");
  Serial.println(ch1); 
  if (ch1 > 1800);
  digitalWrite(13, HIGH);
}

in the serial monitor i see: channel1 1:977 when the switch is off
and i see channel1 1:1990 when the switch is on
the LED is not coming on when the value is over 1800. did i leave something out of the code?

Couple of things but the biggy is your if statement.

if (ch1 > 1800);

the semicolon is in the wrong place.
Try this:

if(ch1 > 1800) {
     digitalWrite(13, HIGH);
}

and

int ch1;
int led;

You should give those variables values to point to the pins, they can be bytes to save sram and const so they are saved in flash not sram

const byte ch1 = 3;
const byte led = 13:

Then instead of using the pin number, refer by the variable
pinMode(ch1,INPUT);
etc.

ok i made changes

int ch1;
int led;
void setup() {

  const byte ch1 = 3;
  const byte led = 13;
  
  pinMode(ch1, INPUT);
  pinMode(led, OUTPUT);

  Serial.begin(9600);

}

void loop() {

  ch1 = pulseIn(ch1, HIGH, 30000); 

  Serial.print("Channel 1:"); 
  Serial.println(ch1);       
  if(ch1 > 1800) {
     digitalWrite(led, HIGH);
  }

Serial.println();

delay(100);
}

but now in the serial monitor it only shows this:
Channel 1:0
doesnt matter if the switch is on or off it doesnt change.

You put the const byte stuff in void setup().
They are out of scope for void loop(). I'll leave it to you to look up variable scoping.
Put them before setup in place of the int declarations (int ch1;).

ok i replaced them but now i get an error on   ch1 = pulseIn(ch1, HIGH, 30000);

it says
" in function 'void loop()':
error: assignment of read-only variable 'ch1' "

i feel like we are getting close lol
im sorry for all the fuss. i need to brush up on my arduino language lol

You are trying to write the pulse width to the variable that names a pin. My example use the variable width to hold pulse width.
It can be an int cause it won't ever be bigger than 32000.

int width = pulseIn(ch1, HIGH, 30000); 
  Serial.print("Channel 1:  "); 
  Serial.println(width);       
  if(width > 1800) {
     digitalWrite(led, HIGH);

We will make it. I have this fresh in my mind cause I just used it for motor control on my RC paddlewheel tow boat.

well now the serial monitor shows 982 with the switch on or off.

Let' see the code.

const byte ch1 = 3;
const byte led = 13;
void setup() {

  const byte ch1 = 3;
  const byte led = 13;
  
  pinMode(ch1, INPUT);
  pinMode(led, OUTPUT);

  Serial.begin(9600);

}

void loop() {

  int width = pulseIn(ch1, HIGH, 30000); 
  Serial.print("Channel 1:  "); 
  Serial.println(width);       
  if(width > 1800) {
     digitalWrite(led, HIGH);
 
  }

Serial.println();

delay(100);
}

wait... something is not right. i think my transmitter lost its bind. bc i uploaded the original code just to check and it still wasnt changing values when i switch it. let me re-bind and see

edit: im dumb. the reason the value wasnt changing is i had un-ticked the auto scroll button. lmao. the values are changing but the led is still not coming on

I cleaned it up a bit. This should work.

const byte ch1 = 3;
const byte led = 13;

void setup() {
  pinMode(ch1, INPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int width = pulseIn(ch1, HIGH, 30000); 
  Serial.print("Channel 1:  "); 
  Serial.println(width);       
  if(width > 1800) {
     digitalWrite(led, HIGH); 
  }

Serial.println();
delay(100);
}

thank you!!!! but i did have to make a change. i changed it to pin 11 as the led output and it works! maybe something is wrong with pin 13 on my board here is the finished code i added a line to turn the led back off

const byte ch1 = 3;
const byte led = 11;

void setup() {
  pinMode(ch1, INPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int width = pulseIn(ch1, HIGH, 30000); 
  Serial.print("Channel 1:  "); 
  Serial.println(width);       
  if(width > 1990) {
     digitalWrite(led, HIGH); 
  }
     if(width < 1800) {
     digitalWrite(led, LOW);
  }
}

Yeah, I realized that as soon as you said the led wasn't coming on. Congrats.

thank you so much for your help! you are awesome lol now im going to edit it to have three channels since i have three spare channels on my receiver.