Sending data to arduino board from receiver

Hi, I would like to know how to send signals received from a receiver to an arduino board to turn on an LED. The transmitter and receiver are communicating with each other. However, the receiver is unable to send the data received from the transmitter to the arduino board to turn on the LED. I will provide my code so that if there is anything wrong with it, anyone can provide advice.

const int channelPin = 2;
const int ledPin = 13;

int channelState = 0;

double channel;
void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(2, INPUT);
  Serial.begin(9600);
}

void loop() {
  channelState = digitalRead(channelPin);
  channel = pulseIn(2, HIGH);
  
  if (channelState > 1550) 
  {
    digitalWrite(ledPin, HIGH);
    Serial.println(channel);
  } 
  else (channelState < 1520); 
  {
    digitalWrite(ledPin, LOW);
    Serial.println(channel);
  }
}

What kind of receiver? How is it supposed to communicate with the arduino?

digitalRead() returns either 0 or 1; how big do you think the chaces are that it's greater than 1550 :wink:

PS: And you're missing an if after the else

  channelState = digitalRead(channelPin);
  channel = pulseIn(2, HIGH);

You have done a good job of naming variables, except this last one. pulseIn() returns a time value, so using time in the name (or Time) would prevent the kind of mistake you make later.

What is not clear is why you are reading a value and a time from the same pin. One or the other is wrong.

To sterretje: The receiver is called Futaba EPCar R214GF-E receiver. I think that the receiver should be able to communicate with the arduino.

To PaulS: I am not so sure how does the pulseIn work. Could you help me by providing me with such an example so that I am able to use the function properly?

Could you help me by providing me with such an example so that I am able to use the function properly?

The way that you are using the function is correct. That you are also using digitalRead() on the same pin is not. That you are not using the value that pulseIn() returns is not.

channelState = digitalRead(channelPin);

Does this mean I have to change "channelPin" to "ledPin"? Or do I use another pin as another input, like pin 3?

channel = pulseIn(2, HIGH);

PaulS:
That you are not using the value that pulseIn() returns is not.

Do I use the values that appear on the serial monitor?

Does this mean I have to change "channelPin" to "ledPin"?

What does the value in the variable correspond to? It does not make sense to read the state of an LED pin, since the name implies that an LED is connected, and an LED is usually an output device. If you have set the state of the pin (turned the LED on or off), surely you can remember that.

Or do I use another pin as another input, like pin 3?

Again, it is not clear what you want to do. What is clear is that you can't connect an RF receiver and anything else to the same input pin, and expect anything good to happen. You can't use a pin as both input and output at the same time, either.

Do I use the values that appear on the serial monitor?

No. You might want to use that same value that you sent to the serial monitor, but you can't use the text that is shown in the output pane of the serial monitor for anything.

I suggest that you start simple by simply printing the result of the pulseIn() function. No conditions; see pulseIn reference.
I've changed the example code (see below) to reflect the use of pin 2 and to print the measured duration.

int pin = 2;

unsigned long duration;

void setup()
{
  pinMode(pin, INPUT);
}

void loop()
{
  duration = pulseIn(pin, HIGH);
  Serial.print("duration = ");
  Serial.println(duration);
}

I don't know if it will help, but I found RC Hobby Controllers and Arduino - SparkFun Electronics

Disclaimer: no experience with the Futaba stuff.

int pin = 2;
const int ledPin = 13;

unsigned long duration;

void setup()
{
  Serial.begin(9600);
  pinMode(2, INPUT);
  pinMode(13, OUTPUT);
}

void loop()
{
  duration = pulseIn(2, HIGH);
  Serial.print("duration = ");
  Serial.println(duration);
  
   if (duration > 1550) {
   digitalWrite(ledPin, HIGH);
}
   else if (duration < 1500) {
   digitalWrite(ledPin, LOW);
   }
}

Here is the code and it works. Thanks for everyone’s help. :smiley: :smiley: