Difficulties using Tx and Tx communication with RF APC220 module.

Hi there,

I'm trying to communicate between two arduinos using the Rx and Tx ports through the APC220 module.

Some points:

  • Both modules has been properly programmed through RF-MAGIC software for Windows
  • I'm NOT using USB to power the arduinos, since you cannot use serial communication for two things at the same time (inferference). I removed the APC220 module while uploading the code to Arduinos in order to prevent errors.
  • The wiring is correct.

I'm trying to send a analog value from a potentiometer from the transmitter to the receiver.
In receiver code, I'm trying to compare this value, and if it's >250, it turns on a LED.

However, the LED isn't turning on.

Simple code :slight_smile:

I believe it's a code error, since I never used Tx Rx ports before. Can you spot any code error?

TRANSMITTER CODE:

int value;
int Pin = A1;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
value = analogRead(Pin);
Serial.write(value);
delay(2000);
}

RECEIVER CODE:

int value;
int ledPin = 8;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:


value = Serial.read();
if (value>250){
  digitalWrite(ledPin,HIGH);
  }
 else {digitalWrite(ledPin,LOW);}
}

Thank you so much for all the your attention, time and willing to help,

Matheus Bitencourt

Serial.write sends a byte and read does too. You're trying to send an int. If you want to stick with that method, you can do the test against 250 on the transmitter and send 'H' or 'L' (or whatever) to the receiver to indicate whether the led should be on or off.

If you actually want the receiver to get the value read, you will need to do it differently.

'm NOT using USB to power the arduinos, since you cannot use serial communication for two things at the same time (inferference).

If you mean that if you open two sketches in the IDE at the same time they both use the same COM port that is true. However, if you open 2 separate instances of the IDE then each can use a different COM port

I'm trying to send a analog value from a potentiometer from the transmitter to the receiver.

One immediate problem is that the value read from the analogue port is an int consisting of 2 bytes. How many bytes will Serial.write() send and how many bytes will be read by the receiver ?